Written and maintained by CASRAI Editorial Board
Last updated
A mediator variable (also called a mediating or intervening variable) is a variable that carries the effect of one variable on another. If a predictor X influences an outcome Y by first changing a third variable M, then M is the mediator. Mediators describe the “how” or “why” of a relationship between two other variables. This guide gives the definition, the path formulas, a fully computed worked example, and the modern way to test and report the indirect effect.
What is a mediator variable?
A mediator variable is a variable M that sits on the causal pathway between a predictor X and an outcome Y. In David Kenny’s account of mediation, the effect of X on Y “may be mediated by a process or mediating variable M”: X causes M (path a), and M causes Y (path b). The University of Zurich multivariate statistics course puts it this way: “Mediators describe the how or why of a relationship between two other variables.”
The same idea appears under several names. A mediating variable and an intervening variable both refer to M. The amount of mediation, the product ab, is called the indirect effect. A mediator is not the same thing as a moderator, which changes the strength of a relationship rather than carrying it; see mediator vs moderator for that distinction, and independent vs dependent variable for the roles of X and Y.
The mediation formula: paths a, b, c and c’
Mediation is described with three regression equations. Using the notation in the Zurich course material, each equation has an intercept and an error term (e).
- Total effect (path c): Y = b0 + c·X + e. This is the effect of X on Y ignoring M. Kenny calls it the total effect.
- Path a: M = b0 + a·X + e. This is the effect of X on the mediator.
- Paths b and c’: Y = b0 + c’·X + b·M + e. Here b is the coefficient of M (the effect of the mediator on Y, holding X constant) and c’ is the coefficient of X. Kenny calls c’ the direct effect, the effect of X on Y not due to the mediator.
The indirect effect is ab, the product of the two coefficients. The paths are tied together by one identity: total effect = direct effect + indirect effect, that is, c = c’ + ab, which rearranges to c’ = c − ab.
Worked example with numbers
Illustrative example, not real data. Suppose X is hours of weekly study support, M is study-skills score, and Y is exam score, and suppose the three regressions return these coefficients:
- Path a (X predicting M): a = 0.50
- Path b (M predicting Y, controlling for X): b = 0.40
- Direct effect (X predicting Y, controlling for M): c’ = 0.15
The arithmetic:
- Indirect effect: ab = 0.50 × 0.40 = 0.20.
- Total effect: c = c’ + ab = 0.15 + 0.20 = 0.35.
- Check by rearranging: c’ = c − ab = 0.35 − 0.20 = 0.15, which matches the direct effect.
- Share of the total effect that runs through M: ab / c = 0.20 / 0.35 = 0.571, about 57%.
In words: a one-unit increase in X raises Y by 0.35 in total, of which 0.20 travels through the mediator and 0.15 does not.
How to interpret the indirect effect
The point estimate ab is only half the answer. Kenny’s page states that the currently recommended test of the indirect effect is bootstrapping, and the Zurich course material recommends the percentile bootstrap confidence interval. The Zurich course gives the decision rule: significant mediation occurs when the confidence interval for the indirect effect does not include 0.
| What you see | How to read it |
|---|---|
| Bootstrap confidence interval for ab excludes 0 | Significant mediation (Zurich course material) |
| Bootstrap confidence interval for ab includes 0 | No significant indirect effect |
| c = c’ + ab holds in your output | Your path estimates are consistent with each other (Kenny) |
| ab and c’ have opposite signs | They can cancel, so the total effect c can be small or non-significant while mediation is present; a significant total effect is not required (Zurich course material) |
For a fuller treatment of testing, sample size and reporting, see mediation analysis: methods and reporting.
Assumptions and common mistakes
- Using the Sobel test. Kenny notes that the Sobel test “falsely assumes that the indirect effect has a normal distribution” and that “it should no longer be used.” The product of two coefficients is generally not normally distributed. Use a bootstrap interval instead; the Sobel test and its alternatives explains the options.
- Requiring a significant total effect first. A significant total effect c is not required, because ab and c’ can have opposite signs and cancel.
- Ignoring confounding. Kenny notes that Baron and Kenny (1986), which he calls the most prominent paper discussing the SEM approach to mediation, does not even mention confounding as an assumption. The a and b paths are causal claims; a variable that influences both M and Y can distort b. See confounding variable.
- Treating statistical mediation as proof of mechanism. A significant ab shows a pattern in the data that fits the mediation model. Whether the effect is causal depends on the design and assumptions; see causal mediation analysis.
How to report mediation in APA style
Report the a path, the b path, the direct effect, the indirect effect and its bootstrap interval, plus the number of resamples. The numbers below are the illustrative values from the worked example; the interval is a placeholder to show the format.
Study-skills score mediated the effect of study support on exam score. Study support predicted study-skills score (a = 0.50), and study-skills score predicted exam score controlling for study support (b = 0.40). The indirect effect was ab = 0.20, 95% percentile bootstrap CI [0.11, 0.30] (5,000 resamples), and the direct effect was c’ = 0.15 (total effect c = 0.35).
If you used the PROCESS macro, see PROCESS model numbers and reporting for what to state about the model.
How to calculate it in Excel, R or Python
All three snippets estimate a, b, c’ and ab from the regressions above. For the interval, resample your rows with replacement, recompute ab each time, and take the 2.5th and 97.5th percentiles.
Excel
Put X in column A, M in column B and Y in column C, with data in rows 2 to 101.
a =SLOPE(B2:B101, A2:A101)
c =SLOPE(C2:C101, A2:A101)
b =INDEX(LINEST(C2:C101, A2:B101), 1, 1)
c' =INDEX(LINEST(C2:C101, A2:B101), 1, 2)
ab =a*b
LINEST returns coefficients in reverse column order, so the first value is the coefficient of M (column B) and the second is the coefficient of X (column A). Excel has no built-in bootstrap, so use R or Python for the interval.
R
a <- coef(lm(M ~ X, data = d))["X"]
fit <- lm(Y ~ X + M, data = d)
b <- coef(fit)["M"]; cp <- coef(fit)["X"]
ab <- a * b
c_total <- coef(lm(Y ~ X, data = d))["X"] # equals cp + ab
boot <- replicate(5000, {
s <- d[sample(nrow(d), replace = TRUE), ]
coef(lm(M ~ X, s))["X"] * coef(lm(Y ~ X + M, s))["M"]
})
quantile(boot, c(0.025, 0.975))
Python
import numpy as np
rng = np.random.default_rng(1)
def paths(x, m, y):
a = np.polyfit(x, m, 1)[0]
X = np.column_stack([np.ones(len(x)), x, m])
coef = np.linalg.lstsq(X, y, rcond=None)[0]
cp, b = coef[1], coef[2]
c = np.polyfit(x, y, 1)[0]
return a, b, cp, c
a, b, cp, c = paths(x, m, y) # x, m, y are NumPy arrays
ab = a * b # c equals cp + ab
boot = []
for _ in range(5000):
i = rng.integers(0, len(x), len(x))
aa, bb, _, _ = paths(x[i], m[i], y[i])
boot.append(aa * bb)
print(np.percentile(boot, [2.5, 97.5]))
Frequently asked questions
What is a mediator variable?
A variable that lies between a predictor and an outcome and transmits part or all of the predictor’s effect. It explains how or why X affects Y.
What is the difference between a mediator and a moderator?
A mediator carries the effect of X to Y; a moderator changes how strong the X-Y relationship is. See mediator vs moderator and moderation analysis and interaction terms.
What is the indirect effect?
The product ab of the X-to-M path and the M-to-Y path. Kenny calls the amount of mediation, ab, the indirect effect.
How do you test whether a mediator is significant?
Estimate a bootstrap confidence interval for ab. If the interval does not include 0, the indirect effect is significant.
Sources
- Kenny, D. A. “Mediation.” davidakenny.net/cm/mediate.htm (checked 2026-10-29).
- “8 Mediation analysis,” Multivariate statistics course material, University of Zurich. meth.ikmz.uzh.ch/Mediation.html (checked 2026-10-29).








