parmice: Parallel function for MICE

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/parmice.R

Description

This is a wrapper function for mice, using multiple cores to execute mice in parallel. As a result, the imputation procedure is sped up, which might be useful in general.

Usage

1
2
parmice(data, n.core = detectCores() - 1, n.imp.core = 2, seed = NULL,
  m = NULL, ...)

Arguments

data

A data frame or matrix containing the incomplete data. Similar to the first argument of mice.

n.core

A scalar indicating the number of cores that should be used. Default is the number of logical cores minus 1.

n.imp.core

A scalar indicating the number of imputations per core. The total number of imputations will be equal to n.core * n.imp.core.

seed

A scalar to be used as the seed value. It is recommended to put the seed value here and not outside this function, as otherwise the parallel processes will be performed with separate, random seeds.

...

Named arguments that are passed down to function mice or makeCluster.

Details

This function is built upon package parallel, which is a base package for R versions 2.14.0 and later. We have chosen to use parallel function parLapply to allow the use of parallelMICE on Mac, Linux and Windows systems. For the same reason, we use the Parallel Socket Cluster (PSOCK) type.

On systems other than Windows, it is recommended to change the cluster type to FORK, as it is better in handling the memory space. When memory issues arise on a Windows system, we advise to store the multiply imputed datasets, clean the memory by using rm and gc and make another run using the same settings. For more tips about dealing with memory problems, we refer to Max Gordon's document *How-to go parallel in R <e2><80><93> basics + tips*.

This wrapper function combines the output of parLapply with function ibind in mice. A mids object is returned and can be used for further analyses.

Note that if a seed value is desired, the seed should be entered to this function with argument seed. Seed values outside the wrapper function (in an R-script or passed to mice) will not result to reproducible results. We refer to the manual of parallel for an explanation on this matter.

A vignette describing the use of 'parlMICE' can be found in the mice package or through Github: https://github.com/gerkovink/parallelMICE/blob/master.

Value

A mids object as defined by mids-class

Author(s)

Rianne Schouten, Gerko Vink, 2016, with many thanks to Max Gordon.

References

Gordon, M. (2015). How-to go parallel in R <e2><80><93> basics + tips.

Van Buuren, S. (2012). Flexible imputation of missing data. Boca Raton, FL.: Chapman & Hall/CRC Press.

See Also

parallel, parLapply, makeCluster, mice, mids-class

Examples

1
2
3
4
5
6
7
# 150 imputations in dataset nhanes, performed by 3 cores
result1 <- parlMICE(data = nhanes, n.core = 3, n.imp.core = 50)
# Making use of arguments in \code{mice}.
result2 <- parlMICE(data = nhanes, method = "norm.nob", m = 100)
with(result2, lm(bmi ~ hyp))
# On systems other than Windows, use type = "FORK"
result3 <- parlMICE(data = nhanes, type = "FORK", n.imp.core = 100)

sdaza/sdazar documentation built on May 29, 2019, 4:20 p.m.