Learn R Programming

sjPlot (version 2.0.0)

sjp.glmer: Plot estimates, predictions or effects of generalized linear mixed effects models

Description

By default, this function plots estimates (odds, risk or incidents ratios, i.e. exponentiated coefficients, depending on family and link function) with confidence intervals of either fixed effects or random effects of generalized linear mixed effects models (that have been fitted with the glmer-function of the lme4-package). Furthermore, this function also plots predicted probabilities / incidents or diagnostic plots.

Usage

sjp.glmer(fit, type = "re", vars = NULL, ri.nr = NULL,
  remove.estimates = NULL, emph.grp = NULL, sample.n = NULL,
  sort.est = NULL, title = NULL, axis.labels = NULL, axis.title = NULL,
  geom.colors = "Set1", geom.size = NULL, show.values = TRUE,
  show.p = TRUE, show.ci = FALSE, show.legend = FALSE,
  show.intercept = TRUE, string.interc = "(Intercept)", fade.ns = FALSE,
  axis.lim = NULL, digits = 2, vline.type = 2, vline.color = "grey70",
  facet.grid = TRUE, free.scale = FALSE, y.offset = 0.1,
  prnt.plot = TRUE, ...)

Arguments

Value

(Insisibily) returns, depending on the plot type
  • The ggplot-object (plot). For multiple plots and iffacet.grid = FALSE) aplot.listis returned.
  • A data framedatawith the data used to build the ggplot-object(s), or a list of data frames (data.list).

Details

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

See Also

http://www.strengejacke.de/sjPlot/sjp.glmer/{sjPlot manual: sjp.glmer}

Examples

Run this code
library(lme4)
library(sjmisc)
# create binary response
sleepstudy$Reaction.dicho <- dicho(sleepstudy$Reaction, dich.by = "median")
# fit model
fit <- glmer(Reaction.dicho ~ Days + (Days | Subject),
             data = sleepstudy, family = binomial("logit"))

# simple plot
sjp.glmer(fit)

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

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_labels(efc$e15relat)
# data frame for fitted model
mydf <- data.frame(hi_qol = to_factor(efc$hi_qol),
                   sex = to_factor(efc$c161sex),
                   education = to_factor(efc$c172code),
                   c12hour = efc$c12hour,
                   neg_c_7 = 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 and sort fixed effects
sjp.glmer(fit, type = "fe", sort.est = TRUE)

# fit glmer, with categorical predictor with more than 2 levels
fit <- glmer(hi_qol ~ sex + education + c12hour + neg_c_7 + (1|grp),
             data = mydf, family = binomial("logit"))

# plot and sort fixed effects, axis labels automatically retrieved
sjp.glmer(fit, type = "fe", sort.est = TRUE)

# plot probability curves (predicted probabilities)
# for each covariate, grouped by random intercepts
# in integrated plots, emphasizing groups 1 and 4
sjp.glmer(fit, type = "ri.slope", emph.grp = c(1, 4), facet.grid = FALSE)

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

# plot predicted probabilities for response,
# related to model predictor, conditioned on random effects
sjp.glmer(fit, type = "pred", vars = "neg_c_7")

# plot predicted probabilities for response,
# related to model predictor, grouped
sjp.glmer(fit, type = "pred.fe", vars = c("neg_c_7", "sex"))
          
# non faceted, with ci           
sjp.glmer(fit, type = "pred.fe", vars = c("neg_c_7", "education"), 
          show.ci = TRUE, facet.grid = FALSE)

Run the code above in your browser using DataLab