Learn R Programming

sjPlot (version 1.7)

sjp.int: Plot interaction effects of (generalized) linear (mixed) models

Description

Plot regression (predicted values) or probability lines (predicted probabilities) of significant interaction terms to better understand effects of moderations in regression models. This function accepts following fitted model classes:
  • linear models (lm)
  • generalized linear models (glm)
  • linear mixed effects models (lme4::lmer)
  • generalized linear mixed effects models (lme4::glmer)
Note that beside interaction terms, also the single predictors of each interaction (main effects) must be included in the fitted model as well. Thus, lm(dep ~ pred1 * pred2) will work, but lm(dep ~ pred1:pred2) won't!

Usage

sjp.int(fit, diff = FALSE, moderatorValues = "minmax",
  swapPredictors = FALSE, plevel = 0.05, title = NULL,
  fillColor = "grey", fillAlpha = 0.4, geom.colors = "Set1",
  axisTitle.x = NULL, axisTitle.y = NULL, legendLabels = NULL,
  showValueLabels = FALSE, breakTitleAt = 50, breakLegendLabelsAt = 20,
  breakAnnotationLabelsAt = 50, axisLimits.y = NULL, gridBreaksAt = NULL,
  showInterceptLines = FALSE, showInterceptLabels = TRUE,
  interceptLineColor = "darkseagreen4", estLineColor = "darkslategray4",
  lineLabelSize = 3.7, lineLabelColor = "black",
  lineLabelString = "(no interaction)", printPlot = TRUE)

Arguments

Value

(Insisibily) returns the ggplot-objects with the complete plot-list (plot.list) as well as the data frame that were used for setting up the ggplot-objects (df.list).

References

  • http://www.theanalysisfactor.com/interpreting-interactions-in-regression/{Grace-Martin K: Interpreting Interactions in Regression}
  • http://www.theanalysisfactor.com/clarifications-on-interpreting-interactions-in-regression/{Grace-Martin K: Clarifications on Interpreting Interactions in Regression}
  • http://www.theanalysisfactor.com/3-tips-interpreting-moderation/{Grace-Martin K: 3 Tips to Make Interpreting Moderation Effects Easier}
  • Aiken and West (1991). Multiple Regression: Testing and Interpreting Interactions.

See Also

Examples

Run this code
# Note that the data sets used in this example may not be perfectly suitable for
# fitting linear models. I just used them because they are part of the R-software.

# fit "dummy" model.
fit <- lm(weight ~ Time * Diet,
          data = ChickWeight,
          x = TRUE)

# show summary to see significant interactions
summary(fit)

# plot regression line of interaction terms
sjp.int(fit)
# plot regression line of interaction terms, including value labels
sjp.int(fit, showValueLabels = TRUE)


# load sample data set
data(efc)
# create data frame with variables that should be included
# in the model
mydf <- data.frame(usage = efc$tot_sc_e,
                   sex = efc$c161sex,
                   education = efc$c172code,
                   burden = efc$neg_c_7,
                   dependency = efc$e42dep)
# convert gender predictor to factor
mydf$sex <- relevel(factor(mydf$sex), ref = "2")
# fit "dummy" model
fit <- lm(usage ~ .*., data = mydf, x = TRUE)
summary(fit)

# plot interactions
sjp.int(fit)

# plot interactions, using mean and sd as moderator
# values to calculate interaction effect
sjp.int(fit, moderatorValues = "meansd")

# plot interactions, including those with p-value up to 0.1
sjp.int(fit,
        plevel = 0.1,
        showInterceptLines = TRUE)

# -------------------------------
# Predictors for negative impact of care.
# Data from the EUROFAMCARE sample dataset
# -------------------------------
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 = as.factor(efc$c161sex),
                   barthel = as.numeric(efc$barthtot))
# fit model
fit <- glm(y ~ sex * barthel,
           data = mydf,
           family = binomial(link = "logit"),
           x = TRUE)
# plot interaction, increase p-level sensivity
sjp.int(fit,
        legendLabels = get_val_labels(efc$c161sex),
        plevel = 0.1)

# compare results to boxplots
sjp.grpfrq(mydf$barthel,
           mydf$y,
           interactionVar = mydf$sex,
           interactionVarLabels = get_val_labels(efc$c161sex),
           legendLabels = c("low burden", "high burden"),
           type = "box")

Run the code above in your browser using DataLab