Skip to content
Statistical RethinkingStatistical Rethinking

7.2 Symmetry of the linear interaction

Interactions are symmetric. If the effect of xx depends on zz, then the effect of zz also depends on xx. This symmetry has important consequences for interpretation and visualization.

7.2.1 The symmetry

The linear interaction model is:

μi=α+βxxi+βzzi+βxzxizi\mu_i = \alpha + \beta_x x_i + \beta_z z_i + \beta_{xz} x_i z_i

The slope of xx is:

∂μ∂x=βx+βxzz\frac{\partial \mu}{\partial x} = \beta_x + \beta_{xz} z

And the slope of zz is:

∂μ∂z=βz+βxzx\frac{\partial \mu}{\partial z} = \beta_z + \beta_{xz} x

The same interaction term βxz\beta_{xz} appears in both. The interaction is symmetric: it is equally true that "the effect of xx depends on zz" and "the effect of zz depends on xx."

# Demonstrate the symmetry of interactions
set.seed(42)
n <- 200
study <- runif(n, 0, 10)
sleep <- runif(n, 4, 9)
score <- 50 + 3 * study + 2 * sleep + 0.5 * study * sleep + rnorm(n, sd = 5)

m_int <- lm(score ~ study * sleep)
bx <- coef(m_int)[2]
bz <- coef(m_int)[3]
bxz <- coef(m_int)[4]

cat("Interaction model:\n")
cat(" beta_study:", round(bx, 3), "\n")
cat(" beta_sleep:", round(bz, 3), "\n")
cat(" beta_study:sleep:", round(bxz, 3), "\n")

cat("\nSlope of study at sleep = 4:", round(bx + bxz _ 4, 3), "\n")
cat("Slope of study at sleep = 6:", round(bx + bxz _ 6, 3), "\n")
cat("Slope of study at sleep = 8:", round(bx + bxz * 8, 3), "\n")

cat("\nSlope of sleep at study = 0:", round(bz + bxz _ 0, 3), "\n")
cat("Slope of sleep at study = 5:", round(bz + bxz _ 5, 3), "\n")
cat("Slope of sleep at study = 10:", round(bz + bxz * 10, 3), "\n")

cat("\nThe interaction is symmetric:\n")
cat(" Effect of study depends on sleep\n")
cat(" Effect of sleep depends on study\n")
cat(" Same coefficient (beta_xz) governs both\n")
Click Run to execute this code in your browser with WebR

7.2.2 Visualizing the symmetry

We can visualize the interaction from either perspective: plot the effect of xx at different values of zz, or plot the effect of zz at different values of xx. Both show the same interaction.

# Visualize the symmetry of interactions
set.seed(42)
n <- 200
study <- runif(n, 0, 10)
sleep <- runif(n, 4, 9)
score <- 50 + 3 * study + 2 * sleep + 0.5 * study * sleep + rnorm(n, sd = 5)

m_int <- lm(score ~ study * sleep)

par(mfrow = c(1, 2))

# Left: effect of study at different sleep levels

study_seq <- seq(0, 10, length.out = 100)
colors <- c("firebrick", "steelblue", "darkgreen")
sleep_vals <- c(4, 6, 8)

plot(NULL, xlim = c(0, 10), ylim = c(40, 130),
xlab = "Study hours", ylab = "Score",
main = "Effect of study at different sleep levels")
for (i in 1:3) {
pred <- coef(m*int)[1] + coef(m_int)[2] * study*seq +
coef(m_int)[3] * sleep*vals[i] +
coef(m_int)[4] * study*seq * sleep_vals[i]
lines(study_seq, pred, lwd = 2, col = colors[i])
}
legend("topleft", legend = paste("Sleep =", sleep_vals), col = colors, lwd = 2)

# Right: effect of sleep at different study levels

sleep_seq <- seq(4, 9, length.out = 100)
study_vals <- c(0, 5, 10)

plot(NULL, xlim = c(4, 9), ylim = c(40, 130),
xlab = "Sleep hours", ylab = "Score",
main = "Effect of sleep at different study levels")
for (i in 1:3) {
pred <- coef(m*int)[1] + coef(m_int)[2] * study*vals[i] +
coef(m_int)[3] * sleep*seq +
coef(m_int)[4] * study*vals[i] * sleep_seq
lines(sleep_seq, pred, lwd = 2, col = colors[i])
}
legend("topleft", legend = paste("Study =", study_vals), col = colors, lwd = 2)

par(mfrow = c(1, 1))
Click Run to execute this code in your browser with WebR
Rethinking

The symmetry is not a choice — it is a mathematical fact. The interaction term x⋅zx \cdot z is the same as z⋅xz \cdot x. There is no "moderator" and "moderated" variable — both moderate each other equally. When we say "the effect of xx depends on zz," we are also saying "the effect of zz depends on xx." The choice of which variable to plot on the x-axis is a presentation choice, not a statistical one. Both perspectives show the same interaction.

Summary of Section 7.2

  • Interactions are symmetric: the effect of xx depends on zz and vice versa.
  • The same coefficient βxz\beta_{xz} governs both perspectives.
  • The slope of xx is βx+βxzz\beta_x + \beta_{xz} z; the slope of zz is βz+βxzx\beta_z + \beta_{xz} x.
  • Visualizing from either perspective shows the same interaction.
  • There is no "moderator" vs "moderated" — both moderate each other.