# Using MICE in R: is it possible to impute only sub-sections of the data?

When using the mice library in R to impute data I encounter the following problem. I have a data matrix with missing information on y1 and y2 and predictor variable x. However, instead of imputing all missing data NA on y1 and y2, I would like to impute only the subset of data identified by s1==1 and s2==1. Due to the data structure I cannot just drop cases with s1==0 or s2==0.

The data look similar to this:

n=20
y1=c(rnorm(n))
y2=c(rnorm(n))
x=c(y1+y2+rnorm(1))
y1[c(1:10,16:20)]<-NA
y2[11:20]<-NA
s1=c(rep(0,10),rep(NA,5),rep(1,5))
s2=c(rep(NA,10),rep(1,5),rep(0,5))
(data<-data.frame(y1,y2,x,s1,s2))


The question is now to have mice impute the missing data on y1 and y2 for s1==1 and s2==1, but not for s1==0 and s2==0. It is obvious that selecting on data$s1==1 will drop all observations on y2. The reason I want to do this, is that in a larger data file the number of necessary imputations leads to covergence problems in mice with meth='polyreg'. By setting the sindicators I am trying to reduce the complexity to the parts of data that need imputation for relevant inference. • Is there anything wrong with just giving mice only the rows that you want imputed when you make the call to the function? As in imp <- mice(data[data$s == 1, c("y", "x")]). – Patrick S. Forscher Feb 27 '14 at 21:26
• @PatrickS.Forscher Not in the example, but in my application, I want to impute more flexibly. Ideally I would want to inpute s into Mice, so that it only imputes the data where s=1. I will try to extend the example to make this clearer. – tomka Feb 27 '14 at 21:39
• @PatrickS.Forscher I edited the post and hope the problem is more immediate now. It would be great if you know a solution. – tomka Feb 27 '14 at 22:30
• It's not clear to me why you would want to impute on only subsets of data. For one thing, for a given variable y to be imputed based on variable x, you need some cases where both y and x are observed -- the more, the better the quality of your imputation. So, as far as I understand based on your description, MI using only subsets of your data will decrease the quality of your imputation. You can address convergence problems in other ways, such as revising the visit sequence used by mice. See this article: stefvanbuuren.nl/publications/MICE%20in%20R%20-%20Draft.pdf – Patrick S. Forscher Feb 27 '14 at 22:50
• You might consider creating a new question asking more specifically about ways of dealing with convergence problems in MI (if that issue hasn't been addressed in another CV question). That seems like a question that would be appropriate for CV. I think you would get more responses than on this question. – Patrick S. Forscher Feb 27 '14 at 22:51