簡體   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