Learn R Programming

sjPlot (version 1.8.3)

sjp.glmm: Plot odds ratios (forest plots) of multiple fitted glm's

Description

Plot and compare odds ratios (forest plots) of multiple fitted glm's with confidence intervals in one plot.

Usage

sjp.glmm(..., title = NULL, labelDependentVariables = NULL,
  legendDepVarTitle = "Dependent Variables", legendPValTitle = "p-level",
  stringModel = "Model", axisLabels.y = NULL, axisTitle.x = "Odds Ratios",
  axisLimits = NULL, breakTitleAt = 50, breakLabelsAt = 25,
  breakLegendTitleAt = 20, gridBreaksAt = 0.5, transformTicks = TRUE,
  geom.size = 3, geom.spacing = 0.4, geom.colors = "Set1",
  fade.ns = FALSE, usePShapes = FALSE, interceptLineType = 2,
  interceptLineColor = "grey70", remove.estimates = NULL,
  coord.flip = TRUE, showIntercept = FALSE, showAxisLabels.y = TRUE,
  showValueLabels = TRUE, labelDigits = 2, showPValueLabels = TRUE,
  hideLegend = FALSE, facet.grid = FALSE, printPlot = 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 (df).

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,
         labelDependentVariables = c("Fertility",
                                     "Infant Mortality",
                                     "Agriculture"),
         showValueLabels = FALSE,
         showPValueLabels = FALSE,
         fade.ns = TRUE,
         usePShapes = 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
edu.mid <- ifelse(efc$c172code == 2, 1, 0)
edu.high <- ifelse(efc$c172code == 3, 1, 0)
# create data frame for fitted model
mydat <- data.frame(y = as.factor(y),
                    sex = as.factor(efc$c161sex),
                    dep = as.factor(efc$e42dep),
                    barthel = as.numeric(efc$barthtot),
                    edu.mid = as.factor(edu.mid),
                    edu.hi = as.factor(edu.high))

fit1 <- glm(y ~ sex + edu.mid + edu.hi,
            data = mydat,
            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