error with using mice-imputed MI data with sem.mi

Skip to first unread message


Feb 23, 2019, 11:05:01 PM2/23/19
to lavaan

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,

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")]
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,

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. 

Mark Seeto

Feb 24, 2019, 1:15:50 AM2/24/19
to lavaan
The problem is that your impHS doesn't have an element called "imputations", so impHS$imputations is nothing. Using impHS$imputations would be correct if impHS was the output of amelia() rather than mice(). As you know, complete(impHS, "all") works, and as far as I know, there is nothing wrong with using it.


Feb 24, 2019, 3:01:14 PM2/24/19
to lavaan

I have had the same problem. But I have found the solution creating a list. One Member of this group has posted the solution somewhere in this group. So you can try the code below, 

imp<-mice(impHS, m=20)

nImputations <- 20

impList <- list()

for (i in 1:nImputations) {

  impList[[i]] <- complete(imp, action = i)


out2 <- cfa.mi(HS.model, data = imp)
Reply all
Reply to author
0 new messages