Multiple Imputed datasets - pooling results

时间:2019-01-07 13:59:39

标签: r imputation r-mice

I have a dataset containing missing values. I have imputed this dataset, as follows:

library(mice)
id <- c(1,2,3,4,5,6,7,8,9,10)
group <- c(0,1,1,0,1,1,0,1,0,1)
measure_1 <- c(60,80,90,54,60,61,77,67,88,90)
measure_2 <- c(55,NA,88,55,70,62,78,66,65,92)
measure_3 <- c(58,88,85,56,68,62,89,62,70,99)
measure_4 <- c(64,80,78,92,NA,NA,87,65,67,96)
measure_5 <- c(64,85,80,65,74,69,90,65,70,99)
measure_6 <- c(70,NA,80,55,73,64,91,65,91,89)
dat <- data.frame(id, group, measure_1, measure_2, measure_3, measure_4, measure_5, measure_6)
dat$group <- as.factor(dat$group)

imp_anova <- mice(dat, maxit = 0)
meth <- imp_anova$method
pred <- imp_anova$predictorMatrix
imp_anova <- mice(dat, method = meth, predictorMatrix = pred, seed = 2018, 
maxit = 10, m = 5)

This creates five imputed datasets. Then, I created the complete datasets (example dataset 1):

impute_1 <- mice::complete(imp_anova, 1) # complete set 1   

And then I performed the desired analysis:

library(reshape)
library(reshape2)
datLong <- melt(impute_1, id = c("id", "group"), measure.vars = c("measure_1", "measure_2", "measure_3", "measure_4", "measure_5", "measure_6"))

colnames(datLong) <- c("ID", "Gender", "Time", "Value")
table(datLong$Time) # To check if correct
datLong$ID <- as.factor(datLong$ID)

library(ez)
model_mixed_1 <- ezANOVA(data = datLong, 
                   dv = Value, 
                   wid = ID, 
                   within = Time, 
                   between = Gender, 
                   detailed = TRUE, 
                   type = 3,
                   return_aov = TRUE)

I did this for all the five datasets, resulting in five models:

model_mixed_1
model_mixed_2
model_mixed_3
model_mixed_4
model_mixed_5

Now I want to combine the results of this models, to generate one results. I have asked a similar question before, but there I focused on the models. Here I just want to ask how I can simply combine five models. Hope someone can help me!

1 个答案:

答案 0 :(得分:0)

您了解基本的多重插补过程权利。该过程类似于:

  1. 首先创建m个估算数据集。 (鼠标()-函数)
  2. 然后您对每个数据集进行分析。 (with()-函数)
  3. 最后,您将这些结果组合在一起。 (pool()-函数)

这是一个经常被误解的过程(人们通常认为您必须将m个估算数据集组合到一个数据集中-这是错误的)

这是此过程的图片: enter image description here

现在,您必须在mouses框架内执行这些步骤-仅在步骤1之前执行此操作。

以下摘录自老鼠的帮助:

  

pool()函数将m个重复的完整数据分析中的估计值合并在一起。进行多次插补分析的典型步骤顺序为:

     
      
  1. 通过鼠标功能填充缺失的数据,从而产生多个估算的数据集(mids类);

  2.   
  3. 使用with()函数将感兴趣的模型(科学模型)适合于每个估算数据集,从而产生了mira类的对象;

  4.   
  5. 将每个模型的估算值合并为一组估算值和标准误差,从而得出mipo类的对象;

  6.   
  7. (可选)通过pool.compare()函数比较来自不同科学模型的合并估算值。

  8.   

明智的做法是,例如:

imp <- mice(nhanes, maxit = 2, m = 5)
fit <- with(data=imp,exp=lm(bmi~age+hyp+chl))
summary(pool(fit))