Hello,
I am using data that has already been imputed using mice but continue to run into the same error seen below:
Error in semTools::runMI(model = HS.model, data = imps, fun = "cfa") :
data is not a valid input type: a partially observed data.frame, a list of imputed data.frames, or previous lavaan.mi object.
Specifically, I am unable to use the imputed data that has been defined by this code:
impHS=mice(HolzingerSwineford1939, m=20, seed=123, print=TRUE, to.data.frame=T)
imps=impHS$imputations
I'm sure this is something very simple that I'm missing but unable to find it on my own. Would appreciate ANY help from the group. Thank you in advance!!
HSMiss <- HolzingerSwineford1939[ , c(paste("x", 1:9, sep = ""),"ageyr","agemo","school")]
set.seed(12345)
HSMiss$x5 <- ifelse(HSMiss$x5 <= quantile(HSMiss$x5, .3), NA, HSMiss$x5)
age <- HSMiss$ageyr + HSMiss$agemo/12
HSMiss$x9 <- ifelse(age <= quantile(age, .3), NA, HSMiss$x9)
impHS=mice(HolzingerSwineford1939, m=20, seed=123, print=TRUE, to.data.frame=T)
imps=impHS$imputations
HS.model <- '
visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9
'
out2 <- cfa.mi(HS.model, data = imps)
I get the same error using "sem.mi" in addition to "cfa.mi"
I've tried "mice::complete(impHS, 'all') and this works but it doesn't seem to be the correct way to do this.