Answer

Moderation vs mediation: what is the difference, and how do you report each?

A frequently asked statistics question ·

regressionbootstrapcausal inference

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.

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

Common mistakes

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

More answered questions

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 question

Written 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.