649 10.475 0.000 1.000 1.000
.alien67 4.841 0.467 10.359 0.000 0.683 0.683
.alien71 4.083 0.404 10.104 0.000 0.503 0.503
12. 估计方法,标准误差和缺失值
12.1 估计方法
如果所有数据都是连续的,默认估计方法是最大似然法,还有一些其他方法:
- "GLS": generalized least squares. 只能用于完整数据
- "WLS": weighted least squares (sometimes called ADF estimation). 只能用于完整数据
- "DWLS": diagonally weighted least squares
- "ULS": unweighted least squares
许多估计方法都有“稳健”变体,意味着它们提供稳健标准误差和缩放的检验统计量。例如,对于最大似然,lavaan提供如下稳健变体:
- "MLM": maximum likelihood estimation with robust standard errors and a Satorra-Bentler scaled test statistic. 只能用于完整数据
- "MLMVS": maximum likelihood estimation with robust standard errors and a mean- and variance adjusted test statistic (aka the Satterthwaite approach). 只能用于完整数据
- "MLMV": maximum likelihood estimation with robust standard errors and a mean- and variance adjusted test statistic (using a scale-shifted approach). 只能用于完整数据
- "MLF": for maximum likelihood estimation with standard errors based on the first-order derivatives, and a conventional test statistic. 可以用于完整和非完整数据
- "MLR": maximum likelihood estimation with robust (Huber-White) standard errors and a scaled test statistic that is (asymptotically) equal to the Yuan-Bentler test statistic. 可以用于完整和非完整数据
12.2 最大似然估计
lavaan默认使用有偏样本协方差矩阵,与Mplus所使用方法相似(“normal”)。我们也可以使用likelihood = "wishart"来使用无偏协方差用以接近EQS, LISREL或AMOS的计算结果(“Wishart”):
fit <- cfa(HS.model,
data = HolzingerSwineford1939,
fit
12.3 缺失值
默认为列表状态删除,在进行统计量的计算时,把含有缺失值的记录删除,这种方法可以用于计算全体无缺失值数据的均数、协方差和标准差。
13. 间接效应和中介分析
设想一个典型的中介分析,X->M->Y,随机生成人工数据,示例如下:
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)
结果如下:
lavaan (0.5-23.1097) converged normally after 12 iterations
Number of observations 100
Estimator ML
Minimum Function Test Statistic 0.000
Degrees of freedom 0
Minimum Function Value 0.0000000000000
Parameter Estimates:
Information Expected
Standard Errors Standard
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
14. 修正指标
可以通过在summary()函数中增加参数modindices = TRUE,来得出修正指标,例如:
fit <- cfa(HS.model,
data = HolzingerSwineford1939)
mi <- modindices(fit)
mi[mi$op == "=~",]
结果为:
lhs op rhs mi epc sepc.lv sepc.all sepc.nox
25 visual =~ x4 1.211 0.077 0.069 0.059 0.059
26 visual =~ x5 7.441 -0.210 -0.189 -0.147 -0.147
27 visual =~ x6 2.843 0.111 0.100 0.092 0.092
28 visual =~ x7 18.631 -0.422 -0.380 -0.349 -0.349
29 visual =~ x8 4.295 -0.210 -0.189 -0.187 -0.187
30 visual =~ x9 36.411 0.577 0.519 0.515 0.515
31 textual =~ x1 8.903 0.350 0.347 0.297 0.297
32 textual =~ x2 0.017 -0.011 -0.011 -0.010 -0.010
33 textual =~ x3 9.151 -0.272 -0.269 -0.238 -0.238
34 textual =~ x7 0.098 -0.021 -0.021 -0.019 -0.019
35 textual =~ x8 3.359 -0.121 -0.120 -0.118 -0.118
36 textual =~ x9