This function computes the indirect (mediated) effect in a mediation model
and either tests its significance or calculates statistical power.
It uses regression coefficients from an independent variable to a mediator (a)
and from the mediator to an outcome (b) with their standard errors.
Variance can be estimated using Sobel, Aroian, or Goodman formulas.
Arguments
- type
Character;
"test"to perform a significance test,"power"to estimate power.- n
Numeric; baseline sample size for power calculation (default 25000).
- a
Numeric; regression coefficient from independent variable to mediator.
- sa
Numeric; standard error of
a.- b
Numeric; regression coefficient from mediator to outcome.
- sb
Numeric; standard error of
b.- alpha
Numeric; significance level (default 0.05) for power calculation.
- fold
Numeric; multiplicative factor for sample size in power calculation.
- method
Character; one of
"sobel","aroian","goodman"specifying the variance formula.
Value
If type = "test", a named numeric vector with:
effect: indirect effect estimate (\(ab\))se: standard errorz: z-statisticp: two-sided p-valuelcl: lower 95% confidence limitucl: upper 95% confidence limit
If type = "power", a named numeric vector with:
sample_size: effective sample size (fold * n)power: estimated statistical power
Details
The indirect effect is \(ab\), representing the portion of the effect of \(X\) on \(Y\) transmitted through mediator \(M\).
Standard errors of the indirect effect are approximated using the delta method:
Sobel: \(SE = \sqrt{b^2 s_a^2 + a^2 s_b^2}\)
Aroian: \(SE = \sqrt{b^2 s_a^2 + a^2 s_b^2 + s_a^2 s_b^2}\)
Goodman: \(SE = \sqrt{b^2 s_a^2 + a^2 s_b^2 - s_a^2 s_b^2}\)
The z-statistic is \(z = ab / SE(ab)\), assumed to follow a standard normal distribution under \(H_0: ab = 0\).
Two-sided p-value: \(p = 2 \Phi(-|z|)\) 95% confidence interval: \(ab \pm 1.96 \cdot SE(ab)\)
Power is based on a non-central chi-square approximation: \(\lambda = z^2 \cdot \text{fold}\) \(Power = P(\chi^2_1(\lambda) > \chi^2_{1,1-\alpha})\), where \(\chi^2_{1,1-\alpha}\) is the critical value at significance level \(\alpha\).
These tests assume large samples. For small samples, bootstrap confidence intervals are recommended.
References
Freathy RM, Timpson NJ, Lawlor DA, Pouta A, Ben-Shlomo Y, Ruokonen A, Ebrahim S, Shields B, Zeggini E, Weedon MN, Lindgren CM, Lango H, Melzer D, Ferrucci L, Paolisso G, Neville MJ, Karpe F, Palmer CN, Morris AD, Elliott P, Jarvelin MR, Smith GD, McCarthy MI, Hattersley AT, Frayling TM (2008). “Common variation in the FTO gene alters diabetes-related metabolic traits to the extent expected given its effect on BMI.” Diabetes, 57(5), 1419-26. doi:10.2337/db07-1466 .
Kline RB (2005). Principles and Practice of Structural Equation Modeling, 2nd edition. The Guilford Press, New York, NY.
MacKinnon DP (2008). Introduction to Statistical Mediation Analysis. Taylor & Francis Group, New York, NY.
Preacher KJ, Leonardelli GJ (2001). “Calculation for the Sobel Test—An Interactive Calculation Tool for Mediation Tests.” https://quantpsy.org/sobel/sobel.htm. Accessed 2026-06-07.