Learn R Programming

sjPlot (version 1.7)

sjp.emm.int: Plot adjusted (estimated marginal) means of interaction (moderation) in linear models

Description

Plot estimated marginal means of (significant) interaction terms in linear models (lm). This function may be used to plot differences in interventions between control and treatment groups over multiple time points.

Usage

sjp.emm.int(fit, swapPredictors = FALSE, plevel = 0.05, title = NULL,
  geom.colors = "Set1", axisTitle.x = NULL, axisTitle.y = NULL,
  legendLabels = NULL, showValueLabels = FALSE, valueLabel.digits = 2,
  breakTitleAt = 50, breakLegendLabelsAt = 20,
  breakAnnotationLabelsAt = 50, axisLimits.y = NULL, gridBreaksAt = NULL,
  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/using-adjusted-means-to-interpret-moderators-in-analysis-of-covariance/{Grace-Martin K: Using Adjusted Means to Interpret Moderators in Analysis of Covariance.}

See Also

  • http://www.strengejacke.de/sjPlot/sjp.emm.int/{sjPlot manual: sjp.emm.int}
  • http://strengejacke.wordpress.com/2014/08/19/visualize-pre-post-comparison-of-intervention-rstats/{Weblog example}
  • sjp.int
  • sjp.aov1

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.

# prepare data frame
df <- data.frame(mpg=mtcars$mpg,vs=factor(mtcars$vs),am=factor(mtcars$am))
# fit "dummy" model.
fit <- lm(mpg~vs+am+vs:am, data=df)
# show summary to see significant interactions
summary(fit)

# plot marginal means of interaction terms
# note we have to adjust plevel, because no interaction
# is significant
sjp.emm.int(fit, plevel=1)
# plot marginal means of interaction terms, including value labels
sjp.emm.int(fit, plevel=1, showValueLabels=TRUE)


# load sample data set
data(efc)
# create data frame with variables that should be included
# in the model
df <- as.data.frame(cbind(burden=efc$neg_c_7,
                          sex=efc$c161sex,
                          education=efc$c172code))
# convert gender predictor to factor
df$sex <- factor(df$sex)
df$education <- factor(df$education)
# name factor levels and dependent variable
levels(df$sex) <- c("female", "male")
levels(df$education) <- c("low", "mid", "high")
df$burden <- set_var_labels(df$burden, "care burden")
# fit "dummy" model
fit <- lm(burden ~ .*., data=df, na.action=na.omit)
summary(fit)

# plot marginal means of interactions, no interaction found
sjp.emm.int(fit)
# plot marginal means of interactions, including those with p-value up to 1
sjp.emm.int(fit, plevel=1)
# swap predictors
sjp.emm.int(fit, plevel=1, swapPredictors=TRUE)

Run the code above in your browser using DataLab