--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/lavaan/CACXLW89BxCVEJPT6VUG3JHOSw9RN24VE63MNmuFsOBAzn4JEkQ%40mail.gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/lavaan/CAMtGSx%3DoO2wOXoq1gyPBKPk6UAq6hfFLJFmjBmGWhOm3by-U4A%40mail.gmail.com.
> library(lavaan)
>
> Data9 <- HolzingerSwineford1939[,c("x1","x2","x3","x4","x5","x6","x7","x8","x9")]
> S <- cov(Data9)
> round(S, 3)
x1 x2 x3 x4 x5 x6 x7 x8 x9
x1 1.363 0.409 0.582 0.507 0.442 0.456 0.085 0.265 0.460
x2 0.409 1.386 0.453 0.210 0.212 0.248 -0.097 0.110 0.245
x3 0.582 0.453 1.279 0.209 0.113 0.245 0.089 0.213 0.375
[snip]
>
> model <- '
+ # measurement model
+ f1 =~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9
+ '
>
> fit <- lavaan::sem(model, data = Data9)
>
>
> inspect(fit, "sampstat")$cov * (nrow(Data9) / (nrow(Data9) - 1))
x1 x2 x3 x4 x5 x6 x7 x8 x9
x1 1.363
x2 0.409 1.386
x3 0.582 0.453 1.279
[snip]
To view this discussion visit https://groups.google.com/d/msgid/lavaan/CACXLW8_s003oJbuF2vBp18RShdN9nhDVyY8WJ4q1Z5Nbm1nFeg%40mail.gmail.com.
Jeremy is correct! While base R (the cov function) gives you the sample covariance matrix (divides by n-1), lavaan gives you the maximum likelihood estimator of the covariance matrix (divides by n).
To go from the sample (unbiased) covariance to the ML covariance, you can multiply by (n - 1) / n. (the reciprocal, to replace the denominator n-1 with n).
> n <- nrow(Data9) # 301 > S_ml <- S * (n - 1) / n # rescale > round(S_ml, 3) - (inspect(fit, "sampstat")$cov) x1 x2 x3 x4 x5 x6 x7 x8 x9 x1 0 x2 0 0 x3 0 0 0 x4 0 0 0 0 x5 0 0 0 0 0 x6 0 0 0 0 0 0 x7 0 0 0 0 0 0 0 x8 0 0 0 0 0 0 0 0 x9 0 0 0 0 0 0 0 0 0
Alex
To view this discussion visit https://groups.google.com/d/msgid/lavaan/1f29838d-cd9f-4631-9705-3c1b10533837n%40googlegroups.com.