future_mids()
is analogous to mice::mice.mids()
, but parallelizes chains
using the {furrr}
package and stops early if convergence is detected using
the R-hat statistic
(see the future_mice()
documentation
for details).
Usage
future_mids(
obj,
newdata = NULL,
maxit = 100L,
minit = min(5L, maxit),
quiet = FALSE,
chunk_size = 1L,
rhat_max = 1.05,
progressor = NULL,
update_call = TRUE,
...
)
Arguments
- obj
A
mids
object, as created bymice::mice()
,future_mice()
, orfuture_mids()
(this function)- newdata
An optional
data.frame
for which multiple imputations are generated according to the model inobj
.- maxit
The number of additional Gibbs sampling iterations.
- minit
The minimum number of iterations to run. This is also the number of iterations used to assess convergence. Convergence is defined as
all(tail(rhat, minit) < rhat_max)
.- quiet
Should convergence messages and warning be suppressed?
- chunk_size
The average number of chains per future. Differs from the usual
{future}
parameter in that multiple chains ("chunks") will be evaluated in a single call tomice::mice()
if there is an integeri
such that1 < i <= chunk_size
andm %% i == 0
.- rhat_max
The R-hat threshold used to assess convergence. Convergence is defined as
all(tail(rhat, minit) < rhat_max)
.- progressor
An optional
progressor
function to signal progress updates. If supplied, you are responsible for ensuring that the number of steps in theprogressor
is consistent with the number of iterations performed infuture_mice()
.- update_call
Should
mids$call
be set to newfuture_mids()
call or left unchanged?- ...
Named arguments that are passed down to the univariate imputation functions.
Examples
# Run in parallel (just two cores to avoid hogging resources)
# Picking a number of workers that divides `m` evenly can help performance
future::plan("multisession", workers = pmin(2L, future::availableCores()))
# Run `mice::mice()`
# `m` and `maxit` are small here to keep runtime short
mids <- mice::mice(mice::nhanes, m = 2L, maxit = 1L)
#>
#> iter imp variable
#> 1 1 bmi hyp chl
#> 1 2 bmi hyp chl
# Run for additional iteration
mids <- future_mids(mids, maxit = 1L)
#> Warning: Sampling did not converge in 2 iterations
#> R-hat: NA
if (FALSE) {
# Run until convergence
mids <- future_mids(mids, maxit = 100L)
mids
}
# Reset future plan
future::plan("sequential")