繁体   English   中英

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

[英]How to extract aggregated imputed data from R-package '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?

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

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

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. 如果您已经找到更好/更优雅/内置的解决方案 - 请与我们分享。

您应该使用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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM