如何从R-package';老鼠';?
我有一个关于R-package“mice”创建的插补数据聚合的问题 据我所知,“小鼠”的“完整”命令用于提取插补值,例如,第一次插补。然而,当运行总共十次插补时,我不确定要提取哪些插补值。有人知道如何在所有插补中提取(合计)插补数据吗 由于我想将数据输入MS Excel并在另一个软件工具中执行进一步的计算,因此这样的命令将非常有用 谢谢你的评论。下面是一个简单的例子(来自“老鼠”本身):如何从R-package';老鼠';?,r,r-mice,R,R Mice,我有一个关于R-package“mice”创建的插补数据聚合的问题 据我所知,“小鼠”的“完整”命令用于提取插补值,例如,第一次插补。然而,当运行总共十次插补时,我不确定要提取哪些插补值。有人知道如何在所有插补中提取(合计)插补数据吗 由于我想将数据输入MS Excel并在另一个软件工具中执行进一步的计算,因此这样的命令将非常有用 谢谢你的评论。下面是一个简单的例子(来自“老鼠”本身): R> library("mice") R> nhanes R> imp <- mic
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)
R>库(“鼠标”)
R> 恩哈内斯
R> imp complete(imp)#提取五个插补数据集(行堆叠矩阵)
如何聚合五个插补数据集并将插补值提取到Excel?您应该使用
complete(imp,action=“long”)
来获取每次插补的值。如果您看到?complete
,您将发现
complete(x,action=1,include=FALSE)
因此,默认值是返回第一个插补值。此外,参数action
也可以是字符串:long
、broad
和repeated
。如果您输入long
,它将为您提供long格式的数据。如果需要原始缺失数据,还可以设置include=TRUE
我也有类似的问题。
我使用了下面的代码,它足以支持数值变量。
对于其他人,我想随机选择一个插补结果(因为平均值会破坏它)
我提供的代码是(数字):
tempData可以,但仍需选择一个插补数据集进行进一步分析。。。我认为最好的选择是使用您的complete(imp,action=“long”)
进行分析,然后汇总结果。fit我认为它代表国家健康和营养检查调查感谢您的回答。很抱歉不清楚,但我正在寻找所有m个插补的插补值,因为我不知道m个插补中哪一个是最好的。是否有一种方法可以提取平均值等?正如我在回答中提到的,如果您键入complete(imp,action=“long”)
它将给出所有插补的插补值。
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'.
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)