Takes a mids object, performs maxit iterations and
produces a new object of class "mids".
Arguments
- obj
An object of class
mids, typically produces by a previous call tomice()ormice.mids()- newdata
An optional
data.framefor which multiple imputations are generated according to the model inobj. The imputation methods are taken fromobj. A variable without missing values in the training data has method""inobj. Ifnewdatahas missing values in such a variable,mice.mids()assigns the default method for its type (seemake.method()), and says so in a message. A method""that the user set for a variable with missing training data is kept, so these values stayNA.- maxit
The number of additional Gibbs sampling iterations. The default is 1.
Logical. If
TRUE(default), diagnostic information during the Gibbs sampling iterations is written to the console. Seemice().- future
Logical. If
TRUE, the chains are run as futures on the current future plan, as inmice(future = TRUE). The default continues in the mode in whichobjwas created. See Details.- ...
Named arguments that are passed down to the univariate imputation functions.
- printFlag
Legacy name of
print, kept for backward compatibility. If given, it takes precedence overprint.
Details
This function enables the user to split up the computations of the Gibbs sampler into smaller parts. This is useful for the following reasons:
To add a few extra iteration to an existing solution.
If RAM memory is exhausted. Returning to prompt/session level may alleviate such problems.
To customize convergence statistics at specific points, e.g., after every
maxititerations to monitor convergence.
The imputation model itself is specified in the mice() function
and cannot be changed in mice.mids(). The state of the random
generator is saved with the mids object. This ensures that the
imputations are reproducible.
By default, mice.mids() continues in the same way as the object
was created: an object made with future = TRUE continues as
futures on the current plan, and other objects continue with the classic
sequential sampler. In both cases, the result is identical to that of a
single call with all iterations. For an object made with
future = TRUE, this works because the object stores the state of
the random number stream of each chain (chainSeed).
It is possible to switch: future = TRUE continues a sequential
object as futures, and future = FALSE continues a future object
with the classic sampler, e.g. to see the iteration history or to debug
an imputation method. The result is reproducible, but differs from a
single call with all iterations, as the random numbers come from
different streams.
Examples
imp1 <- mice(nhanes, maxit = 1, seed = 123)
#>
#> iter imp variable
#> 1 1 bmi hyp chl
#> 1 2 bmi hyp chl
#> 1 3 bmi hyp chl
#> 1 4 bmi hyp chl
#> 1 5 bmi hyp chl
imp2 <- mice.mids(imp1)
#>
#> iter imp variable
#> 2 1 bmi hyp chl
#> 2 2 bmi hyp chl
#> 2 3 bmi hyp chl
#> 2 4 bmi hyp chl
#> 2 5 bmi hyp chl
# yields the same result as
imp <- mice(nhanes, maxit = 2, seed = 123)
#>
#> iter imp variable
#> 1 1 bmi hyp chl
#> 1 2 bmi hyp chl
#> 1 3 bmi hyp chl
#> 1 4 bmi hyp chl
#> 1 5 bmi hyp chl
#> 2 1 bmi hyp chl
#> 2 2 bmi hyp chl
#> 2 3 bmi hyp chl
#> 2 4 bmi hyp chl
#> 2 5 bmi hyp chl
# verification
identical(imp$imp, imp2$imp)
#> [1] TRUE
if (FALSE) { # \dontrun{
# the same holds for chains run as futures
future::plan(future::multisession, workers = 2)
imp1 <- mice(nhanes, maxit = 1, seed = 123, future = TRUE)
imp2 <- mice.mids(imp1)
imp <- mice(nhanes, maxit = 2, seed = 123, future = TRUE)
identical(imp$imp, imp2$imp)
future::plan(future::sequential)
} # }
#
