R Under development (unstable) (2024-11-03 r87286 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("glmertree") Loading required package: lme4 Loading required package: Matrix Loading required package: partykit Loading required package: grid Loading required package: libcoin Loading required package: mvtnorm > options(width = 70, prompt = "R> ", continue = "+ ", digits = 4) R> R> data("DepressionDemo", package = "glmertree") R> summary(DepressionDemo) depression treatment cluster age Min. : 3.00 Treatment 1:78 1 :15 Min. :18 1st Qu.: 7.00 Treatment 2:72 2 :15 1st Qu.:39 Median : 9.00 3 :15 Median :45 Mean : 9.12 4 :15 Mean :45 3rd Qu.:11.00 5 :15 3rd Qu.:52 Max. :16.00 6 :15 Max. :69 (Other):60 anxiety duration depression_bin Min. : 3.0 Min. : 1.00 0:78 1st Qu.: 8.0 1st Qu.: 5.00 1:72 Median :10.0 Median : 7.00 Mean :10.3 Mean : 6.97 3rd Qu.:12.0 3rd Qu.: 9.00 Max. :18.0 Max. :17.00 R> R> lmm_tree <- lmertree(depression ~ treatment | cluster | age + duration + anxiety, + data = DepressionDemo) R> plot(lmm_tree, which = "tree") R> plot(lmm_tree, which = "ranef") $cluster R> coef(lmm_tree) (Intercept) treatmentTreatment 2 3 7.500 4.1221 4 8.591 0.5213 5 11.088 -4.5469 R> ranef(lmm_tree)$cluster (Intercept) 1 -0.30964 2 -0.34155 3 -0.06755 4 -0.57676 5 -0.15247 6 -0.08762 7 0.12906 8 0.22501 9 0.26126 10 0.92027 R> predict(lmm_tree, newdata = DepressionDemo[1:7, ]) 1 2 3 4 5 6 7 10.778 11.555 7.159 9.045 11.281 8.816 11.883 R> predict(lmm_tree, newdata = DepressionDemo[1:7, -3], re.form = NA) 1 2 3 4 5 6 7 11.088 11.622 7.500 9.113 11.622 8.591 11.622 R> residuals(lmm_tree)[1:10] 1 2 3 4 5 6 7 8 2.2220 2.4453 -0.1586 0.9549 -1.2807 1.1836 -1.8835 -1.7711 9 10 0.8008 4.0766 R> predict(lmm_tree)[1:10] 1 2 3 4 5 6 7 8 9 10 10.778 11.555 7.159 9.045 11.281 8.816 11.883 8.771 6.199 6.923 R> R> glmm_tree <- glmertree(depression_bin ~ treatment | cluster | age + duration + anxiety, + data = DepressionDemo, family = binomial) R> plot(glmm_tree, which = "tree") Loading required namespace: vcd R> plot(glmm_tree, which = "ranef") $cluster R> coef(glmm_tree) (Intercept) treatmentTreatment 2 3 -2.0406 3.0486 4 0.8951 -0.4461 5 1.9203 -4.8921 R> ranef(glmm_tree)$cluster (Intercept) 1 -0.28669 2 -0.27530 3 0.04737 4 0.05603 5 -0.10327 6 -0.18038 7 0.26866 8 0.23237 9 0.04446 10 0.17721 R> predict(glmm_tree, newdata = DepressionDemo[1:7, ]) 1 2 3 4 5 6 7 0.83666 0.74181 0.08982 0.62160 0.67541 0.75537 0.74126 R> predict(glmm_tree, newdata = DepressionDemo[1:7, -3], re.form = NA) 1 2 3 4 5 6 7 0.8722 0.7326 0.1150 0.6104 0.7326 0.7099 0.7326 R> residuals(glmm_tree)[1:10] 1 2 3 4 5 6 7 8 0.5972 0.7729 -0.4338 0.9751 0.8859 0.7491 0.7738 -1.5001 9 10 -0.2762 2.0559 R> predict(glmm_tree)[1:10] 1 2 3 4 5 6 7 8 0.83666 0.74181 0.08982 0.62160 0.67541 0.75537 0.74126 0.67541 9 10 0.03743 0.12084 R> > proc.time() user system elapsed 2.40 0.21 2.62