bootImpute {bootImpute}R Documentation

Bootstrap then impute an incomplete dataset

Description

Bootstraps an incomplete dataset and then imputes each bootstrap a number of times. The resulting list of bootstrapped then imputed datasets can be analysed with bootImputeAnalyse.

Usage

bootImpute(
  obsdata,
  impfun,
  nBoot = 200,
  nImp = 2,
  nCores = 1,
  seed = NULL,
  ...
)

Arguments

obsdata

The data frame to be imputed.

impfun

A function which when passed an incomplete dataset will return a list of imputed data frames.

nBoot

The number of bootstrap samples to take. It is recommended that you use a minimum of 200. If you specify nCores>1, nBoot must be a multiple of the specified nCores value.

nImp

The number of times to impute each bootstrap sample. Two is recommended.

nCores

The number of CPU cores to use. If specified greater than one, bootImpute will impute using the number of cores specified.

seed

Random number seed.

...

Other parameters that are to be passed through to impfun, which will often include the argument that tells impfun to generate as many imputations as specified by the value passed to nImp.

Details

The impfun must be a function which when passed an incomplete datasets and possibly additional arguments, returns a list of (e.g. 2) imputed datasets. The number of imputed datasets that impfun returns should match the value you specify for the argument nImp. Depending on what your imputation function returns by default, you may need to write a small wrapper function that calls the imputation procedure and returns the list of nImp datasets.See the Example for an illustration with the mice package.

To improve computation times, bootImpute now supports multiple cores through the nCores argument which uses the parallel package.

Value

A list of imputed datasets.

Examples

#this example shows how you can use bootImpute to impute using the mice
#package. If you do want to impute using MICE you can instead use the
#bootMice function, which essentially contains the code below
library(mice)

#write a wrapper function to call mice generating M imputations
impM <- function(inputData,M) {
  miceImps <- mice::mice(inputData, m=M)
  imps <- vector("list", M)
  for (i in 1:M) {
    imps[[i]] <- mice::complete(miceImps,i)
  }
  imps
}

#bootstrap twice and impute each twice
#in practice you should bootstrap many more times, e.g. at least 200
#note you have to tell bootImpute how many imputations per bootstrap in
#nImp=2 and also pass through whatever your imp function argument is called
#for specifying number of imputations, which here is M=2.
imps <- bootImpute(ex_linquad, impM, nBoot=2, nImp=2, M=2, seed=564764)

[Package bootImpute version 1.2.1 Index]