[英]How extract several imputed values from several variables using mice or another package in R into a single dataset?
From the multiple imputation output (eg, object of class mids for mice) I want to extract several imputed values for some of the imputed variables into a single dataset that also includes original data with the missing values.从多重插补输出(例如,鼠标类中的对象),我想将一些插补变量的几个插补值提取到一个数据集中,该数据集还包括带有缺失值的原始数据。
Here are sample dataset and code:以下是示例数据集和代码:
library("mice")
nhanes
tempData <- mice(nhanes, seed = 23109)
Using the code below I can extract these values for each variable into separate datasets:使用下面的代码,我可以将每个变量的这些值提取到单独的数据集中:
age_imputed<-as.data.frame(tempData$imp$age)
bmi_imputed<-as.data.frame(tempData$imp$bmi)
hyp_imputed<-as.data.frame(tempData$imp$hyp)
chl_imputed<-as.data.frame(tempData$imp$chl)
But I want to extract several variables to preserve the order of the rows for further analysis.但我想提取几个变量以保留行的顺序以供进一步分析。
I would appreciate any help.我将不胜感激任何帮助。
Use the complete
function from mice
package to extract the complete data set including the imputations:使用来自
mice
包的complete
函数来提取完整的数据集,包括插补:
complete(tempData, action = 1)
action
argument takes the imputation number or if you need it in "all", "long" formats etc. Refer R documentation . action
参数采用插补编号,或者如果您需要“all”、“long”格式等。请参阅R 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.