user3631369
user3631369

Reputation: 331

Residual plots for multiple imputation using mice package in R

With the mice package, how do we check for the residuals of the pooled analysis?

library(mice) 
imp <- mice(nhanes, seed = 23109)
fit <- with(imp, lm(chl ~ age + bmi))
pool(fit)
summary(pool(fit))

fit contains the analysis for each imputed dataset and pool(fit) the pooled results. Is there a command to check the residuals as for a standard lm object, something like plot(pool(fit))?

Upvotes: 3

Views: 1783

Answers (2)

JJceey
JJceey

Reputation: 21

just to improve on what Floor Middel did:

  RS1=NULL
  PS1=NULL

  for(i in 1:5){
  RS1=rbind(RS1,residuals(model1$analyses[[i]]))
  RS=colMeans(RS1)
  PS1=rbind(PS1,predict(model1$analyses[[i]])) 
  PS=colMeans(PS1)}


  plot(RS,PS)

Upvotes: 2

Floor Middel
Floor Middel

Reputation: 46

I ran into the same problem and I resolved it with a quite exhaustive solution. I saved the residuals and fitted values for each separate imputed dataset. This works okay if you have only a limited amount of datasets, but will become more complicated if you have more datasets (I had 75, so my script became terrible long). I will explain my solution based on an example with 5 imputed datasets:

 # Computing and saving the mean residual per individual over 5 imputed datasets
 RS1 <-residuals(model1$ana[[1]])+residuals(model1$ana[[2]])+residuals(model1$ana[[3]])+residuals(model1$ana[[4]])+residuals(model1$ana[[5]])
 RSmodel1 <- RS1 / 5 
 # Computing and saving the mean predicted value per individual over 5 imputed datasets     
 PS1 <-predict(model1$ana[[1]])+predict(model1$ana[[2]])+predict(model1$ana[[3]])+predict(model1$ana[[4]])+predict(model1$ana[[5]])
 PSmodel1 <- PS1 / 5
 # Creating the residual plot 
 plot(RSmodel1, PSmodel1) 

I hope this will help you! I am very aware that my solution is quite inconvenient, but it will do the job :)

Upvotes: 3

Related Questions