Learn R Programming

sjPlot (version 1.7)

sjp.glmer: Plot odds ratios (forest plots) of generalized linear mixed effects models

Description

Plot odds ratios (exponentiated coefficients) with confidence intervalls of either fixed effects or random effects of generalized linear mixed effects models (that have been fitted with glmer of the lme4 package.

Usage

sjp.glmer(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,
  facet.grid = TRUE, free.scale = FALSE, interceptLineType = 2,
  interceptLineColor = "grey70", showValueLabels = TRUE, labelDigits = 2,
  showPValueLabels = TRUE, fade.ns = FALSE, show.se = 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
library(lme4)
# create binary response
sleepstudy$Reaction.dicho <- dicho(sleepstudy$Reaction, dichBy = "md")
# fit model
fit <- glmer(Reaction.dicho ~ Days + (Days | Subject),
             sleepstudy,
             family = binomial("logit"))

# simple plot
sjp.glmer(fit)

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

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

library(lme4)
data(efc)
# create binary response
efc$hi_qol <- dicho(efc$quol_5)
# 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(hi_qol = as.factor(efc$hi_qol),
                           sex = as.factor(efc$c161sex),
                           c12hour = as.numeric(efc$c12hour),
                           neg_c_7 = as.numeric(efc$neg_c_7),
                           grp = efc$grp))
# fit glmer
fit <- glmer(hi_qol ~ sex + c12hour + neg_c_7 + (1|grp),
             data = mydf,
             family = binomial("logit"))

# plot random effects
sjp.glmer(fit)

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

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

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

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

# plot probability curves (predicted probabilities)
# for each covariate, grouped by random intercepts
sjp.glmer(fit,
          type = "ri.pc",
          show.se = TRUE)

# plot probability curves (predicted probabilities)
# for each covariate, grouped by random intercepts
# in integrated plots
sjp.glmer(fit,
          type = "ri.pc",
          facet.grid = FALSE)

# plot probability curve (predicted probabilities)
# of fixed effect, only for coefficient "neg_c_7"
sjp.glmer(fit,
          type = "fe.pc",
          vars = "neg_c_7")

Run the code above in your browser using DataLab