I have a question about using multiple imputation. I have a dataset of approximately 16,000 people with over 15 years of follow-up. To address missing data and loss-to-follow-up, I'm using multiple imputation (MI; using the MICE package in R). For my longitudinal/repeated measures analysis, I am excluding participants who report the outcome prior to or at the same wave of their first reported exposure (i.e., when exposure variable X first equals 1). My question is - should I do MI first, since I has missing data on the exposure? If so, however, how would I be able to exclude participants from a dataset that is technically multiple datasets?

Thank you!


1 Answer 1


Yes, if you want to exclude participants who report the outcome before the exposure and incorporate the uncertainty in whether a participant with missing data should be included or not, you should do the imputation first and then exclude participants.

The way to do this in MICE would be to use the complete(..., action = "long", include = TRUE) function after creating the imputations with mice(), perform the desired exclusion calculations on each imputed dataset, then recombine the data using as.mids(). Then you can fit your models on the imputed data and pool the results like normal.

EDIT: On second thought, you probably can't do it like this. I think as.mids will throw an error if the number of rows isn't equal in each imputed dataset.

Instead, you can probably put the exclusion code in the with() block. For example, here I remove anyone with jobperf less than 11 before fitting a glm model in the employee dataset.


imps <- mice(employee,printFlag = FALSE)
fits1 <- with(imps,
             glm(jobperf ~ IQ + wbeing))
fits2 <- with(imps,
              {dat <- data.frame(IQ,wbeing,jobperf)
              dat <- dat[dat$jobperf > 10,]
          glm(jobperf ~ IQ + wbeing,
              data = dat)})
#>  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 
#> 10 10 10 10 10 10 10 15 11  7  7 10 11 15 10 10 12 14 16 12
#>  8  9 13 14 17 18 19 20 
#> 15 11 11 15 12 14 16 12

As you can see, fits2 excludes anyone with a response vector less than 11. This responds to the imputed values, so people with missing values will sometimes be included and sometimes not. Depending on the details of the model fitting function you're using there might be some complications getting it to work, but this should do what you need.

  • $\begingroup$ Thank you so much for this answer! I did indeed try your first way, and ran into issues with as.mids. I will try your second way (exclusion within the with() block) and see how it goes. I appreciate your help! $\endgroup$
    – PotterFan
    Commented Apr 22, 2021 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.