Julian Schulze
2014-Jul-22 08:00 UTC
Multiple Imputation of longitudinal data in MICE and statistical analyses of object type mids
Dear all, I have a problem with performing statistical analyses of longitudinal data after the imputation of missing values using mice. After the imputation of missings in the wide data-format I convert the extracted data to the longformat. Because of the longitudinal data participants have duplicate rows (3 timepoints) and this causes problems when converting the long-formatted data set into a type mids object. Does anyone know how to create a mids object or something else appropriate after the imputation? I want to use lmer,lme for pooled fixed effects afterwards. I tried a lot of different things, but still cant figure it out. Thanks in advance and see the code below for a minimal reproducible example: ------------------------------------------------------------ # minimal reproducible example ## Make up some data set.seed(2) # ID Variable, Group, 3 Timepoints outcome measure (X1-X3) Data <- data.frame( ID = sort(sample(1:100)), GROUP = sample(c(0, 1), 100, replace = TRUE), matrix(sample(c(1:5,NA), 300, replace=T), ncol=3) ) # install.packages("mice") library(mice) # Impute the data in wide format m.out <- mice(Data, maxit = 5, m = 2, seed = 9, pred=quickpred(Data, mincor = 0.0, exclude = c("ID","GROUP"))) # ignore group here for easiness # mids object? is.mids(m.out) # TRUE # Extract imputed data imp_data <- complete(m.out, action = "long", include = TRUE)[, -2] # Converting data into long format # install.packages("reshape") library(reshape) imp_long <- melt(imp_data, id=c(".imp","ID","GROUP")) # sort data imp_long <- imp_long[order(imp_long$.imp, imp_long$ID, imp_long$GROUP),] row.names(imp_long)<-NULL # save as.mids as.mids(imp_long,.imp=1, .id=2) # doesnt work as.mids(imp_long) # doesnt work ------------------------------------------------------------ Best, Julian