4

我有一个关于由 R-package 'mice' 创建的估算数据聚合的问题。

据我了解,'mice' 的'complete' 命令用于提取例如第一个插补的插补值。但是,当总共运行十次插补时,我不确定要提取哪些插补值。有谁知道如何在所有插补中提取(汇总)插补数据?

由于我想将数据输入 MS Excel 并在另一个软件工具中执行进一步的计算,这样的命令将非常有帮助。

谢谢您的意见。一个简单的例子(来自“老鼠”本身)可以在下面找到:

R> library("mice")
R> nhanes
R> imp <- mice(nhanes, seed = 23109) #create imputation
R> complete(imp) #extraction of the five imputed datasets (row-stacked matrix)

如何聚合五个估算数据集并将估算值提取到 Excel?

4

3 回答 3

3

我有类似的问题。我使用了下面的代码,它对数字变量来说已经足够好了。对于其他人,我考虑过随机选择一个估算结果(因为平均会破坏它)。

我提供的代码是(对于数字):

tempData <- mice(data,m=5,maxit=50,meth='pmm',seed=500)
completedData <- complete(tempData, 'long')
a<-aggregate(completedData[,3:6] , by = list(completedData$.id),FUN= mean)
  1. 你应该加入结果。
  2. 我认为'Hmisc'是一个更好的包。
  3. 如果您已经找到更好/更优雅/内置的解决方案 - 请与我们分享。
于 2016-07-27T09:40:38.730 回答
1

您应该使用complete(imp,action="long")来获取每个插补的值。如果你看到?complete,你会发现

complete(x, action = 1, include = FALSE)

Arguments

x   
An object of class mids as created by the function mice().

action  
If action is a scalar between 1 and x$m, the function returns the data with imputation number action filled in. Thus, action=1 returns the first completed data set, action=2 returns the second completed data set, and so on. The value of action can also be one of the following strings: 'long', 'broad', 'repeated'. See 'Details' for the interpretation.

include 
Flag to indicate whether the orginal data with the missing values should be included. This requires that action is specified as 'long', 'broad' or 'repeated'.

因此,默认是返回第一个估算值。此外,参数action还可以是字符串:longbroadrepeated。如果您输入long,它将为您提供长格式的数据。您还可以设置include = TRUE是否需要原始缺失数据。

于 2015-03-02T16:20:59.113 回答
0

好的,但是您仍然必须选择一个估算数据集进行进一步分析...我认为最好的选择是使用您的数据集进行分析,complete(imp,action="long")然后汇总结果。fit <- with(data=imp,exp=lm(bmi~hyp+chl)) pool(fit)

但我也假设不禁止仅使用其中一个估算数据集;)

于 2017-01-31T20:30:41.043 回答