There is an upcoming feature in mice
to re-use the imputation models, with the new tasks
argument:
# install dev version of mice
remotes::install_github("amices/mice", ref = "imputation_models")
# train imputation models
trained <- mice(nhanes, tasks = "train", seed = 1, print = FALSE)
# generate synthetic test set for illustraion purposes
newdata <- data.frame(age = c(2, 1), bmi = c(NA, NA), chl = c(NA, 190), hyp = c(NA, 1))
# re-use the imputation models on the test set
filled <- mice(newdata, tasks = "fill", models = trained$models, seed = 1, print = FALSE)
# inspect imputed test set data
complete(filled, 2)
#> age bmi chl hyp
#> 1 2 27.2 229 2
#> 2 1 33.2 190 1
A vignette for this feature is available via https://www.gerkovink.com/miceVignettes/Imputation_models/imputation_models.html
Feedback on this feature is welcomed via https://github.com/amices/mice/discussions/697