Learn R Programming

sjPlot (version 1.7)

sjp.lmer: Plot estimates (forest plots) of linear mixed effects models

Description

Plot estimates (coefficients) with confidence intervalls of either fixed effects or random effects of linear mixed effects models (that have been fitted with lmer of the lme4 package.

Usage

sjp.lmer(fit, type = "re", vars = NULL, ri.nr = 1, title = NULL,
  geom.size = 3, geom.colors = "Set1", hideErrorBars = FALSE,
  showIntercept = TRUE, stringIntercept = "(Intercept)", sort.coef = NULL,
  pred.labels = NULL, axisTitle.x = NULL, axisTitle.y = NULL,
  interceptLineType = 2, interceptLineColor = "grey70",
  showValueLabels = TRUE, labelDigits = 2, showPValueLabels = TRUE,
  facet.grid = TRUE, free.scale = FALSE, fade.ns = FALSE,
  printPlot = TRUE)

Arguments

Value

(Insisibily) returns
  • the ggplot-object (plot), iftype = "fe"or iftype = "re"andfacet.grid = TRUE). Multiple plots (type = "re"and iffacet.grid = FALSE) are returned in the objectplot.list.
  • a list of ggplot-objects (plot.list). seeplotfor details.
  • a data framemydfwith the data used to build the ggplot-object(s).

See Also

Examples

Run this code
# fit model
library(lme4)
fit <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)

# simple plot
sjp.lmer(fit)

# plot fixed effects
sjp.lmer(fit, type = "fe")

# sort by predictor Days
sjp.lmer(fit, sort.coef = "Days")

# plot each predictor as own plot
# sort each plot
sjp.lmer(fit,
         facet.grid = FALSE,
         sort.coef = "sort.all")

# plot and sort fixed effects
sjp.lmer(fit,
         type = "fe",
         sort.coef = TRUE)


library(lme4)
data(efc)
# prepare group variable
efc$grp = as.factor(efc$e15relat)
levels(x = efc$grp) <- get_val_labels(efc$e15relat)
# data frame for fitted model
mydf <- na.omit(data.frame(neg_c_7 = as.numeric(efc$neg_c_7),
                           sex = as.factor(efc$c161sex),
                           c12hour = as.numeric(efc$c12hour),
                           barthel = as.numeric(efc$barthtot),
                           grp = efc$grp))
# fit glmer
fit <- lmer(neg_c_7 ~ sex + c12hour + barthel + (1|grp),
            data = mydf)

# plot random effects
sjp.lmer(fit)

# plot fixed effects
sjp.lmer(fit, type = "fe")

sjp.lmer(fit,
         type = "fe.std",
         sort.coef = TRUE)

# plot fixed effects slopes for
# each random intercept, but only for
# coefficient "c12hour"
sjp.lmer(fit,
         type = "fe.ri",
         vars = "c12hour")

# plot fixed effects correlations
sjp.lmer(fit, type = "fe.cor")

# qq-plot of random effects
sjp.lmer(fit, type = "re.qq")

Run the code above in your browser using DataLab