# \donttest{
require("lmerTest") ## load BEFORE lme4 and glmertree to obtain hypothesis tests / p-values
## Create artificial training and test datasets
set.seed(42)
train <- sample(1:nrow(DepressionDemo), size = 200, replace = TRUE)
test <- sample(1:nrow(DepressionDemo), size = 200, replace = TRUE)
## Fit tree on training data
tree1 <- lmertree(depression ~ treatment | cluster | age + anxiety + duration,
data = DepressionDemo[train, ])
## Obtain honest estimates of parameters and standard errors using test data
tree2 <- cv.lmertree(tree1, newdata = DepressionDemo[test, ])
tree3 <- cv.lmertree(tree1, newdata = DepressionDemo[test, ],
reference = 7, omit.intercept = TRUE)
summary(tree2)
summary(tree3)
coef(tree1)
coef(tree2)
coef(tree3)
plot(tree1, which = "tree")
plot(tree2, which = "tree")
plot(tree3, which = "tree")
predict(tree1, newdata = DepressionDemo[1:5, ])
predict(tree2, newdata = DepressionDemo[1:5, ])
# }
Run the code above in your browser using DataLab