[R] Multiple Imputation of longitudinal data in MICE and statistical analyses of object type mids

Julian Schulze julian_schulze at arcor.de
Tue Jul 22 10:00:54 CEST 2014

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

# 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")

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

# save as.mids
as.mids(imp_long,.imp=1, .id=2) # doesnt work
as.mids(imp_long) # doesnt work




More information about the R-help mailing list