如何从R-package鼠标中提取汇总的估算数据'

时间:2015-03-02 16:12:38

标签: r r-mice

我对R-package'鼠标创建的估算数据的聚合有疑问。

据我所知,'完整的'指令'老鼠'用于提取例如第一次插补的插补值。然而,当总共运行十次插补时,我不确定,哪些估算值要提取。有谁知道如何在所有插补中提取(聚合)推算数据?

由于我想将数据输入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?

3 个答案:

答案 0 :(得分:3)

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

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

header('Content-Length: ' . filesize($full_path_file));
  1. 你应该加入结果。
  2. 我认为&#39; Hmisc&#39;是一个更好的方案。
  3. 如果您已经找到更好/更优雅/内置解决方案 - 请与我们分享。

答案 1 :(得分: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

答案 2 :(得分:0)

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

但我也假设它不被禁止仅使用其中一个插补数据集;)