Parallel computation of multiple imputations by using mitml
Closed this issue · 2 comments
sophieschneemelcher commented
Dear Simon,
I was wondering if there is any possibility to run multiple imputation using jomoImpute
with parallel processing like futuremice
in the mice
package does. This would speed up my imputation process.
Thank you very much in advance
Sophie
simongrund1 commented
Currently, mitml
does not have out-of-the-box parallelization, but you can use packages like parallel
or future
for this. This can save computation time, but it also comes with the disadvantage of having to (a) re-run the burn-in phase of the imputation, and (b) inspect multiple output objects for the results.
Here's an example with parallel
and some timings:
library(parallel)
library(mitml)
dat <- studentratings
fml <- ReadDis + SES ~ ReadAchiev + (1|ID)
# parallelized
.cl <- parallel::makeCluster(2, type = "PSOCK")
parallel::clusterEvalQ(.cl, library(mitml))
parallel::clusterExport(.cl, varlist = c("dat", "fml"))
t1 <- system.time({
par.seed <- c(5947, 7135)
imp1 <- parallel::parLapply(.cl, par.seed, function(s) jomoImpute(dat, formula = fml, n.burn = 5000, n.iter = 100, m = 50, seed = s))
})
parallel::stopCluster(.cl)
# non-parallelized
t2 <- system.time({
imp2 <- jomoImpute(dat, formula = fml, n.burn = 5000, n.iter = 100, m = 100, seed = 2452)
})
t1 # ~6 sec
t2 # ~10 sec
# summaries
lapply(imp1, summary)
summary(imp2)
# create lists of imputed data sets
implist1 <- as.mitml.list(do.call(c, lapply(imp1, mitmlComplete)))
implist2 <- mitmlComplete(imp2)
simongrund1 commented
No further response, so I'm marking this as solved (but can open again if needed).