从 lavaan 中提取误差协方差矩阵

Extract error covariance matrix from lavaan

我想从sem()中提取误差协方差矩阵,但我不知道我是否做对了。我使用 inspect("cov.ov") 并且对于 "cov.ov" 文档说“模型隐含的方差-协方差矩阵”。那么这与误差协方差矩阵相同吗?代码如下:

# convert vector of correlations into matrix
   wisc4.cor <- lav_matrix_lower2full(c(1,0.72,1,0.64,0.63,1,0.51,0.48,0.37,1,0.37,0.38,0.38,0.38,1))
# enter the SDs
   wisc4.sd <- c(3.01 , 3.03 , 2.99 , 2.89 , 2.98)
# name the variables
   colnames(wisc4.cor) <- rownames(wisc4.cor) <- c("Information", "Similarities", "Word.Reasoning", "Matrix.Reasoning", "Picture.Concepts")
   names(wisc4.sd) <-  c("Information", "Similarities", "Word.Reasoning", "Matrix.Reasoning", "Picture.Concepts")
# convert correlations and SDs to covarainces
   wisc4.cov <- cor2cov(wisc4.cor,wisc4.sd)
# specify single factor model
   wisc4.model<-'
   g =~ a*Information + b*Similarities + c*Word.Reasoning + d*Matrix.Reasoning + e*Picture.Concepts
'
# fit model
   wisc4.fit <- sem(model=wisc4.model, sample.cov=wisc4.cov, sample.nobs=550,  std.lv=FALSE)
#does this extract the error covariance matrix?
   inspect(wisc4.fit, "cov.ov")

您需要残差的 cov 矩阵:

residuals(wisc4.fit)$cov