R Under development (unstable) (2024-06-26 r86840 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 = "+ ") 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.00 Min. : 1.000 0:78 1st Qu.: 8.00 1st Qu.: 5.000 1:72 Median :10.00 Median : 7.000 Mean :10.26 Mean : 6.973 3rd Qu.:12.00 3rd Qu.: 9.000 Max. :18.00 Max. :17.000 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> round(coef(lmm_tree), digits = 6) (Intercept) treatmentTreatment 2 3 7.500140 4.122083 4 8.591409 0.521259 5 11.087612 -4.546886 R> round(ranef(lmm_tree)$cluster, digits = 6) (Intercept) 1 -0.309644 2 -0.341546 3 -0.067551 4 -0.576757 5 -0.152473 6 -0.087617 7 0.129055 8 0.225009 9 0.261257 10 0.920266 R> formatC(predict(lmm_tree, newdata = DepressionDemo[1:7, ]), format = "f", + digits = 7) 1 2 3 4 5 "10.7779679" "11.5546716" "7.1585945" "9.0451168" "11.2806773" 6 7 "8.8164179" "11.8834799" R> formatC(predict(lmm_tree, newdata = DepressionDemo[1:7, -3], re.form = NA), + format = "f", digits = 7) 1 2 3 4 5 "11.0876120" "11.6222230" "7.5001402" "9.1126682" "11.6222230" 6 7 "8.5914088" "11.6222230" R> formatC(residuals(lmm_tree)[1:10], format = "f", digits = 7) 1 2 3 4 5 "2.2220321" "2.4453284" "-0.1585945" "0.9548832" "-1.2806773" 6 7 8 9 10 "1.1835821" "-1.8834799" "-1.7711225" "0.8008197" "4.0766164" R> formatC(predict(lmm_tree)[1:10], format = "f", digits = 7) 1 2 3 4 5 "10.7779679" "11.5546716" "7.1585945" "9.0451168" "11.2806773" 6 7 8 9 10 "8.8164179" "11.8834799" "8.7711225" "6.1991803" "6.9233836" 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> round(coef(glmm_tree), digits = 6) (Intercept) treatmentTreatment 2 3 -2.040571 3.048616 4 0.895104 -0.446130 5 1.920259 -4.892110 R> round(ranef(glmm_tree)$cluster, digits = 6) (Intercept) 1 -0.286691 2 -0.275303 3 0.047374 4 0.056034 5 -0.103269 6 -0.180381 7 0.268662 8 0.232370 9 0.044460 10 0.177206 R> formatC(predict(glmm_tree, newdata = DepressionDemo[1:7, ]), format = "f", + digits = 7) 1 2 3 4 5 "0.8366579" "0.7418140" "0.0898168" "0.6216006" "0.6754067" 6 7 "0.7553725" "0.7412556" R> formatC(predict(glmm_tree, newdata = DepressionDemo[1:7, -3], re.form = NA), + format = "f", digits = 7) 1 2 3 4 5 "0.8721674" "0.7326373" "0.1150086" "0.6103953" "0.7326373" 6 7 "0.7099424" "0.7326373" R> formatC(residuals(glmm_tree)[1:10], format = "f", digits = 7) 1 2 3 4 5 "0.5972270" "0.7728605" "-0.4338419" "0.9751487" "0.8859348" 6 7 8 9 10 "0.7490585" "0.7738343" "-1.5001216" "-0.2762165" "2.0558798" R> formatC(predict(glmm_tree)[1:10], format = "f", digits = 7) 1 2 3 4 5 "0.8366579" "0.7418140" "0.0898168" "0.6216006" "0.6754067" 6 7 8 9 10 "0.7553725" "0.7412556" "0.6754067" "0.0374293" "0.1208360" R> > proc.time() user system elapsed 2.32 0.15 2.48