我有一个关于R-package 'mice‘创建的估算数据聚合的问题。
据我所知,'mice‘的’complete‘-命令是用来提取第一个推算的值的。但是,当总共运行十次估算时,我不确定要提取哪些估算的值。有人知道如何在所有估算中提取(聚合)估算数据吗?
由于我想将数据输入到MS Excel中,并在另一个软件工具中执行进一步的计算,因此这样的命令将非常有用。
感谢您的评论。下面是一个简单的例子(来自“mice”本身):
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中?
发布于 2016-07-27 17:40:39
我也有过类似的问题。我使用了下面的代码,它可以很好地处理数值变量。对于其他人,我想随机选择一个估算的结果(因为平均可能会打乱它)。
我提供的代码是(对于数字):
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)发布于 2015-03-03 00:20:59
您应该使用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也可以是字符串:long、broad和repeated。如果您输入long,它将提供长格式的数据。如果您想要原始的缺失数据,也可以设置include = TRUE。
发布于 2017-02-01 04:30:41
好的,但是你仍然必须选择一个推定的数据集进行进一步的分析……我认为最好的选择是使用你的complete(imp,action="long")进行分析,然后将结果汇集在一起。fit <- with(data=imp,exp=lm(bmi~hyp+chl)) pool(fit)
但我也假设不禁止只使用其中一个估算的数据集;)
https://stackoverflow.com/questions/28814384
复制相似问题