Learn R Programming

sjPlot (version 2.0.0)

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

Description

Plot odds or incident rate ratios with confidence intervalls as dot plot. Depending on the type argument, this function may also plot model assumptions for generalized linear models, or marginal effects (predicted probabilities or events).

Usage

sjp.glm(fit, type = "dots", vars = NULL, group.estimates = NULL,
  remove.estimates = NULL, sort.est = TRUE, title = NULL,
  legend.title = NULL, axis.labels = NULL, axis.title = "Odds Ratios",
  geom.size = NULL, geom.colors = "Set1", wrap.title = 50,
  wrap.labels = 25, axis.lim = NULL, grid.breaks = 0.5,
  trns.ticks = TRUE, show.intercept = FALSE, show.values = TRUE,
  show.p = TRUE, show.ci = FALSE, show.legend = FALSE,
  show.summary = FALSE, digits = 2, vline.type = 2,
  vline.color = "grey70", coord.flip = TRUE, y.offset = 0.15,
  facet.grid = TRUE, 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]

See Also

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

Examples

Run this code
# prepare dichotomous dependent variable
swiss$y <- ifelse(swiss$Fertility < median(swiss$Fertility), 0, 1)

# fit model
fitOR <- glm(y ~ Education + Examination + Infant.Mortality + Catholic,
             family = binomial(link = "logit"), data = swiss)

# print Odds Ratios as dots
sjp.glm(fitOR)

# -------------------------------
# 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 data frame for fitted model
mydf <- data.frame(y = as.factor(y),
                   sex = efc$c161sex,
                   dep = to_factor(efc$e42dep),
                   barthel = efc$barthtot,
                   education = to_factor(efc$c172code))
# fit model
fit <- glm(y ~., data = mydf, family = binomial(link = "logit"))

# plot odds ratios
sjp.glm(fit, title = get_label(efc$neg_c_7))

# plot probability curves (relationship between predictors and response)
sjp.glm(fit, title = get_label(efc$neg_c_7), type = "slope")

# --------------------------
# grouping estimates
# --------------------------
sjp.glm(fit,  group.estimates = c(1, 2, 2, 2, 3, 4, 4))

# --------------------------
# model predictions, with selected model terms.
# 'vars' needs to be a character vector of length 1 or 2
# with names of model terms for x-axis and grouping factor.
# --------------------------
sjp.glm(fit, type = "pred", vars = "barthel")
# faceted, with ci
sjp.glm(fit, type = "pred", vars = c("barthel", "dep"), show.ci = TRUE)
# w/o facets
sjp.glm(fit, type = "pred", vars = c("barthel", "dep"), facet.grid = FALSE)

Run the code above in your browser using DataLab