# 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