plot.glmertree: Plotting (Generalized) Linear Mixed Model Trees

plot.glmertreeR Documentation

Plotting (Generalized) Linear Mixed Model Trees

Description

plot method for (g)lmertree objects.

Usage

## S3 method for class 'lmertree'
plot(x, which = "all", ask = TRUE, type = "extended", 
    observed = TRUE, fitted = "combined", tp_args = list(), 
    drop_terminal = TRUE, terminal_panel = NULL, ...)
## S3 method for class 'glmertree'
plot(x, which = "all", ask = TRUE, type = "extended", 
    observed = TRUE, fitted = "combined", tp_args = list(), 
    drop_terminal = TRUE, terminal_panel = NULL, ...)

Arguments

x

an object of class lmertree or glmertree.

which

character; "all" (default), "tree", "random" or "tree.coef". Specifies whether, tree, random effects, or both should be plotted. Alternatively, "tree.coef" yields caterpillar plots of the estimated fixed-effects coefficients in every terminal node of the tree, but omits the tree structure (see Details).

ask

logical. Should user be asked for input, before a new figure is drawn?

type

character; "extended" (default) or "simple". "extended" yields a plotted tree with observed data and/or fitted means plotted in the terminal nodes; "simple" yields a plotted tree with the value of fixed and/or random effects coefficients reported in the terminal nodes.

observed

logical. Should observed datapoints be plotted in the tree? Defaults to TRUE, FALSE is only supported for objects of class lmertree, not of classglmertree.

fitted

character. "combined" (default), "marginal" or "none". Specifies whether and how fitted values should be computed and visualized. Only used when predictor variables for the node-specific (G)LMs were specified. If "combined", fitted values will computed, using observed values of the remaining (random and fixed-effects) predictor variables, which can yield very wiggly curves. If "marginal", fitted values will be calculated, fixing all remaining predictor variables (with random and/or fixed effects) at the observed sample mean (or majority class).

tp_args

list of arguments to be passed to panel generating function node_glmertree. See arguments node_bivplot in panelfunctions.

drop_terminal

logical. Should all terminal nodes be plotted at the bottom of the plot?

terminal_panel

an optional panel generating function to be passed to plot.party(), but will most likely be ignored. For passing arguments to the panel generating functions, use argument tp_args. For using a custom panel generating function, see Details.

...

Additional arguments to be passed to plot.party(). See party-plot documentation for details.

Details

If the node-specific model of the (g)lmertree object specified by argument x is an intercept-only model, observed data distributions will be plotted in the terminal nodes of the tree (using node_barplot (for categorical responses) or node_boxplot (for numerical responses). Otherwise, fitted values will be plotted, in addition to observed datapoints, using a function taking similar arguments as node_bivplot.

If which = "tree.coef"), caterpillar plot(s) are created for the local (node-specific) fixed effects. These depict the estimated fixed-effects coefficients with 95% confidence intervals, but note that these CIs do not account for the searching of the tree structure and are therefore likely too narrow. There is currently no way to adjust CIs for searching of the tree structure, but the CIs can be useful to obtain an indication of the variability of the coefficient estimates, not for statistical significance testing.

If which = "ranef" or "all", caterpillar plot(s) for the random effect(s) created, depicting the predicted random effects with 95% confidence intervals. See also ranef for more info. Note that the CIs do not account for the searching of the tree structure and may be too narrow.

If you want to specify custom panel generating functions, it might be best to not use the plotting method for (g)lmertrees. Instead, extract the (g)lmtree from the fitted (g)lmertree object (which is a list containing amongst other a $tree entry). On this tree, most of the customization options from party-plot can then be applied.

The code is still under development and might change in future versions.

References

Fokkema M, Smits N, Zeileis A, Hothorn T, Kelderman H (2018). “Detecting Treatment-Subgroup Interactions in Clustered Data with Generalized Linear Mixed-Effects Model Trees”. Behavior Research Methods, 50(5), 2016-2034. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.3758/s13428-017-0971-x")}

See Also

lmertree, glmertree, party-plot.

Examples


## load artificial example data
data("DepressionDemo", package = "glmertree")

## fit linear regression LMM tree for continuous outcome
lt <- lmertree(depression ~ treatment + age | cluster | anxiety + duration,
  data = DepressionDemo)
plot(lt)
plot(lt, type = "simple")
plot(lt, which = "tree", fitted = "combined")
plot(lt, which = "tree", fitted = "none")
plot(lt, which = "tree", observed = FALSE)
plot(lt, which = "tree.coef")
plot(lt, which = "ranef")

## fit logistic regression GLMM tree for binary outcome
gt <- glmertree(depression_bin ~ treatment + age | cluster | 
  anxiety + duration, data = DepressionDemo)
plot(gt)  
plot(gt, type = "simple")
plot(gt, which = "tree", fitted = "combined")
plot(gt, which = "tree", fitted = "none")
plot(gt, which = "tree.coef")
plot(gt, which = "ranef")


glmertree documentation built on March 31, 2023, 3:04 p.m.