Concept map / Path analysis and mediation
Share
Path analysis and mediation
Fit a mediation model X → M → Y with a direct path, split the total effect into direct and indirect parts, and compare Sobel and bootstrap intervals for the indirect effect.
1Does X act on Y through M?
A tutoring program (X) may raise test scores (Y) partly because it raises study time (M). Path analysis writes that idea as two regressions: M on X with slope a, and Y on X and M with slopes c′ and b. The part of X’s effect that runs through M is the indirect effect a·b. The rest, c′, is the direct effect, and the two add up to the total effect c. It is the smallest kind of structural equation model, fitted by the same maximum likelihood as a CFA.
Set the true paths and the sample size. The lab simulates the people, fits the model, and puts an interval around a·b. How far can that interval be trusted?
The sliders set the true paths. X and the residuals of M and Y each have variance 1.
In this sample of 100, a = 0.40 and b = 0.35, so the indirect effect is a·b = 0.399 × 0.347 = 0.138. The direct effect c′ is 0.142, and the total effect, their sum, is 0.281. The bootstrap interval for a·b excludes zero; the total effect is significant (p = .020).
More controls
Sample 1, the one R draws after set.seed(1). The sliders rescale the same draws.
2No total effect: is there anything to mediate?
A study of 200 people regresses Y on X alone and finds a total effect of 0.07, p = .421. The first of Baron and Kenny's steps stops here. Could the data still show a clear indirect effect of X on Y through M?
3Two intervals for a·b
The indirect effect is a product, and a product of two estimates does not have a normal sampling distribution. The Sobel interval assumes it does. The percentile bootstrap resamples the 100 people 1000 times, refits both regressions each time, and keeps the middle 95% of the products.
Point at a part of a formula to light up its part of the histogram.
With your numbers: SE = √(0.347² × 0.107² + 0.399² × 0.108²) = 0.0567, so Sobel gives 0.138 ± 1.96 × 0.0567 = [0.027, 0.249]. The bootstrap gives [0.050, 0.249], with the upper arm 1.26 times as long as the other.
When a and b are both well away from zero, the products pile up symmetrically and the two intervals agree. When one path is small relative to its standard error, the products bunch near zero on one side and trail off on the other. The bootstrap interval follows that skew; the Sobel interval cannot, so it reaches too far toward zero and misses real effects more often.
4What “the effect disappears” gets wrong
Baron and Kenny's 1986 steps test mediation by asking whether X predicts Y, then whether the X–Y effect shrinks once M is in the model. With the current sample:
- X predicts Y on its own: c = 0.281, p = .020.
- X predicts M: a = 0.399, p < .001.
- M predicts Y with X held fixed: b = 0.347, p = .001.
- The direct effect c′ = 0.142 is not significant, so the steps say full mediation.
Both ends of this recipe can mislead. Step 1 fails whenever c′ and a·b have opposite signs and cancel, as in the prediction above, though M still carries an effect. Step 4 reads a non-significant c′ as a zero c′, which in a small sample it often is not. The modern practice is to estimate a·b and report its bootstrap interval directly.
None of these numbers is a causal effect unless nothing unmeasured drives both M and Y. Randomizing X does not randomize M: a trait that raises both M and Y would inflate b and a·b, and no interval on this page can detect it.
5Check yourself
The tasks use the controls in section 1, including Draw another sample under More controls. They tick themselves when you meet them.
- Set a true direct effect c′ of 0.20 or more, then find a sample in which the estimated c′ is not significant while the bootstrap interval for a·b excludes zero. Baron and Kenny would call this full mediation.Now: true c′ = 0.10; estimated c′ = 0.14, p = .246; bootstrap interval excludes zero
- Find a sample in which the bootstrap interval for a·b excludes zero but the Sobel interval does not.Now: bootstrap [0.050, 0.249], Sobel [0.027, 0.249]
- Make the bootstrap interval lopsided: one arm, from the estimate to an end, at least 1.5 times as long as the other.Now: lower arm 0.088, upper arm 0.111, ratio 1.26
6Fit the mediation model with lavaan
The snippet draws the lab’s starting sample with set.seed(1) and fits it with sem(), labeling the paths so := can define the indirect and total effects. The estimates match the lab: a = 0.399, b = 0.347, a·b = 0.138, c′ = 0.142 with p = .246, and a total of 0.281 with p = .020. lavaan’s default interval for ind, [0.027, 0.249], is the Sobel interval. Its bootstrap interval, [0.049, 0.243], differs a little from the lab’s [0.050, 0.249] because R draws different resamples.
A mediation model with lavaan, delta method and bootstrapShow the code
library(lavaan)
# The lab's starting sample: a = 0.4, b = 0.4, c' = 0.1
set.seed(1)
N <- 100
X <- rnorm(N)
M <- 0.4 * X + rnorm(N)
Y <- 0.1 * X + 0.4 * M + rnorm(N)
d <- data.frame(X, M, Y)
# Label the paths, then define the indirect and total effects
model <- "
M ~ a * X
Y ~ cp * X + b * M
ind := a * b
total := cp + a * b
"
# Delta-method (Sobel) standard errors
fit <- sem(model, data = d)
pe <- parameterEstimates(fit)
print(pe[pe$label != "", c("label", "est", "se", "pvalue",
"ci.lower", "ci.upper")], digits = 3)
# Percentile bootstrap interval from 1000 resamples
fitb <- sem(model, data = d, se = "bootstrap", bootstrap = 1000)
pb <- parameterEstimates(fitb, boot.ci.type = "perc")
print(pb[pb$label == "ind", c("est", "ci.lower", "ci.upper")],
digits = 3)Uses lavaan. Install once with install.packages(c("lavaan")).
What a mediation model can and cannot say
- The indirect effect is the product a·b, and the total effect is c = c′ + a·b. In the starting sample the direct and indirect effects are both about 0.14, so the total is 0.28.
- A product of two estimates has a skewed sampling distribution when either path is small next to its standard error. The percentile bootstrap follows the skew; the Sobel interval is symmetric by construction and misses real indirect effects more often.
- Testing the total effect first, or reading a non-significant c′ as full mediation, can mislead. The direct and indirect effects can cancel, and a real direct effect can fail to reach significance in a small sample.
- The paths are causal effects only if nothing unmeasured affects both M and Y. Model fit cannot check this: with three variables and three paths the model is saturated, so it reproduces any covariance matrix exactly.
- Paths can also connect latent variables, each measured by several items as in a CFA. Comparing such paths across groups first requires the measurement models to hold in every group, which is what measurement invariance tests.
Recommended reading
- lavaan: An R package for structural equation modelingYves RosseelPaper · Journal of Statistical Software, 48(2), 2012
- Asymptotic and resampling strategies for assessing and comparing indirect effects in multiple mediator modelsKristopher J. Preacher and Andrew F. HayesPaper · Behavior Research Methods, 40(3), 2008