# NOT RUN {
train <- smocc_200[1:1198, ]
# fit with implicit boundary c(0, 3)
fit <- brokenstick(hgt.z ~ age | id, data = train, knots = 0:3)
# using KR sampler
fit <- brokenstick(hgt.z ~ age | id, data = train, knots = 0:3,
method = "kr", seed = 1)
# }
# NOT RUN {
knots <- round(c(0, 1, 2, 3, 6, 9, 12, 15, 18, 24) / 12, 4)
boundary <- c(0, 3)
fit_lmer <- brokenstick(hgt.z ~ age | id, data = train,
knots = knots, boundary = boundary)
fit_kr <- brokenstick(hgt.z ~ age | id, data = train, knots = knots,
boundary = boundary, method = "kr")
# }
# NOT RUN {
# Four ways to specify the same model
# Formula interface
mod1 <- brokenstick(hgt.z ~ age | id, train)
# XY interface - numeric vector
mod2 <- with(train, brokenstick(age, hgt.z, id))
identical(mod1, mod2)
# XY interface - data.frame
mod3 <- with(train, brokenstick(data.frame(age), hgt.z, id))
identical(mod1, mod3)
# XY interface - matrix
tt <- as.matrix(train[, c(1, 2, 7)])
mod4 <- brokenstick(tt[, "age", drop = FALSE],
tt[, "hgt.z", drop = FALSE],
tt[, "id", drop = FALSE])
identical(mod1, mod4)
# }
Run the code above in your browser using DataLab