Statistics Glossary → Mediation Analysis
Mediation Analysisanalysis
An analysis that shows how much of a variable's (X) effect on an outcome (Y) is transmitted through a third variable (the mediator, M), by estimating the indirect effect and its confidence interval.
Concept
Knowing that an effect exists is often not enough; the question 'how does the effect come about?' also matters. If regular exercise improves mood, part of this may be thanks to better sleep. Mediation analysis splits the total effect of X on Y into an indirect effect passing through M and a direct effect independent of M.
Two regression equations are fitted: M = a·X + …, Y = c'·X + b·M + … . a shows how much X changes the mediator, and b how much the mediator changes the outcome with X held fixed. The indirect effect is their product (ab), the direct effect is c', and the total effect is c = c' + ab. Because the sampling distribution of ab is usually skewed, its significance is best judged with a bootstrap confidence interval: if the interval excludes zero, the indirect effect is significant. If c' also remains significant the mediation is partial; if c' is near zero it is full mediation. The model extends to several mediators (parallel or serial) and to cases where the indirect effect changes with a moderator (moderated mediation).
Mediation is a causal claim: it assumes X precedes M and M precedes Y, and that no unmeasured confounders explain the X-M or M-Y relationships. In one-time (cross-sectional) data this ordering cannot be proven, and the result must be interpreted in the light of theory and design. An unreliably measured mediator can also bias the indirect effect.
When to use it
- When the question is through which intermediate mechanism an effect works (does a training programme change behaviour by increasing knowledge, does a treatment reduce pain by reducing inflammation?).
- To test several mechanisms together, use a parallel or serial multiple-mediator model; when asking whether the indirect effect differs by a group or a continuous variable, use a moderated mediation model.
- With several outcomes, latent variables or more complex directed relationships, path analysis or structural equation modelling is more suitable; with repeated measurements over time, longitudinal mediation models are.
An everyday example
A middle school knows that pupils' weekly reading time raises their Turkish exam scores, but wonders whether this happens by building vocabulary. In 200 pupils, reading time predicts a vocabulary test (path a), and vocabulary predicts the exam score with reading time held fixed (path b). If the indirect effect ab and its bootstrap confidence interval exclude zero, part of the reading effect is transmitted through vocabulary; for example, 40% of the total effect.
Parameters in MerQur
X (independent), M (mediator), Y (dependent)
Concept: X is the source of the effect (antecedent), M the intermediate variable that carries it (mediator) and Y the outcome. The mediation claim rests on the assumption that the three follow one another in the order X → M → Y.
Everyday example: In the school example, X is weekly reading time, M vocabulary and Y the Turkish exam score. The order comes from theory: reading happens first, then vocabulary develops, then the score rises.
What it does: The antecedent, mediator and outcome variables. The M list shows only numeric columns; the X and Y lists also contain non-numeric columns at the end (text X is used as multicategorical X, text Y as binary Y).
Effect on the result: All paths and the indirect effect change.
On the validation data: hsbdemo (X = math, M = read, Y = science): a = 0.7248, b = 0.3654, c' = 0.4017, c = 0.6666, ab = 0.2649.
Bootstrap (B) (100 to 50 000; default 5000)
Concept: Because the indirect effect is the product of two coefficients, its distribution is skewed and simple formulas approximate it poorly. The bootstrap draws thousands of new samples from the data with replacement and recomputes ab in each; the distribution of these values gives the confidence interval.
Everyday example: From the 200 pupils' records, new '200-pupil classes' are drawn 5,000 times with replacement, and each time the indirect effect of reading through vocabulary is computed. If the middle 95% of these 5,000 values excludes zero, the mediation is significant.
What it does: Estimates the sampling distribution of the indirect effect by case resampling; the confidence interval and the bootstrap p come from it.
Effect on the result: Only the SE, p and CI of the indirect effect rows change; the regression paths do not change. A warning is given for B < 1000.
On the validation data: hsbdemo, bias-corrected 95%: B = 100: SE 0.0545, CI [0.1793, 0.3874]; 1000: 0.0580, [0.1464, 0.3850]; 5000: 0.0558, [0.1562, 0.3804]; 20000: 0.0547, [0.1572, 0.3746].
Seed (0 to 99999; default 42)
Concept: The seed is the starting point of the random resampling. Running the analysis with the same seed gives the same bootstrap samples and the same confidence interval; different seeds move the limits slightly.
Everyday example: So that an interval reported in a paper as [0.15, 0.38] can be reproduced exactly, the seed used is reported. With a different seed the limits may shift slightly, for example to [0.16, 0.37]; this wobble shrinks as B grows.
What it does: Fixes the bootstrap samples (reproducibility).
Effect on the result: Only the bootstrap endpoints change; the point estimates do not change.
On the validation data: Seed 0: CI [0.1617, 0.3705]; 2026: [0.1653, 0.3779]; 42: [0.1562, 0.3804]. The Monte Carlo margin is determined from the distribution across seeds 1 to 30.
Covariates
Concept: Covariates are control variables added to both the mediator and the outcome equations. By holding fixed factors that could confound the X-M or M-Y relationship, they help estimate the indirect effect more accurately.
Everyday example: Children from wealthier families may both read more and have a richer vocabulary. Adding family income as a covariate estimates the indirect effect cleared of the income difference.
What it does: Control variables added to both the M and the Y equation.
Effect on the result: The paths and the indirect effect change; the covariate coefficients are given in the "Y ~ c (covariate)" rows.
On the validation data: estress (ese, sex, tenure) ab = 0.1127; hsbdemo (ses, female) ab from 0.2649 to 0.2394; jobs (econ_hard, sex, age) ab = -0.0157.
Additional mediators and Multiple-mediator model (Parallel / Serial)
Concept: In a parallel model, several mediators sit side by side between X and Y, each forming a separate indirect path. In a serial model the mediators form a chain: X affects the first mediator, which affects the second.
Everyday example: If reading time develops both vocabulary and reading speed, the parallel model gives the share of each path separately. If reading first builds vocabulary and vocabulary then builds comprehension, the serial model tests the chain X → vocabulary → comprehension → score.
What it does: Parallel (Hayes (2022) mediation framework, Model 4): a_i·b_i for each mediator, the total indirect effect and pairwise contrasts. Serial (Model 6, two mediators): the paths X→M1→Y, X→M2→Y and X→M1→M2→Y.
Effect on the result: The number of indirect effects and the contrasts change.
On the validation data: hsbdemo parallel read + write: total 0.3476, read 0.2186, write 0.1290; serial X→read→write→Y: 0.0463. pmi serial (Hayes): 0.2033; 0.1402; 0.0488.
Confidence Level (%90 / %95 / %99 / Other, custom value)
Concept: Sets the confidence level of the interval estimates for the path coefficients and the indirect effect; the higher the level, the wider the interval and the more likely it is to include zero.
Everyday example: If the 95% interval for the indirect effect is [0.15, 0.38], asking for 99% widens it to something like [0.12, 0.42]. Since neither includes zero, the mediation conclusion stays the same.
What it does: The t interval on the regression paths (z for binary Y) and the bootstrap interval of the indirect effect are given at the same level.
Effect on the result: Only the interval limits change.
On the validation data: Indirect effect CI (bias-corrected): 90% [0.1755, 0.3603], 95% [0.1562, 0.3804], 99% [0.1226, 0.4173]; for c' 90% [0.2818, 0.5217].
Bootstrap CI type (Bias-corrected BC / Percentile / BCa)
Concept: These are different ways of building a confidence interval from the bootstrap values. The percentile interval takes the lower and upper 2.5% points of the bootstrap distribution; the bias-corrected (BC) and BCa intervals try to correct for shift and skewness. Because the BC interval can inflate the Type I error (false alarm) rate in some situations, current recommendations mostly favour the percentile interval.
Everyday example: From the same 5,000 bootstrap values the percentile interval may be [0.151, 0.376] and the BC interval [0.156, 0.380]. When the limits are far from zero the choice does not change the conclusion; when a limit is very close to zero, which type is used should be stated in advance.
What it does: BC is the percentile with z0 bias correction; Percentile takes the α/2 and 1-α/2 percentiles; BCa is BC with a jackknife acceleration. The default is Percentile; the percentile bootstrap is the current recommendation (Hayes 2022; Tibbe and Montoya 2022).
Effect on the result: Only the indirect effect interval changes.
On the validation data: hsbdemo: BC [0.1562, 0.3804], Percentile [0.1511, 0.3756], BCa [0.1554, 0.3791]. Percentiles are computed with linear interpolation (Hyndman-Fan type 7).
Moderator (W) and Moderation model (Model 7 / Model 14)
Concept: In moderated mediation, the size of the indirect effect changes with a moderator (W). W can moderate the a path, where X affects the mediator, or the b path, where the mediator affects the outcome; the index of moderated mediation tests whether this change is significant.
Everyday example: If reading builds vocabulary more strongly when the teacher holds class discussions about the books, W is 'class discussion' and it moderates the a path. The indirect effect comes out larger in classes with discussion.
What it does: Conditional indirect effect: in Model 7, W moderates the a path; in Model 14, the b path. The index of moderated mediation (a3·b or a·b3) and the conditional indirect effects at the 16th, 50th and 84th percentiles of W (at two values for binary W) are given.
Effect on the result: The indirect effects become conditional. If W is not selected, the model option has no effect.
On the validation data: protest (W = sexism) Model 7 index 0.1450, Model 14 0.0881; teams (W = negexp) Model 14 index -0.3204. The W probe values in MerQur are 4.25 / 5.12 / 5.896.
Sobel test (Extra output)
Concept: The Sobel test approximates the standard error of the indirect effect by formula and assumes that ab is normally distributed. Since this often fails, it has less power than the bootstrap interval, especially in small samples; it is reported as supplementary information.
Everyday example: If a reviewer asks 'what does the Sobel test say?', its z value can be reported. With 200 pupils Sobel and the bootstrap usually agree; in a class of 30, the bootstrap interval is the more reliable basis.
What it does: Normal theory tests: Sobel (first order), Aroian (+s_a²s_b²) and Goodman (-s_a²s_b²); a: M ~ X, b: Y ~ M | X (OLS SE).
Effect on the result: Only adds tests.
On the validation data: hsbdemo: Sobel SE 0.05258 (z 5.037), Aroian 0.05272 (z 5.024), Goodman 0.05244.
Binary Y (Extra output)
Concept: When the outcome is binary (0/1), the Y equation is fitted by logistic regression and the b path is on the logit (log-odds) scale. The indirect effect is therefore not read on the same scale as in the linear model, and its sign depends on which level is coded 1.
Everyday example: If the outcome is 'passed / failed the exam', the effect of vocabulary is expressed on the log of the odds of passing. If 'failed' instead of 'passed' is coded 1, the indirect effect has the same size but the opposite sign.
What it does: The Y equation is logistic; the indirect effect is a·b (b on the logit scale; the Hayes 2022 framework). The levels are sorted and the first is taken as 0.
Effect on the result: b and the indirect effect change; the total and direct effects are on the logit scale (c ≠ c' + ab; expected in logistic). Effect sizes are not given for binary Y.
On the validation data: hsbdemo honors (text; "not enrolled" = 1) ab = -0.0514; numeric honors (enrolled = 1) ab = +0.0514 (the sign depends only on the coding and is stated in the output). framing cong_mesg (with covariates) ab = 0.5358.
Multicategorical X (text X; automatic)
Concept: When X has more than two categories, it is expanded into indicator (dummy) variables and a separate relative indirect effect is estimated for each category against the base category.
Everyday example: If X is 'school type' (state, private, academy) with 'state' as the base, the model answers separately for each type 'how much does attending this school rather than a state school affect the score through vocabulary?'.
What it does: Relative indirect effects with indicator coding (the alphabetically first level is the baseline level).
Effect on the result: A separate relative effect is given for each level.
On the validation data: hsbdemo prog (baseline level "academic"): general -3.9457, vocation -6.1356; framing educ (baseline level "bachelor's degree or higher"). The baseline level is stated in the output.
Example on real data
Data: UCLA OARC hsbdemo
Variables: X math (mathematics score), mediator M read (reading), Y science
- Question: Is part of the effect of the mathematics score (math, X) on the science score (science, Y) transmitted through reading skill (read, M)? (n = 200)
- Paths: The a path (math -> read) is 0.7248, the b path (read -> science, controlling for math) 0.3654; both p < .001.
- Result: Indirect effect ab = 0.2649, 95% percentile bootstrap CI [0.151, 0.376] (B = 5000); because the interval does not contain 0, the mediation effect is significant.
- Direct and total effect: Total effect c = 0.6666; when read is controlled, the direct effect c' = 0.4017 (p < .001) remains significant, so the mediation is partial (c = c' + ab).
- Effect size: Completely standardized indirect effect ab_cs = 0.2506; proportion mediated P_M = 0.3973, that is, about 40% of the total effect of math on science is transmitted through reading.
- Limitation: In cross-sectional data, mediation does not prove the causal order; the endpoints of the bootstrap interval depend on the random samples (seed 42).
- APA: Indirect effect, ab = 0.265, 95% CI [0.15, 0.38], p < .001; direct effect c' = 0.40, p < .001 (partial mediation).
Related concepts
Bootstrap (resampling)Random seedIndirect effect (mediation)Sobel testModerator variableBCa bootstrap confidence intervalCovariateDummy (indicator) variable coding
The numbers in the examples are MerQur's output on independent, publicly available validation data; see the MerQur Technical Note for details.