Background
The brokenstick
package has three major interfaces:
- Up to version
brokenstick 0.62.1
(before May 2020) - Up to version
brokenstick 1.1.1
(May 2020 - Nov 2021) - Versions higher than
brokenstick 2.0.0
(Nov 2021 - now)
This document summarises the main changes in
brokenstick 2.0.0
. See “Help for old friends” in
brokenstick 1.1.1
for an overview of the previous changes
from 0.75.0
to 1.1.1
.
Main changes
Function
brokenstick()
in version2.0.0
sets the Kasim-Raudenbush sampler as the default method. The former methodlme4::lmer()
remains available by settingmethod = "lmer"
argument.Version
2.0.0
adopts the variable names of thecoda
package (e.g.,start
,end
,thin
,niter
, and so on) and stores the results of the Kasim-Raudenbush sampler as objects of classmcmc
.For
method = "kr"
one may now inspect the solution of the sampler by standard functions from thecoda
package. Formethod = "lmer"
we can apply functions from thelme4
package formerMod
objects.Version
2.0.0
redefines thebrokenstick
class. New entries includecall
,formula
,internal
,sample
,light
,data
,imp
andmod
. Removed entries areknots
(renamed tointernal
) anddraws
(renamed toimp
). We may omit thenewdata
argument for the training data. Settinglight = TRUE
creates a small version of thebrokenstick
object. Objects of classbrokenstick
are not backwards compatible, so one should regenerate objects of classbrokenstick
in order use newer features in2.0.0
.Version
2.0.0
conforms to classic model fitting interface inR
. Renames thenew_data
argument tonewdata
to conform topredict.lm()
. Methodsplot()
andpredict()
no longer require anewdata
argument. All special cases ofpredict()
updated and explained in documentation and examples.Version
2.0.0
adds methodscoef()
,fitted()
,model.frame()
,model.matrix()
,print()
andsummary()
for thebrokenstick
object.Simplifies algorithmic control. Renames
control_brokenstick()
toset_control()
and removes a layer in the control list.Added support for
hide
argument in user-oriented functions. Automatic suppression of last knot.
Minor changes
- Stabilises the
rgamma()
calls in KR-algorithm for edge cases. -
predict_brokenstick()
can now work with the both (internal) training and (external) test data. - Removes the superfluous
type
argument frompredict.brokenstick()
- Adds a function
get_omega()
to extract the variance-covariance matrix of the broken stick estimates - Improves error messages of edge cases in
test-brokenstick_edge.R
- Perform stricter tests on arguments of
brokenstick()
- Introduces argument
warn_splines
inmake_basis()
to suppress uninteresting warns fromsplines::bs()
- Removes superfluous
knotnames
argument inmake_basis()
- Argument
x
inmake_basis()
is now a vector instead of a column vector - Introduces new
xname
argument inmake_basis()
to set the xname
Install legacy version
We recommend changing your code to reflect the above changes and run
brokenstick 2.4.0
or higher. If needed, version
1.1.1
can be installed as
library("devtools")
install_github("growthcharts/brokenstick@9b969af")
Examples
Example 1: Fit model
Fit model, brokenstick package version 0.75.0
-
1.1.1
:
library(brokenstick)
data <- brokenstick::smocc_200
# formula interface
fit1 <- brokenstick(hgt.z ~ age | id, data)
# XY interface - numeric vector
# Deprecated in v2.0.0
fit2 <- with(data, brokenstick(age, hgt.z, id))
# XY interface - data.frame
# Deprecated in v2.0.0
fit3 <- with(data, brokenstick(data.frame(age), hgt.z, id))
# XY interface - matrix
# Deprecated in v2.0.0
tt <- as.matrix(data[, c(1, 2, 7)])
fit4 <- brokenstick(tt[, "age", drop = FALSE],
tt[, "hgt.z", drop = FALSE],
tt[, "id", drop = FALSE])
Fit model, brokenstick package version 2.4.0
:
library(brokenstick)
data <- brokenstick::smocc_200
# formula interface
fit1 <- brokenstick(hgt_z ~ age | id, data)
Example 2: Predict model
Predict model, brokenstick package version 0.75.0
-
1.1.1
:
# predict at observed data
p1 <- predict(fit1, data)
# predict at knots
p2 <- predict(fit1, data, x = "knots")
# predict at both observed data and knots
p3 <- predict(fit1, data, x = "knots", strip_data = FALSE)
# predict knots, broad matrix
p4 <- predict(fit1, data, x = "knots", shape = "wide")
Predict model, brokenstick package version 2.4.0
: