I am reading about the mediation test example from the lavaan package here:
http://lavaan.ugent.be/tutorial/mediation.html
Specifically, they fit the model:
set.seed(1234)
X <- rnorm(100)
M <- 0.5*X + rnorm(100)
Y <- 0.7*M + rnorm(100)
Data <- data.frame(X = X, Y = Y, M = M)
model <- ' # direct effect
Y ~ c*X
# mediator
M ~ a*X
Y ~ b*M
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b)
'
fit <- sem(model, data = Data)
summary(fit)
which produces the following output:
Regressions:
Estimate Std.Err Z-value P(>|z|)
Y ~
X (c) 0.036 0.104 0.348 0.728
M ~
X (a) 0.474 0.103 4.613 0.000
Y ~
M (b) 0.788 0.092 8.539 0.000
Variances:
Estimate Std.Err Z-value P(>|z|)
Y 0.898 0.127 7.071 0.000
M 1.054 0.149 7.071 0.000
Defined Parameters:
Estimate Std.Err Z-value P(>|z|)
ab 0.374 0.092 4.059 0.000
total 0.410 0.125 3.287 0.001
The summary shows that the so called "direct effect", which is expressed as a bivariate regression of $Y$ on $X$, has an effect labeled "c", and the total effect is the sum of the direct effect and the indirect effect. I was under the impression that a regression of an outcome onto an exposure not adjusting for the mediator summarized the total effect, and if you included the mediator in such a model, the conditional effect of the exposure is the direct effect. Indeed this is the case if one fits linear regression models.
Running lm(Y~X, data=Data)
gives:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.1929 0.1274 1.513 0.13339
X 0.4100 0.1260 3.254 0.00156 **
which is, in the lavaan example, what was called the "Direct" effect but which numerically equals the "total" effect. In order to get lavaan's "direct" effect, I fit the model lm(Y~X+M)
and get:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.16358 0.09747 1.678 0.0965 .
X 0.03635 0.10605 0.343 0.7325
M 0.78832 0.09373 8.410 3.58e-13 ***
Which is conditional on M.
Can someone explains how SEM works in this fashion to "sequentially condition" the regression models as specified?