Learn R Programming

sjPlot (version 2.1.0)

sjp.lmm: Plot estimates of multiple fitted lm(er)'s

Description

Plot and compare coefficients (estimates) with confidence intervals of multiple fitted linear (mixed effects) models in one plot. Fitted models may have differing predictors, but only in a "stepwise" sense.

Usage

sjp.lmm(..., type = "lm", remove.estimates = NULL, title = NULL, depvar.labels = NULL, legend.title = "Dependent Variables", legend.pval.title = "p-level", axis.labels = NULL, axis.title = "Estimates", axis.lim = NULL, wrap.title = 50, wrap.labels = 25, wrap.legend.title = 20, grid.breaks = NULL, geom.size = 3, geom.spacing = 0.4, geom.colors = "Set1", show.values = TRUE, show.legend = TRUE, show.intercept = FALSE, show.p = TRUE, fade.ns = FALSE, p.shape = FALSE, p.kr = TRUE, vline.type = 2, vline.color = "grey70", digits = 2, facet.grid = FALSE, coord.flip = TRUE, prnt.plot = TRUE)

Arguments

...
one or more fitted lm or lmerMod-objects. May also be a list-object with fitted models, instead of separating each model with comma. See 'Examples'.
type
type of plot. Use one of following:
remove.estimates
character vector with coefficient names that indicate which estimates should be removed from the plot. remove.estimates = "est_name" would remove the estimate est_name. Default is NULL, i.e. all estimates are printed.
title
character vector, used as plot title. Depending on plot type and function, will be set automatically. If title = "", no title is printed.
depvar.labels
character vector with labels of dependent variables of all fitted models. See 'Examples'.
legend.title
character vector, used as title for the plot legend. Note that only some plot types have legends (e.g. type = "pred" or when grouping estimates with group.estimates).
legend.pval.title
character vector, used as title of the plot legend that indicates the p-values. Default is "p-level". Only applies if p.shape = TRUE.
axis.labels
character vector with labels used as axis labels. Optional argument, since in most cases, axis labels are set automatically.
axis.title
character vector of length one or two (depending on the plot function and type), used as title(s) for the x and y axis. If not specified, a default labelling is chosen.
axis.lim
numeric vector of length 2, defining the range of the plot axis. Depending on plot type, may effect either x- or y-axis, or both. For multiple plot outputs (e.g., from type = "eff" or type = "slope" in sjp.glm), axis.lim may also be a list of vectors of length 2, defining axis limits for each plot (only if non-faceted).
wrap.title
numeric, determines how many chars of the plot title are displayed in one line and when a line break is inserted.
wrap.labels
numeric, determines how many chars of the value, variable or axis labels are displayed in one line and when a line break is inserted.
wrap.legend.title
numeric, determines how many chars of the legend's title are displayed in one line and when a line break is inserted.
grid.breaks
numeric; sets the distance between breaks for the axis, i.e. at every grid.breaks'th position a major grid is being printed.
geom.size
size resp. width of the geoms (bar width, line thickness or point size, depending on plot type and function). Note that bar and bin widths mostly need smaller values than dot sizes.
geom.spacing
spacing between the dots and error bars of the plotted fitted models. Default is 0.3.
geom.colors
user defined color palette for geoms. If group.estimates is not specified, must either be vector with two color values or a specific color palette code (see 'Details' in sjp.grpfrq). Else, if group.estimates is specified, geom.colors must be a vector of same length as groups. See 'Examples'.
show.values
logical, whether values should be plotted or not.
show.legend
logical, if TRUE, and depending on plot type and function, a legend is added to the plot.
show.intercept
logical, if TRUE, the intercept of the fitted model is also plotted. Default is FALSE. For glm's, please note that due to exponential transformation of estimates, the intercept in some cases can not be calculated, thus the function call is interrupted and no plot printed.
show.p
logical, adds significance levels to values, or value and variable labels.
fade.ns
if TRUE, non significant estimates will be printed in slightly faded colors.
p.shape
If TRUE, significant levels are distinguished by different point shapes and a related legend is plotted. Default is FALSE.
p.kr
logical, if TRUE, p-value estimation is based on conditional F-tests with Kenward-Roger approximation for the df. Caution: Computation may take very long time for large samples!
vline.type
linetype of the vertical "zero point" line. Default is 2 (dashed line).
vline.color
color of the vertical "zero point" line. Default value is "grey70".
digits
numeric, amount of digits after decimal point when rounding estimates and values.
facet.grid
TRUE to arrange the lay out of of multiple plots in a grid of an integrated single plot. This argument calls facet_wrap or facet_grid to arrange plots. Use plot_grid to plot multiple plot-objects as an arranged grid with grid.arrange.
coord.flip
logical, if TRUE, the x and y axis are swapped.
prnt.plot
logical, if TRUE (default), plots the results as graph. Use FALSE if you don't want to plot any graphs. In either case, the ggplot-object will be returned as value.

Value

(Insisibily) returns the ggplot-object with the complete plot (plot) as well as the data frame that was used for setting up the ggplot-object (data).

Examples

Run this code
# prepare dummy variables for binary logistic regression
# Now fit the models. Note that all models share the same predictors
# and only differ in their dependent variable
library(sjmisc)
data(efc)

# fit three models
fit1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)
fit2 <- lm(neg_c_7 ~ c160age + c12hour + c161sex + c172code, data = efc)
fit3 <- lm(tot_sc_e ~ c160age + c12hour + c161sex + c172code, data = efc)

# plot multiple models
sjp.lmm(fit1, fit2, fit3, facet.grid = TRUE)

# plot multiple models with legend labels and 
# point shapes instead of value labels
sjp.lmm(fit1, fit2, fit3,
        axis.labels = c("Carer's Age", "Hours of Care", "Carer's Sex",
                        "Educational Status"),
        depvar.labels = c("Barthel Index", "Negative Impact", "Services used"),
        show.values = FALSE, show.p = FALSE, fade.ns = TRUE, p.shape = TRUE)

# ------------------------------
# plot multiple models from nested lists argument
# ------------------------------
all.models <- list()
all.models[[1]] <- fit1
all.models[[2]] <- fit2
all.models[[3]] <- fit3

sjp.lmm(all.models)

# ------------------------------
# plot multiple models with different
# predictors (stepwise inclusion),
# standardized estimates
# ------------------------------
fit1 <- lm(mpg ~ wt + cyl + disp + gear, data = mtcars)
fit2 <- update(fit1, . ~ . + hp)
fit3 <- update(fit2, . ~ . + am)

sjp.lmm(fit1, fit2, fit3, type = "std2")

Run the code above in your browser using DataLab