if (FALSE) {
#############################################################################
# EXAMPLE 1: Write data list imputed in mice
#############################################################################
data(data.ma01)
dat <- as.matrix(data.ma01)
# start with empty imputation
imp0 <- mice::mice( dat, maxit=0)
# modify predictor matrix
predM <- imp0$predictorMatrix
predM[, c("idschool", "idstud" ) ] <- 0
# modify imputation method
impMeth <- imp0$method
impMeth[ impMeth=="pmm" ] <- "norm"
# do imputations in mice
imp <- mice::mice( dat, predictorMatrix=predM, method=impMeth, m=3, maxit=4 )
# write imputed data in format "csv2" and round after 4 digits
write.datlist( datlist=imp, name="mice_imp_csv2", round=4 )
# write imputed data in R binary format
write.datlist( datlist=imp, name="mice_imp_Rdata", type="Rdata")
# write data for Mplus usage
write.datlist( datlist=imp, name="mice_imp_Mplus", Mplus=TRUE, round=5)
}
Run the code above in your browser using DataLab