Hi everyone,
out of interest, i tried different ways of using multiple imputation in lavaan. Three different ways to be precise.
1.) Multiple Imputation and model estimation in one step with runMI()
2.) Multiple Imputation with mice first, then passing the previously imputed data to runMI()
3.) Multiple Imputation with mice first, then passing the imputed data to a svydesign-object and analyse it in lavaan.survey. BUT: Without specifying any samplingdesign r weight.
I used the HolzingerSwineford-Data. Something must have gone wrong, because i get three different chi-square values.
#--------------------------
# Setting up example data and model
#--------------------------
# Create data with missings
set.seed(20170110)
HSMiss <- HolzingerSwineford1939[,paste("x", 1:9, sep="")]
randomMiss <- rbinom(prod(dim(HSMiss)), 1, 0.1)
randomMiss <- matrix(as.logical(randomMiss), nrow=nrow(HSMiss))
HSMiss[randomMiss] <- NA
# lavaan model
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
#------------------------------------------------------------------
# Variant 1: Imputation and model estimation with runmI
#-------------------------------------------------------------------
# run lavaan and imputation in one step
out1 <- runMI(HS.model,
data=HSMiss,
m = 5,
miPackage="mice",
fun="cfa",
meanstructure = TRUE)
summary(out1)
fitMeasures(out1, "chisq")
#------------------------------------------------------------------
# Variant 2: Imputation in step 1 and model estimation in step 2 with runMI
#-------------------------------------------------------------------
# impute data first
HSMiss_imp<-mice(HSMiss, m = 5)
mice.imp <- NULL
for(i in 1:5) mice.imp[[i]] <- complete(HSMiss_imp,"long",inc=FALSE)
# run lavaan with previously imputed data using runMI
out2 <- runMI(HS.model,
data=mice.imp,
fun="cfa",
meanstructure = TRUE)
summary(out2)
fitMeasures(out2, "chisq") #extremely high chi-square
#------------------------------------------------------------------
# Variant 3: Imputation in step 1 and model estimation in step 2 with lavaan.survey (but without weights)
#-------------------------------------------------------------------
# take previously imputed data from variant 2 and convert it to svydesign-object
mice.imp2<-lapply(seq(HSMiss_imp$m),function(im) complete(HSMiss_imp,im))
mice.imp2<-mitools::imputationList(mice.imp2)
svy.df_imp<-survey::svydesign(id=~1,weights=~1,data=mice.imp2)
# fit model with lavaan.survey
lavaan_fit_HS.model<-cfa(HS.model, meanstructure = TRUE)
out3<-lavaan.survey(lavaan_fit_HS.model, svy.df_imp)
summary(out3)
fitMeasures(out3, "chisq")
It´s more a matter of personal interest for me, but it would be great to have some help, figuring out, why i get three different chisquares.
> fitMeasures(out1, "chisq")
chisq
73.841
> fitMeasures(out2, "chisq")
chisq
483.637
> fitMeasures(out3, "chisq")
chisq
96.748