首页 文章

如何从R-package 'mice'中提取聚合推算数据?

提问于
浏览
3

我有一个关于由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 回答

  • 1

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

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

    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)
    
    • 你应该加入结果 .

    • 我认为'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 .

  • 0

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

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

相关问题