Multiple imputation of longitudinal data in MICE and statistical analysis of object type environments

I have a problem with performing statistical analysis of longitudinal data after imputing missing values ​​using mice. After imputing the passes into the wide data-format, I convert the extracted data to longformat. Due to the longitudinal, data participants have duplicate rows (3 time points), and this causes problems when converting a long-format data set to an object of type mids. Does anyone know how to create a mids object or something else appropriate after imputation? I want to use lmer, lme for combined fixed effects. I tried a lot of different things, but still can't figure it out.

Thanks in advance and see the code below:

# 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

+4
2

, . , mids. , mice, , apply.

library(mice)
library(reshape)
library(lme4)

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

# impute
m.out <- mice(Data, pred=quickpred(Data, mincor=0, exclude=c("ID","GROUP")))

# complete
imp.data <- as.list(1:5)
for(i in 1:5){
  imp.data[[i]] <- complete(m.out, action=i)
}

# reshape
imp.data <- lapply(imp.data, melt, id=c("ID","GROUP"))

# analyse
imp.fit <- lapply(imp.data, FUN=function(x){
  lmer(value ~ as.numeric(variable)+(1|ID), data=x) 
})
imp.res <- sapply(imp.fit, fixef)

, , , , . , , mice .

mice, , , Mplus pan R MI.

+3

, , -, ... - https://stefvanbuuren.name/Winnipeg/Lectures/Winnipeg.pdf , " POST" long2mids():

imp1 <- mice(boys); 
long <- complete(imp1, "long", inc = TRUE);
long$whr <- with(long, wgt/(hgt/100));
imp2 <- long2mids(long)

long2mids(), , as.mids() (. https://www.rdocumentation.org/packages/mice/versions/2.30/topics/long2mids)

0

All Articles