# NOT RUN {
train <- smocc_200[1:1198, ]
test <- smocc_200[1199:1940, ]
# Fit
fit <- brokenstick(hgt.z ~ age | id, data = train, knots = 0:3)
# Predict, with preprocessing
tail(predict(fit, test), 3)
# case 1: x as knots
z <- predict(fit, test, x = "knots")
# case 2: x and y, one new group
predict(fit, test, x = "knots", y = c(1, 1, 0.5, 0))
# case 2: x and y, one new group, we need not specify new_data
predict(fit, x = "knots", y = c(1, 1, 0.5, 0))
# case 3: only group
predict(fit, test, group = c(11045, 11120, 999))
# case 4: predict at x in selected groups
predict(fit, test, x = c(0.5, 1, 1.25), group = c(11045, 11120, 999))
# case 5: vectorized
predict(fit, test, x = c(0.5, 1, 1.25), y = c(0, 0.5, 1), group = c(11045, 11120, 999))
# case 6: vectorized, without new_data, results are different for 11045 and 11120
predict(fit, x = c(0.5, 1, 1.25), y = c(0, 0.5, 1), group = c(11045, 11120, 999))
# }
Run the code above in your browser using DataLab