Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

mice does not support post-processing for blocks of variables #326

Closed
Garyf20 opened this issue Mar 25, 2021 · 10 comments
Closed

mice does not support post-processing for blocks of variables #326

Garyf20 opened this issue Mar 25, 2021 · 10 comments

Comments

@Garyf20
Copy link

Garyf20 commented Mar 25, 2021

The processing of "post" is missed for multivariate imputation.

@gerkovink
Copy link
Member

gerkovink commented Mar 25, 2021

Cannot reproduce on mice v3.13. Could you present a reprex?

set.seed(123)
library(mice)
library(magrittr)
version()
#> [1] "mice 3.13.0 2021-01-26 /Library/Frameworks/R.framework/Versions/4.0/Resources/library"

ini <- mice(boys, maxit = 0)
meth <- ini$meth
meth["tv"] <- "norm"
post <- ini$post
post["tv"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(3, 7))"
post["bmi"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(28, Inf))"
post["hgt"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(50, 55))"
imp <- mice(boys, meth=meth, post=post, print=FALSE)

imp$imp$tv %>% range
#> [1] 3 7
imp$imp$bmi %>% range
#> [1] 28 28
imp$imp$hgt %>% range
#> [1] 50 55

Created on 2021-03-25 by the reprex package (v1.0.0)

@gerkovink
Copy link
Member

Please note that post-processing only works for imputed values; the observations are not processed.

@stefvanbuuren
Copy link
Member

This is not a bug. mice does not support post-processing for blocks of variables. The length of the post vector equals the number of variables', and post works only in combination with a series of univariate models.

I found it hard to imagine a generic way to implement post-processing under block-wise imputation models. I'll be interested to hear of any suggestions, preferably including practical examples that illustrate the need for such block-wise post-processing.

@stefvanbuuren stefvanbuuren changed the title sampler function bug mice does not support post-processing for blocks of variables Mar 26, 2021
@stefvanbuuren
Copy link
Member

Commit 8f78a27 adds the explanation to the documentation.

@Garyf20
Copy link
Author

Garyf20 commented Mar 31, 2021 via email

@stefvanbuuren
Copy link
Member

The mice philosophy is to solve the multivariate imputation problem by repeatedly applying univariate variable-by-variable imputation. So mice solves the multivariate imputation problem, and nothing special is needed to do that.

The blocks facility is more of an experimental feature meant for cases where you wish model two or more variables jointly, so you would impute two or more values per row by one method.

Hope this helps.

@stefvanbuuren
Copy link
Member

Question: In that default method case, is there any difference between blocks with more than 1 variable setting and 1 variable in 1 block setting?

No difference. mice simply repeats any given univariate method within the block. Be aware that it is possible to change the sequence in which variables are imputed. See example below.

suppressPackageStartupMessages(library(mice))

imp1 <- mice(nhanes, seed = 1, m = 1, maxit = 2, print = FALSE)
imp2 <- mice(nhanes, blocks = list(c("bmi", "hyp"), "chl"), m = 1, maxit = 2, seed = 1, print = FALSE)
identical(complete(imp1, 1), complete(imp2, 1))
#> [1] TRUE

imp3 <- mice(nhanes, blocks = list(c("hyp", "bmi"), "chl"), m = 1, maxit = 2, seed = 1, print = FALSE)
identical(complete(imp1, 1), complete(imp3, 1))
#> [1] FALSE

imp4 <- mice(nhanes, visitSequence = c("hyp", "bmi", "chl"), m = 1, maxit = 2, seed = 1, print = FALSE)
identical(complete(imp3, 1), complete(imp4, 1))
#> [1] TRUE

Created on 2021-04-01 by the reprex package (v1.0.0)

@stefvanbuuren
Copy link
Member

Comment: If the results are similar. Using blocks plus default methods will have the drawback that only 1 default method can be applied to a block.

That's correct, but you should think of it as a feature rather than as a drawback. The whole idea of block imputation is that you can use one method (be it univariate or multivariate) to impute multiple variables at the same time.

@Garyf20
Copy link
Author

Garyf20 commented Apr 1, 2021 via email

@stefvanbuuren
Copy link
Member

I would do that by

mice(nhanes, blocks = list(c("bmi", "hyp"), "chl"), method = c("jomoImpute", "pmm"))

I also tried to set defaultMethod but that errors on chl, probably because it is univariate. But the above just works fine.

@amices amices locked and limited conversation to collaborators Apr 1, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants