Extract error covariance matrix from lavaan

210 views Asked by At

I want to extract the error covariance matrix from sem() but I don't know if I did it correctly. I used inspect("cov.ov") and for "cov.ov" the document says "The model-implied variance-covariance matrix". So is this the same as error covariance matrix? Codes are below:

# 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")
1

There are 1 answers

0
Sinval On BEST ANSWER

You want the residuals' cov matrix:

residuals(wisc4.fit)$cov