Description Usage Arguments Value Examples
Calculate complex survey standard errors for lavaan fits estimated with FIML.
1 | vcov_complex(fit, ids = ~1, strata = NULL)
|
fit |
A lavaan Fit object. |
ids |
Clusters specified as a vector or data frame (not a formula!) |
strata |
Strata specified as a vector or data frame (not a formula!) |
The estimated variance-covariance matrix of the paramters, accounting for complex sampling design.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | library(lavaan)
###### A single group example #######
# European Social Survey Denmark data (SRS)
data(ess.dk, package = "lavaan.survey")
# A saturated model with reciprocal effects from Saris & Gallhofer
dk.model <- "
socialTrust ~ 1 + systemTrust + fearCrime
systemTrust ~ 1 + socialTrust + efficacy
socialTrust ~~ systemTrust
"
lavaan.fit <- lavaan(dk.model, data=ess.dk, auto.var=TRUE, estimator="MLM")
summary(lavaan.fit)
# Use vcov_complex to obtain se's instead of lavaan.survey:
sqrt(diag(vcov_complex(lavaan.fit, ids = ess.dk$intnum)))
# Create random missings and use FIML to estimate the model
set.seed(4897)
ess.dk.mis <- ess.dk
ess.dk.mis[cbind(sample(1:nrow(ess.dk), size=200), sample(3:6, size=200, replace=TRUE))] <- NA
lavaan.fit.mis <- lavaan(dk.model, data=ess.dk.mis, auto.var=TRUE, missing="fiml")
summary(lavaan.fit.mis)
# Use vcov_complex to obtain se's accounting for clustering
sqrt(diag(vcov_complex(lavaan.fit.mis, ids = ess.dk$intnum)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.