Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block-wise imputation #175

Closed
alexanderrobitzsch opened this issue Apr 12, 2019 · 3 comments
Closed

Block-wise imputation #175

alexanderrobitzsch opened this issue Apr 12, 2019 · 3 comments

Comments

@alexanderrobitzsch
Copy link

alexanderrobitzsch commented Apr 12, 2019

Hi Stef,

I tried the functionality of block-wise imputation. I used your example with the "jomoImpute" imputation method. My syntax is as follows (only slightly adapted from the manual)

data(nhanes, package="mice")
dat <- nhanes
dat$age[c(1,2)] <- NA

blocks <-  list( block1=c("bmi", "chl", "hyp"), "age")
method <- c("jomoImpute", "pmm")

dat <- dat[, unlist(blocks)]
ini <- mice::mice(dat, blocks = blocks, method = method, maxit = 0)
pred <- ini$pred
imp <- mice::mice(dat, blocks = blocks, method = method, pred = pred, maxit = 1, m=1)

So, I want to inpute bmi, chl and hyp (say X1, X2, X3) in a block and age (say Z) based on a single conditional model. My understanding is that I want to impute the first block based on the distribution P(X1, X2, X3|Z) and age based on P(Z|X1,X2,X3). I played a bit with the source code (which is here

https://github.com/stefvanbuuren/mice/blob/master/R/mice.impute.jomoImpute.R

However, it seems the for imputing X=(X1,X2,X3), the original data data is used and not the updated values of Z. Is this a bug or is this by intention implemented in this way?

Best,
Alexander

@alexanderrobitzsch
Copy link
Author

alexanderrobitzsch commented Apr 17, 2019

An additional note. The lines 91-96 in the function mice:::sampler() are

# multivariate imputation - type and formula
if (mult) {
   mis <- !r
   mis[, setdiff(b, colnames(data))] <- FALSE
   data[mis] <- NA
  # [...]
}

I think that the following change would fix the issue

if (mult) {
   mis <- !r
   for (j in b){
	data[ mis[,j] , j ] <- NA
  }
  # [...]
}

@stefvanbuuren
Copy link
Member

Alexander, as you suspected, this is a bug. Thanks for catching this.

In mice 3.4.3 I have corrected this as

mis <- !r
mis[, setdiff(colnames(data), b)] <- FALSE
data[mis] <- NA

The bug ignores imputed values in variables outside the blocks when using multivariate imputation. It happens when using block-wise imputation with multivariate missing data.

My mistake was in interchanging the roles of the arguments in setdiff(), something that bugs me more often.

@alexanderrobitzsch
Copy link
Author

Thank you for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants