简体   繁体   中英

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:

complete(tempData, action = 1)       

action argument takes the imputation number or if you need it in "all", "long" formats etc. Refer R documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM