1
$\begingroup$

I encounter a problem with the use of the mice function to do multiple imputation. I want to do imputation only on part of the missing data, what looking at the help seems possible and straightworward. But i can't get it to work. here is the example:

I have some missing data on x and y:

library(mice)
plouf <- data.frame(ID = rep(LETTERS[1:10],each = 10), x = sample(10,100,replace = T), y = sample(10,100,replace = T))
plouf[sample(100,10),c("x","y")] <- NA

I want only to impute missing data on y:

where <- data.frame(ID = rep(FALSE,100),x = rep(FALSE,100),y = is.na(plouf$y))

I do the imputation

plouf.imp <- mice(plouf, m = 1,method="pmm",maxit=5,where = where)

I look at the imputed values:

test <- complete(plouf.imp)

Here i still have NAs on y:

> sum(is.na(test$y))
[1] 10

if I use where to say to impute on all values, it works:

where <- data.frame(ID = rep(FALSE,100),x = is.na(plouf$x),y = is.na(plouf$y))
plouf.imp <- mice(plouf, m = 1,method="pmm",maxit=5,where = where)
test <- complete(plouf.imp)

> sum(is.na(test$y))
[1] 0

but it does the imputation on x too, that I don't want in this specific case (speed reason in a statistial simulation study)

Has anyone any idea ?

$\endgroup$

closed as off-topic by rolando2, Michael Chernick, kjetil b halvorsen, Juho Kokkala, Peter Flom Apr 24 '18 at 11:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – rolando2, Michael Chernick, kjetil b halvorsen, Juho Kokkala, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.