Learn R Programming

sjPlot (version 2.0.0)

sjp.glmm: Plot estimates of multiple fitted glm(er)'s

Description

Plot and compare odds or incidents ratios (forest plots) of multiple fitted generalized linear (mixed effects) models with confidence intervals in one plot.

Usage

sjp.glmm(..., 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 = 0.5, trns.ticks = TRUE, 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, vline.type = 2,
  vline.color = "grey70", digits = 2, facet.grid = FALSE,
  coord.flip = TRUE, prnt.plot = TRUE)

Arguments

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
y1 <- ifelse(swiss$Fertility < median(swiss$Fertility), 0, 1)
y2 <- ifelse(swiss$Infant.Mortality < median(swiss$Infant.Mortality), 0, 1)
y3 <- ifelse(swiss$Agriculture<median(swiss$Agriculture), 0, 1)

# Now fit the models. Note that all models share the same predictors
# and only differ in their dependent variable (y1, y2 and y3)
fitOR1 <- glm(y1 ~ swiss$Education + swiss$Examination + swiss$Catholic,
              family = binomial(link = "logit"))
fitOR2 <- glm(y2 ~ swiss$Education + swiss$Examination + swiss$Catholic,
              family = binomial(link = "logit"))
fitOR3 <- glm(y3 ~ swiss$Education + swiss$Examination + swiss$Catholic,
              family = binomial(link = "logit"))

# plot multiple models
sjp.glmm(fitOR1, fitOR2, fitOR3, facet.grid = TRUE)

# plot multiple models with legend labels and point shapes instead of value  labels
sjp.glmm(fitOR1, fitOR2, fitOR3,
         depvar.labels = c("Fertility", "Infant Mortality", "Agriculture"),
         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]] <- fitOR1
all.models[[2]] <- fitOR2
all.models[[3]] <- fitOR3

sjp.glmm(all.models)

# -------------------------------
# Predictors for negative impact
# of care. Data from the EUROFAMCARE
# sample dataset
# -------------------------------
library(sjmisc)
data(efc)

# create binary response
y <- ifelse(efc$neg_c_7 < median(na.omit(efc$neg_c_7)), 0, 1)
# create dummy variables for educational status
mydf <- data.frame(y = as.factor(y),
                   sex = efc$c161sex,
                   dep = to_factor(efc$e42dep),
                   barthel = efc$barthtot,
                   education = to_factor(efc$c172code))

fit1 <- glm(y ~ sex + education,  data = mydf, family = binomial(link = "logit"))
fit2 <- update(fit1, . ~ . + barthel)
fit3 <- update(fit2, . ~ . + dep)

sjp.glmm(fit1, fit2, fit3)

Run the code above in your browser using DataLab