多个估算数据集-合并结果 [英] Multiple Imputed datasets - pooling results

查看:138
本文介绍了多个估算数据集-合并结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含缺失值的数据集.我已估算出此数据集,如下所示:

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)

这将创建五个估算的数据集.然后,我创建了完整的数据集(示例数据集1):

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!

推荐答案

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

You understood the basic multiple imputation process right. The process is like:

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

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

This is a quite often misunderstand process (often people assume you have to combine your m imputed datasets together to one dataset - which is wrong)

这是此过程的图片:

Here is a picture of this process:

现在,您必须在mouses框架内按照这些步骤进行操作-仅在第1步之前这样做.

Now you have to follow these steps within the mice framework - you did this only till step 1.

以下摘录自老鼠的帮助:

Here an excerpt from the mice help:

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

The pool() function combines the estimates from m repeated complete data analyses. The typical sequence of steps to do a multiple imputation analysis is:

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

  1. Impute the missing data by the mice function, resulting in a multiple imputed data set (class mids);

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

Fit the model of interest (scientific model) on each imputed data set by the with() function, resulting an object of class mira;

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

Pool the estimates from each model into a single set of estimates and standard errors, resulting is an object of class mipo;

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

Optionally, compare pooled estimates from different scientific models by the pool.compare() function.

明智的代码可以看起来像这样:

Code wise this can look for example like this:

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

这篇关于多个估算数据集-合并结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆