# 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