Perform various bootstrap process for nested linear mixed effects (LMEs) models including: parametric, residual, cases, wild, and REB bootstraps.

# S3 method for merMod
bootstrap(
  model,
  .f = extract_parameters,
  type,
  B,
  resample,
  reb_type,
  hccme,
  aux.dist,
  orig_data = NULL,
  .refit = TRUE
)

# S3 method for lme
bootstrap(
  model,
  .f = extract_parameters,
  type,
  B,
  resample,
  reb_type,
  hccme,
  aux.dist,
  orig_data = NULL,
  .refit = TRUE
)

bootstrap(
  model,
  .f,
  type,
  B,
  resample = NULL,
  reb_type = NULL,
  hccme = NULL,
  aux.dist = NULL,
  orig_data = NULL,
  .refit = TRUE
)

Arguments

model

The model object you wish to bootstrap.

.f

A function returning the statistic(s) of interest.

type

A character string indicating the type of bootstrap that is being requested. Possible values are "parametric", "residual", "case", "wild", or "reb" (random effect block bootstrap).

B

The number of bootstrap resamples.

resample

A logical vector specifying whether each level of the model should be resampled in the cases bootstrap. The levels should be specified from the highest level (largest cluster) of the hierarchy to the lowest (observation-level); for example for students within a school, specify the school level first, then the student level.

reb_type

Specification of what random effect block bootstrap version to implement. Possible values are 0, 1 or 2.

hccme

either "hc2" or "hc3", indicating which heteroscedasticity consistent covariance matrix estimator to use.

aux.dist

one of "mammen", "rademacher", "norm", "webb", or "gamma" indicating which auxiliary distribution to draw the errors from

orig_data

the original data frame. This should be specified if variables are transformed within the formula for glmer() or lmer() and the case bootstrap is used.

.refit

a logical value indicating whether the model should be refit to the bootstrap resample, or if the simulated bootstrap resample should be returned. Defaults to TRUE.

Value

The returned value is an object of class "lmeresamp". This is a list with the following elements:

  • observed: the estimated values for the model parameters

  • model: the fitted model object

  • .f: the function call

  • replicates: a \(B \times p\) data frame of bootstrap values for each of the p model parameters,

  • stats: a tibble containing the \]codeobserved, rep.mean (bootstrap mean), se (bootstrap standard error), and bias values for each model parameter,

  • B: the number of bootstrap resamples performed

  • data: the data with which the model was fit

  • seed: a vector of randomly generated seeds that are used by the bootstrap

  • type: the type of bootstrap executed

  • call: the call to bootstrap() that the user

  • message: a list of length B giving any messages generated during refitting. An entry will be NULL if no message was generated.

  • warning: a list of length B giving any warnings generated during refitting. An entry will be NULL if no message was generated.

  • error: a list of length B giving any errors generated during refitting. An entry will be NULL if no message was generated.

Details

All of the below methods have been implemented for nested linear mixed-effects models fit by lmer (i.e., an lmerMod object) and lme (i.e., an lmerMod object). Details of the bootstrap procedures can be found in the help file for that specific function.

References

Carpenter, J. R., Goldstein, H. and Rasbash, J. (2003) A novel bootstrap procedure for assessing the relationship between class size and achievement. Journal of the Royal Statistical Society. Series C (Applied Statistics), 52, 431--443.

Chambers, R. and Chandra, H. (2013) A random effect block bootstrap for clustered data. Journal of Computational and Graphical Statistics, 22, 452--470.

Morris, J. S. (2002) The BLUPs are not "best" when it comes to bootstrapping. Statistics and Probability Letters, 56, 425--430.

Van der Leeden, R., Meijer, E. and Busing F. M. (2008) Resampling multilevel models. In J. de Leeuw and E. Meijer, editors, Handbook of Multilevel Analysis, pages 401--433. New York: Springer.

Bates, D., Maechler, M., Bolker, W., Walker, S. (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67, 1--48. doi:10.18637/jss.v067.i01.

Modugno, L., & Giannerini, S. (2015). The Wild Bootstrap for Multilevel Models. Communications in Statistics -- Theory and Methods, 44(22), 4812--4825.

See also

Examples

#> Loading required package: Matrix
vcmodA <- lmer(mathAge11 ~ mathAge8 + gender + class + (1 | school), data = jsp728) ## you can write your own function to return stats, or use something like 'fixef' mySumm <- function(.) { s <- getME(., "sigma") c(beta = getME(., "beta"), sigma = s, sig01 = unname(s * getME(., "theta"))) } ## running a parametric bootstrap set.seed(1234) boo1 <- bootstrap(model = vcmodA, .f = mySumm, type = "parametric", B = 20) ## to print results in a formatted way print(boo1)
#> Bootstrap type: parametric #> #> Number of resamples: 20 #> #> term observed rep.mean se bias #> 1 beta1 14.1577509 14.1949464 0.66538125 0.0371954794 #> 2 beta2 0.6388895 0.6385629 0.02608992 -0.0003265699 #> 3 beta3 -0.3571922 -0.4561735 0.35477238 -0.0989812789 #> 4 beta4 0.7200815 0.7927683 0.31179264 0.0726868125 #> 5 sigma 4.4416279 4.4036722 0.11963706 -0.0379557056 #> 6 sig01 1.8199553 1.7894322 0.23985803 -0.0305230950 #> #> There were 0 messages, 0 warnings, and 0 errors.
if (FALSE) { ## running a cases bootstrap - only resampling the schools boo2 <- bootstrap(model = vcmodA, .f = mySumm, type = "case", B = 100, resample = c(TRUE, FALSE)) ## running a cases bootstrap - resampling the schools and students within the school boo3 <- bootstrap(model = vcmodA, .f = mySumm, type = "case", B = 100, resample = c(TRUE, TRUE)) ## running a residual bootstrap boo4 <- bootstrap(model = vcmodA, .f = mySumm, type = "residual", B = 100) ## running an REB0 bootstrap boo5 <- bootstrap(model = vcmodA, .f = mySumm, type = "reb", B = 100, reb_typ = 0) ## Running the Wild bootstrap boo6 <- bootstrap(model = vcmodA, .f = mySumm, type = "wild", B= 100, hccme = "hc2", aux.dist = "mammen") ## Running a bootstrap in parallel via foreach library(foreach) library(doParallel) set.seed(1234) numCores <- 2 cl <- makeCluster(numCores, type = "PSOCK") # make a socket cluster doParallel::registerDoParallel(cl) # how the CPU knows to run in parallel b_parallel <- foreach(B = rep(250, 2), .combine = combine_lmeresamp, .packages = c("lmeresampler", "lme4")) %dopar% { bootstrap(vcmodA, .f = fixef, type = "parametric", B = B) } stopCluster(cl) ## Running a bootstrap in parallel via parLapply cl <- makeCluster(numCores, type = "PSOCK") # make a socket cluster doParallel::registerDoParallel(cl) # how the CPU knows to run in parallel boot_mod <- function(...) { library(lme4) library(lmeresampler) vcmodA <- lmer(mathAge11 ~ mathAge8 + gender + class + (1 | school), data = jsp728) bootstrap(vcmodA, .f = fixef, type = "parametric", B = 250) } result <- parLapply(cl, seq_len(2), boot_mod) b_parallel2 <- do.call("combine_lmeresamp", result) stopCluster(cl) }