Skip to contents

The 'mice' hexlogo+ The 'futurize' hexlogo= The 'future' logo

The futurize package allows you to easily turn sequential code into parallel code by piping the sequential code to the futurize() function. Easy!

TL;DR

library(futurize)
plan(multisession)
library(mice)

imp <- mice(nhanes, m = 5) |> futurize()

Introduction

This vignette demonstrates how to use this approach to parallelize mice functions such as mice().

The mice package (Multivariate Imputation by Chained Equations) provides a principled approach to handling missing data. Its mice() function creates multiple imputed datasets by iterating a sequence of univariate imputation models, one per variable with missing values. Each of the m imputed datasets is generated independently, making the algorithm an excellent candidate for parallelization.

Example: Multiple imputation

The mice() function generates m imputed copies of a dataset. For example, using the built-in nhanes dataset, which contains missing values in three of its four variables:

library(mice)

imp <- mice(nhanes, m = 5)

Here mice() evaluates the m = 5 imputations sequentially, but we can easily make it evaluate them in parallel by piping to futurize():

library(futurize)
library(mice)

imp <- mice(nhanes, m = 5) |> futurize()

This will distribute the imputations across the available parallel workers, given that we have set up parallel workers, e.g.

plan(multisession)

The built-in multisession backend parallelizes on your local computer and works on all operating systems. There are other parallel backends to choose from, including alternatives to parallelize locally as well as distributed across remote machines, e.g.

plan(future.mirai::mirai_multisession)

and

plan(future.batchtools::batchtools_slurm)

Supported Functions

The following mice functions are supported by futurize():