Mediation Analysis Explained: How to Run, Read and Report It

By Dr. Faheem Afzal Shah, Founder, StatFAS.com · Tool: Mediation Analysis Calculator

Mediation analysis asks how or through what mechanism a predictor affects an outcome. It splits the total effect of X on Y into an indirect effect, passing through a mediator M, and a direct effect that remains. This guide explains the logic, the indirect effect and its bootstrap confidence interval, and a fully worked example.

What is mediation?

The simplest model has X → M → Y. Two regressions are estimated:

M = i1 + aX + e1    Y = i2 + c′X + bM + e2

The indirect effect is a × b. The direct effect is c′. The total effect c, from the regression Y = i3 + cX + e3, equals c′ + ab in linear models fitted to the same complete data. The proportion mediated, ab/c, is often reported but is unstable in small samples and when direct and indirect effects have opposite signs.

How the indirect effect is tested

The older Baron and Kenny (1986) steps rely on a significant total effect and on a series of separate tests; they have low power and do not test ab directly. Modern practice tests the indirect effect itself. The Sobel (1982) test uses z = ab / SE(ab) with SE(ab) = √(b²SEa² + a²SEb²), but it assumes ab is normally distributed, which is rarely true. Bootstrapping the product, resampling cases and recomputing ab many times, gives a percentile confidence interval that does not rely on that assumption (Preacher & Hayes, 2008). If the interval excludes zero, the indirect effect is supported.

Assumptions and causal caution

Regression assumptions apply to each equation. More importantly, causal interpretation requires temporal ordering and no unmeasured confounding of the X–M, M–Y and X–Y relationships, and no X–M interaction. A statistically significant indirect effect in cross-sectional data shows consistency with a mediation model, not proof of mechanism.

Original example (illustrative)

Question. Does weekly mentoring (X, hours) improve job performance (Y) by raising self-efficacy (M)? Data for n = 20 employees (invented):

#MentoringSelf-efficacyPerformance#MentoringSelf-efficacyPerformance
112.328.452.61112.528.253.9
212.329.749.8123.015.840.6
34.221.143.4139.427.050.7
410.827.555.2146.025.746.8
513.529.856.2157.624.349.4
68.030.057.1169.529.554.5
76.323.542.21710.532.956.6
89.621.144.3188.623.146.5
911.827.150.71917.929.355.7
1013.129.854.72011.129.750.3
PathEstimateSEtp95% CI
a: Mentoring → Self-efficacy0.8340.1954.28< .001[0.42, 1.24]
b: Self-efficacy → Performance (controlling X)0.9560.1905.03< .001[0.55, 1.36]
c′: direct effect0.2600.2231.16.260[−0.21, 0.73]
c: total effect1.0570.2414.39< .001[0.55, 1.56]

The indirect effect is ab = 0.834 × 0.956 = 0.797. Check: c′ + ab = 0.260 + 0.797 = 1.057, which equals c = 1.057. The Sobel statistic is z = 0.797/0.245 = 3.26, p = .001. A percentile bootstrap with 5,000 resamples gives a 95% CI for ab of [0.368, 1.278], which excludes zero. Proportion mediated = 0.797/1.057 = 75%.

Interpretation. Mentoring is associated with higher self-efficacy, and higher self-efficacy is associated with better performance after accounting for mentoring. The indirect effect is positive and its bootstrap interval excludes zero, so the data are consistent with self-efficacy carrying part of the mentoring effect. The remaining direct effect (c′ = 0.260) suggests other pathways or measurement limitations. Bootstrap results vary slightly with the random seed, so report the number of resamples. These invented data come from a cross-sectional layout, so this does not demonstrate that mentoring changes performance through self-efficacy.

How to run mediation analysis with StatFAS

Open the Mediation Analysis Calculator. Arrange columns for X, M and Y (and covariates if supported).

Understanding the output

APA 7 reporting example

Mentoring hours were positively associated with self-efficacy (a = 0.83, 95% CI [0.42, 1.24]), which in turn predicted performance (b = 0.96, 95% CI [0.55, 1.36]). The indirect effect of mentoring on performance through self-efficacy was ab = 0.80, 95% bootstrap CI [0.37, 1.28] (5,000 resamples). The direct effect was c′ = 0.26, 95% CI [−0.21, 0.73].

Common mistakes and troubleshooting

Limitations and alternatives

With many mediators or latent variables, structural equation modelling is more flexible (see the SEM tool). For the underlying regressions, see simple linear and multiple linear regression. Causal mediation methods address confounding more explicitly when the design allows.

Conclusion

Mediation analysis estimates how much of an effect passes through an intermediate variable. Test the indirect effect with a bootstrap interval, report all paths with uncertainty, and be explicit that the causal story depends on the design, not on the statistics.

Screenshots to supply (genuine captures only):
1. statfas-mediation-analysis-interface.png, alt: "StatFAS Mediation Analysis Calculator interface"
2. statfas-mediation-analysis-example-data.png, alt: "Example data entered in the StatFAS Mediation Analysis Calculator"
3. statfas-mediation-analysis-settings.png, alt: "Mediation Analysis Calculator settings in StatFAS"
4. statfas-mediation-analysis-result.png, alt: "Mediation Analysis Calculator results generated in StatFAS"

Frequently asked questions

Do I need a significant total effect to test mediation?

No. Current guidance is to test the indirect effect directly. An indirect effect can be present even when the total effect is not significant, for instance when direct and indirect effects have opposite signs.

Why is bootstrapping preferred to the Sobel test?

The product of two coefficients is usually not normally distributed, so the Sobel test's normality assumption fails, particularly in small samples. Bootstrap intervals make no such assumption.

Can I conclude causation from a mediation analysis?

Not from the statistics alone. Causal conclusions need a design with temporal ordering and control of confounding of the X–M, M–Y and X–Y relationships.

References

Author attribution: Dr. Faheem Afzal Shah, Plant Functional Genomics and Regulatory Genomics Researcher; StatFAS.com Founder.