Interaction in R: interpreting simple slopes
A significant interaction does not yet answer the question that is usually crucial in a thesis or publication: How exactly does the relationship between X and Y change? Therefore, interpreting simple slopes correctly in an R interaction means examining the slope of a predictor at specific values of the moderator. Only these conditional effects make an interaction result professionally understandable and reportable.
Let's take an example from psychology: It is examined whether study time (X) predicts exam performance (Y) and whether this relationship depends on test anxiety (M). An interaction between study time and anxiety would mean: The benefit of additional study time is not the same for everyone. Whether and how much it differs is shown by the simple slopes.
What an interaction in the linear model indicates
For a linear regression with a continuous predictor X and a continuous moderator M, the model is:
modell <- lm(pruefungsleistung ~ lernzeit * angst, data = daten)
summary(modell)
The asterisk is shorthand for lernzeit + angst + lernzeit:angst. This simplifies the estimation as follows:
Y = b0 + b1X + b2M + b3(X × M) + e
The interaction coefficient b3 describes by how many units the slope of X changes when M increases by one unit. If b3 is negative, the relationship between X and Y weakens as moderator values increase. If it is positive, it strengthens.
This may initially sound clear, but it is not yet a complete substantive interpretation. The coefficient of lernzeit - i.e., b1 - only applies when angst = 0. If the value 0 is outside the realistic or observed range, this main effect has little meaningful substantive significance. This is exactly where the analysis of simple slopes begins.
Interpreting simple slopes correctly
The simple slope of X at a specific moderator value M is:
bX|M = b1 + b3M
It indicates how much Y changes on average when X increases by one unit and the moderator has the specified value. In the example, this would be the change in exam performance with an additional hour of study time, respectively at low, medium, or high test anxiety.
Slopes are often examined at the mean of the moderator as well as one standard deviation below and above it. These values are often briefly referred to as "low", "medium", and "high" levels. However, they are not automatically groups in your sample. They are selected points on a continuous scale.
Assuming the estimated simple slopes are:
- at low anxiety: b = 2.10, 95% CI [1.20; 3.00]
- at medium anxiety: b = 1.10, 95% CI [0.45; 1.75]
- at high anxiety: b = 0.10, 95% CI [-0.85; 1.05]
Do not infer differences from individual p-values
A common interpretation error is: "The slope is significant in group A, not significant in group B, so the groups differ." This conclusion is not permissible. Whether the slopes differ is tested by the interaction term itself - or an equivalent contrast. Different significance levels of individual simple slopes do not prove a difference on their own.
Conversely, a significant interaction can exist even if not every selected simple slope is significant. This depends on, among other things, on sample size, dispersion, selected moderator values, and estimation precision.
Interaction in R: simple slopes with emmeans
For practical evaluation, the emmeans package is suitable. It calculates estimated marginal means and trends from the estimated regression model. For simple slopes of a continuous predictor, use emtrends().
install.packages("emmeans")
library(emmeans)
mittelwert_angst <- mean(daten$angst, na.rm = TRUE)
sd_angst <- sd(daten$angst, na.rm = TRUE)
werte_angst <- c(
mittelwert_angst - sd_angst,
mittelwert_angst,
mittelwert_angst + sd_angst
)
trends <- emtrends(
modell,
specs = ~ angst,
var = "lernzeit",
at = list(angst = werte_angst)
)
summary(trends, infer = c(TRUE, TRUE))
The output contains the estimated slope of lernzeit for each specified anxiety value, its standard error, a confidence interval, and a test against zero. Control variables included in the model are taken into account. However, the interpretation remains the same: Each row describes the relationship between study time and exam performance under a specific condition of anxiety.
If you can provide a substantive justification for the moderator values, they are often better than the rule "mean plus or minus one standard deviation". On a scale of 1 to 5, for example, the values 1, 3, and 5 could be more understandable. The prerequisite is that these values are not far outside the actually observed data. Very few cases at the edges lead to uncertain, highly model-dependent statements.
Centering facilitates interpretation but does not change the interaction
For continuous variables, mean centering is often useful. The mean is subtracted from the respective value:
daten$lernzeit_c <- scale(daten$lernzeit, center = TRUE, scale = FALSE)
daten$angst_c <- scale(daten$angst, center = TRUE, scale = FALSE)
modell_c <- lm(pruefungsleistung ~ lernzeit_c * angst_c, data = daten)
After centering, the main effect of lernzeit_c describes the slope at average anxiety. The main effect of angst_c correspondingly describes the relationship of anxiety with exam performance at average study time. This is usually considerably more plausible than an interpretation at a value of zero.
The interaction coefficient and its significance do not change through mean centering alone. The predicted values also remain identical. It looks different if you standardize variables, categorize them, or substantively change the model. Then the conclusions may not necessarily change, but the scale and thus the meaning of the coefficients.
The graphic is both control and explanation
An interaction graphic should not just be decorative. It helps to check whether the calculated simple slopes fit the data structure. Show predicted values of Y over the relevant range of X and draw separate lines for selected moderator values. Confidence bands make visible where the estimation is precise and where it becomes uncertain.
Pay special attention to whether the lines only differ at the outermost edge of the data range. In such areas, there are often few observations. A formally significant interaction can then be practically difficult to interpret. Also check outliers, linearity, homoscedasticity, and the distribution of the residuals. An interaction model is no substitute for proper model diagnostics.
When the moderator is categorical
If the moderator is a group - such as therapy form, gender, or measurement time - the principle remains the same. The simple slope of X is then estimated within each group. Reference coding is important: The coefficient of X refers to the reference group, while the interaction term represents the difference in slopes compared to this group.
modell_gruppe <- lm(pruefungsleistung ~ lernzeit * therapieform, data = daten)
emtrends(modell_gruppe, specs = ~ therapieform, var = "lernzeit")
With more than two groups, additional contrasts can be useful if concrete research questions exist. Unfocused comparisons of all groups, on the other hand, increase the number of tests and make a clear presentation of results more difficult.
How to report the result comprehensibly
A good results text combines model testing, direction, and magnitude. For example: "The relationship between study time and exam performance was moderated by test anxiety, b = -0.50, 95% CI [-0.82; -0.18], p = .003. At low anxiety, an additional hour of study time was associated with exam performance that was 2.10 points higher, while at high anxiety, there was no statistically detectable relationship."
Add the moderator values used and make it clear whether they are unstandardized or standardized coefficients. Causal formulations such as "study time leads to" are only justified with a suitable study design. In cross-sectional data, formulations such as "was associated with" or "was associated with" are more appropriate.
If the choice of moderator values, coding, or reporting format is open in your project, an individual statistics consultation can help to build the model with professional justification and to interpret the results comprehensibly via the contact form.