library(Amelia)
library(lavaan)
modsim <- '
f1 =~ 0.7*y1+0.7*y2+0.7*y3
f2 =~ 0.7*y4+0.7*y5+0.7*y6
f3 =~ 0.7*y7+0.7*y8+0.7*y9'
datsim <- simulateData(modsim,model.type="cfa", meanstructure=TRUE,
std.lv=TRUE, sample.nobs=c(200,200))
randomMiss2 <- rbinom(prod(dim(datsim)), 1, 0.1)
randomMiss2 <- matrix(as.logical(randomMiss2), nrow=nrow(datsim))
randomMiss2[,10] <- FALSE
datsim[randomMiss2] <- NA
datsimMI <- amelia(datsim,m=3,idvars="group")
out1 <- fmi(datsimMI$imputations, exclude="group")
out1
out2 <- fmi(datsimMI$imputations, exclude="group", method="null")
out2
out3 <- fmi(datsimMI$imputations, varnames=c("y1","y2","y3","y4"))
out3
out4 <- fmi(datsimMI$imputations, group="group")
out4
Run the code above in your browser using DataLab