3

My question is how do I go about adding the imputed data to the quakes.missing data frame?

I've created a reproducible example below.

library(Hmisc)
library(missForest) #load packages

data("quakes") 
quakes

quakes.missing <- prodNA(quakes, noNA = 0.1) #create missing values

summary(is.na(quakes.missing)) #confirm that data is missing

impute_quakes <- aregImpute(~ lat + long + depth + mag + stations, data = quakes.missing, n.impute = 5)

impute_quakes
2602
  • 332
  • 3
  • 18
  • 1
    Check out `impute_quakes$imputed`. – Chirayu Chamoli Jan 17 '17 at 12:22
  • Thank you @ChirayuChamoli. I'm going to try to add the data with an apply function. – 2602 Jan 17 '17 at 13:16
  • What do you by "adding the imputed data to the quake.missing" data frame? Do you want to add the data vertically (rbind) or horizontally (rbind)? Or, do you simply want to extract the multiply imputed datasets? – Ahmadov Mar 16 '17 at 09:58
  • @Ahmedov what I meant was that I wanted to extract the imputed data sets so that I could perform an analysis on them. – 2602 Mar 19 '17 at 09:27

1 Answers1

1

Since you have 5 imputations, you'd have 5 full data frames, you can pull them out with a function like this:

fill_data <- function(impute = impute_quakes, data = quakes.missing, im = 1) {
  cbind.data.frame(impute.transcan(x = impute, 
                                   imputation = im, 
                                   data = data, 
                                   list.out = TRUE, 
                                   pr = FALSE))
 }
full_dat1 <- fill_data(im = 1)
full_dat2 <- fill_data(im = 2)
...

(also, I'm sure you are aware, but Hmisc also has a great function fit.mult.impute so you don't need to pull out full data frames in order to perform analyses)

Lucy
  • 981
  • 7
  • 15