Learn R Programming

sjPlot (version 1.7)

sjp.glm: Plot odds ratios (forest plots)

Description

Plot odds ratios (exponentiated coefficients) with confidence intervalls as bar chart or dot plot. Depending on the type parameter, this function may also plot model assumptions for generalized linear models, or predicted probabilities of coefficients.

Usage

sjp.glm(fit, type = "dots", sortOdds = TRUE, title = NULL,
  axisLabels.y = NULL, axisTitle.x = "Odds Ratios", axisLimits = NULL,
  breakTitleAt = 50, breakLabelsAt = 25, gridBreaksAt = 0.5,
  transformTicks = FALSE, geom.size = 3, geom.colors = "Set1",
  hideErrorBars = FALSE, interceptLineType = 2,
  interceptLineColor = "grey70", coord.flip = TRUE, showIntercept = FALSE,
  showAxisLabels.y = TRUE, showValueLabels = TRUE, labelDigits = 2,
  showPValueLabels = TRUE, showModelSummary = TRUE, facet.grid = TRUE,
  show.se = FALSE, showOriginalModelOnly = TRUE, printPlot = TRUE)

Arguments

Value

(Invisibly) returns a structure with following elements:
  • plot: ggplot-object with the complete plot
  • mydf: data frame that was used for setting up the ggplot-object
  • mydf.mp: a list of data frames with the data for metric predictors (terms of typenumeric), which will be plotted ifshowContPredPlotsisTRUE
  • plot.mp: a list of ggplot-objects with plots of metric predictors (terms of typenumeric), which will be plotted ifshowContPredPlotsisTRUE

See Also

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

Examples

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

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

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

# print Odds Ratios as bars
sjp.glm(fitOR, type="bars")


# -------------------------------
# Predictors for negative impact
# of care. Data from the EUROFAMCARE
# sample dataset
# -------------------------------
data(efc)
# retrieve predictor variable labels
labs <- get_var_labels(efc)
predlab <- c(labs[['c161sex']],
             paste0(labs[['e42dep']], "(slightly)"),
             paste0(labs[['e42dep']], "(moderate)"),
             paste0(labs[['e42dep']], "(severely)"),
             labs[['barthtot']],
             paste0(labs[['c172code']], "(mid)"),
             paste0(labs[['c172code']], "(high)"))
# 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
mydf <- na.omit(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)))
# fit model
fit <- glm(y ~., data = mydf, family = binomial(link = "logit"))
# plot odds
sjp.glm(fit,
        title = labs[['neg_c_7']],
        axisLabels.y = predlab)

# plot probability curves (predicted probabilities)
# of coefficients
sjp.glm(fit,
        title = labs[['neg_c_7']],
        axisLabels.y = predlab,
        type = "prob")

Run the code above in your browser using DataLab