Answer
Moderation vs mediation: what is the difference, and how do you report each?
The short answer
Mediation means X affects Y partly through a third variable M (X → M → Y), and you test the indirect effect a × b, usually with a bootstrap confidence interval. Moderation means the size or direction of X's effect depends on a third variable W, and you test the X × W interaction, then describe the effect of X at a few values of W. One is a causal chain; the other is an "it depends".
The difference in one sentence each
Both ideas involve a third variable, which is why they get confused, but they answer different questions.
- Mediation explains how or why X affects Y. The third variable, the mediator M, sits between them: X changes M, and M in turn changes Y. Example: a training course (X) raises confidence (M), and confidence raises job performance (Y).
- Moderation explains when, or for whom, X affects Y. The third variable, the moderator W, does not carry the effect; it changes how strong it is, or even its sign. Example: the course improves performance a lot for new staff but hardly at all for experienced staff, so experience (W) moderates the effect.
- A quick test for which one you mean. If your sentence contains "through" or "because of", you are describing mediation. If it contains "depends on", "stronger for" or "only when", you are describing moderation.
- The same variable can play either role in different theories, so the label comes from your hypothesis, not from the data.
The diagram and the regressions behind each
Mediation (a chain): X changes M, and M changes Y
X ----a----> M ----b----> Y
X ---------- c' ---------> Y indirect effect = a * b
Moderation (an 'it depends'): W changes the X -> Y arrow itself
X ----------------------> Y
^
|
W tested by the X * W interaction
Simple mediation uses two regressions. The first, M on X, gives the a path. The second, Y on X and M together, gives the b path (M's effect on Y holding X constant) and the direct effect c′ (X's effect on Y that does not pass through M). The indirect effect is the product a × b. With ordinary least squares and a continuous mediator, the total effect c from regressing Y on X alone splits exactly into c = c′ + a × b.
Moderation uses one regression with a product term: Y on X, W and X × W. The interaction coefficient says how much the slope of X changes for each one-unit increase in W. If it is clearly different from zero, report the slope of X at a few chosen values of W (often the mean and one standard deviation either side), known as simple slopes. Deciding which interactions belong in a model at all is a separate question, covered on our page about which interaction terms to include.
See it in R and Python
The code simulates 200 people. In the first part, X raises M and M raises Y, with a smaller direct path from X to Y as well. It estimates the paths and builds a percentile bootstrap confidence interval for a × b from 5,000 resamples, refitting both regressions each time. In the second part, a moderator W changes the slope of X, and the code fits the interaction model and computes simple slopes. Only base R and NumPy/SciPy are needed.
R
set.seed(2611)
n <- 200
# Mediation: X changes M, and M changes Y (plus a direct path X -> Y)
x <- rnorm(n)
m <- 0.5 * x + rnorm(n) # a path
y <- 0.4 * m + 0.2 * x + rnorm(n) # b path and direct effect c'
a <- unname(coef(lm(m ~ x))["x"])
fy <- coef(lm(y ~ x + m))
b <- unname(fy["m"]); c_dir <- unname(fy["x"])
c_tot <- unname(coef(lm(y ~ x))["x"])
round(c(a = a, b = b, indirect = a * b, direct = c_dir, total = c_tot), 3)
# Percentile bootstrap CI for the indirect effect a * b
boot_ab <- replicate(5000, {
i <- sample(n, replace = TRUE)
coef(lm(m[i] ~ x[i]))[2] * coef(lm(y[i] ~ x[i] + m[i]))[3]
})
round(quantile(boot_ab, c(0.025, 0.975)), 3)
# Moderation: the effect of X on Y depends on W (an interaction)
w <- rnorm(n)
y2 <- 0.3 * x + 0.2 * w + 0.25 * x * w + rnorm(n)
mod <- lm(y2 ~ x * w)
round(coef(summary(mod)), 3)
# Simple slopes: effect of X at low (-1 SD), mean and high (+1 SD) W
w_at <- mean(w) + c(low = -1, mean = 0, high = 1) * sd(w)
round(coef(mod)["x"] + coef(mod)["x:w"] * w_at, 3)
Python
import numpy as np
from scipy import stats
rng = np.random.default_rng(2611)
np.set_printoptions(suppress=True)
n = 200
def ols(y, *cols):
# Least squares with an intercept: coefficients, standard errors, t, p
X = np.column_stack([np.ones(len(y)), *cols])
beta, *_ = np.linalg.lstsq(X, y, rcond=None)
resid = y - X @ beta
df = len(y) - X.shape[1]
se = np.sqrt(np.diag(resid @ resid / df * np.linalg.inv(X.T @ X)))
t = beta / se
return beta, se, t, 2 * stats.t.sf(np.abs(t), df)
# Mediation: X changes M, and M changes Y (plus a direct path X -> Y)
x = rng.normal(size=n)
m = 0.5 * x + rng.normal(size=n) # a path
y = 0.4 * m + 0.2 * x + rng.normal(size=n) # b path and direct effect c'
a = ols(m, x)[0][1]
_, c_dir, b = ols(y, x, m)[0]
c_tot = ols(y, x)[0][1]
print({k: round(float(v), 3) for k, v in
dict(a=a, b=b, indirect=a * b, direct=c_dir, total=c_tot).items()})
# Percentile bootstrap CI for the indirect effect a * b
boot_ab = np.empty(5000)
for r in range(5000):
i = rng.integers(0, n, n)
boot_ab[r] = ols(m[i], x[i])[0][1] * ols(y[i], x[i], m[i])[0][2]
print(np.round(np.quantile(boot_ab, [0.025, 0.975]), 3))
# Moderation: the effect of X on Y depends on W (an interaction)
w = rng.normal(size=n)
y2 = 0.3 * x + 0.2 * w + 0.25 * x * w + rng.normal(size=n)
beta, se, t, p = ols(y2, x, w, x * w)
print(np.round(np.column_stack([beta, se, t, p]), 3)) # rows: intercept, x, w, x:w
# Simple slopes: effect of X at low (-1 SD), mean and high (+1 SD) W
w_at = w.mean() + np.array([-1, 0, 1]) * w.std(ddof=1)
print(np.round(beta[1] + beta[3] * w_at, 3))
All figures below come from one seeded run of the R code. Python's random numbers differ from R's, so its figures differ slightly (an indirect effect of 0.196 with a bootstrap interval of [0.117, 0.287], and an interaction of 0.261, p = .003), but they show the same pattern.
Reading the results
- Mediation paths. X predicted M with a = 0.471, and M predicted Y with b = 0.516 after adjusting for X. Their product, the indirect effect, is 0.243: a one-unit increase in X raises Y by about 0.24 units through M.
- Direct and total effects. The direct effect was 0.250 and the total effect 0.493. Adding the direct and indirect effects (0.250 + 0.243) gives the total, as it must, so about half of X's effect runs through M in this simulation.
- The bootstrap interval. The 95% percentile interval for the indirect effect was [0.157, 0.337]. It excludes zero, which is the usual evidence for mediation. The bootstrap is preferred because the sampling distribution of a product of two coefficients is often skewed, which the older Sobel test ignores.
- Moderation. The interaction coefficient was 0.336 (SE = 0.075, t = 4.457, p < .001): each one-unit increase in W makes the slope of X about 0.34 steeper (W was simulated with an SD of 1, so one unit is roughly one SD).
- Simple slopes. The effect of X was essentially zero at low W (−0.016), 0.302 at the mean of W, and 0.620 at high W. That is the substantive finding: X only matters when W is average or high.
- Main effects in the moderation model. The coefficient of X (0.329) is its slope when W equals zero, not an average effect across all values of W. It is close to the slope at the mean (0.302) here only because W was simulated with a mean near zero.
Common mistakes
- Treating mediation as proof of a mechanism. The indirect effect has a causal meaning only if X comes before M, M comes before Y, and nothing unmeasured drives both M and Y. Randomizing X does not randomize M, so that last assumption remains even in an experiment. With cross-sectional data, say the results are consistent with mediation rather than that they demonstrate it.
- Following the old causal-steps recipe. Baron and Kenny's (1986) steps required a significant total effect before testing mediation and judged mediation from a series of separate significance tests. Current practice tests the indirect effect directly with a bootstrap interval; an indirect effect can exist even when the total effect is not significant.
- Calling a correlated variable a moderator. A moderator is defined by an interaction, not by being related to X or Y. A variable can be strongly correlated with both and moderate nothing.
- Interpreting a lone main effect in the presence of an interaction. Once X × W is in the model, the X coefficient is conditional on W = 0. Centering W makes that point meaningful.
- Mixing the two up when both are present. If an indirect effect itself depends on a moderator, the model is called moderated mediation (conditional process analysis). Hayes's PROCESS models are numbered for these designs: model 4 is simple mediation and model 1 is simple moderation.
Not sure which analysis fits your design? Try our test chooser, and see why bootstrapping works for the idea behind the resampled interval.
How to report mediation and moderation in APA style (7th edition)
For mediation, give each path, the direct and indirect effects, and the bootstrap interval, and state the number of resamples and the interval type. Using the example above: "X predicted M, a = 0.47, and M predicted Y controlling for X, b = 0.52. The indirect effect was 0.24, 95% percentile bootstrap CI [0.16, 0.34], based on 5,000 resamples. The direct effect of X on Y was 0.25 and the total effect 0.49."
For moderation, report the interaction test and then the simple slopes: "The X × W interaction was significant, b = 0.336, SE = 0.075, t(196) = 4.46, p < .001. The slope of X was −0.02 at low W (1 SD below the mean), 0.30 at the mean, and 0.62 at high W (1 SD above)." Add standard errors or confidence intervals for the simple slopes if your software gives them.
In the method section, name the model and software (for example, regression in R, or PROCESS model 4 or 1), say whether predictors were centered, and include a path diagram for mediation. A table of all coefficients with SEs and 95% CIs is the clearest way to give the full results.
Related tools and guides
- APA 7 formatter for regression
- Which statistical test should I use?
- Which interaction terms belong in a regression model?
- Why does bootstrapping work?
- What does it mean to control for a variable?
- Mediation (statistics) on Wikipedia
More answered questions
- Can you test the exclusion restriction of an instrumental variable?
- What does it mean to control for a variable in regression?
- Bagging, boosting and stacking: how do these ensemble methods differ?
Working with your own data?
General answers only go so far. Send us your situation and we'll reply by email within two business days.
Ask your questionWritten by AskStats with AI assistance. This is general information, not advice for your specific data or study. When the results matter, check your approach with a qualified statistician.