Bootstrap model effects (standardised coefficients) and optional SEM correlated errors.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
A fitted model object, or a list or nested list of such objects.
Number of bootstrap resamples to generate.
Seed for the random number generator. If not provided, a random five-digit integer is used (see Details).
The type of bootstrapping to perform. Can be
For nonparametric bootstrapping of mixed models, the name of the (highest-level) random effect to resample (see Details).
Optional, names of SEM correlated errors to be bootstrapped
Logical, should errors generated during model fitting or
estimation be caught and
The type of parallel processing to use. Can be one of
Number of system cores to use for parallel processing. If
Optional cluster to use if
A named list of any additional arguments to
boot::boot() (primarily) to bootstrap
standardised effects from a fitted model or list of models (calculated
stdEff()). Bootstrapping is typically nonparametric, i.e. model
effects are calculated from data where the rows have been randomly sampled
with replacement. 10,000 such resamples should provide accurate coverage
for confidence intervals in most situations, with fewer sufficing in some
cases. To ensure that data is resampled in the same way across individual
bootstrap operations within the same run (e.g. models in a list), the same
seed is set per operation, with the value saved as an attribute to the
matrix of bootstrapped values (for reproducibility). The seed can either be
user-supplied or a randomly-generated five-digit number (default), and is
always re-initialised on exit (i.e.
weights are specified, bootstrapped effects will be a weighted
average across the set of candidate models for each response variable,
calculated after each model is first refit to the resampled dataset
weights = "equal" will use a simple average instead - see
avgEst()). If no weights are specified and
mod is a nested list of
models, the function will throw an error, as it will be expecting weights
for a presumed model averaging scenario. If instead the user wishes to
bootstrap each individual model, they should recursively apply the function
rMapply() (remember to set a seed).
Where names of response variables with correlated errors are specified to
cor.err, the function will also return bootstrapped Pearson correlated
errors (weighted residuals) for those models. If
weights are supplied and
mod is a nested list, residuals will first be averaged across candidate
models. If any two models (or candidate sets) with correlated errors were
fit to different subsets of data observations, both models/sets are first
refit to data containing only the observations in common.
For nonparametric bootstrapping of mixed models, resampling should occur at
the group-level, as individual observations are not independent. The name
of the random effect to resample must be supplied to
ran.eff. For nested
random effects, this should be the highest-level group (Davison & Hinkley
1997, Ren et al. 2010). This form of resampling will result in datasets
of different sizes if observations are unbalanced across groups; however
this should not generally be an issue, as the number of independent units
(groups), and hence the 'degrees of freedom', remains
For mixed models with non-nested random effects,
nonparametric resampling will not be appropriate. In these cases,
parametric or semiparametric bootstrapping can be performed instead via
lme4::bootMer() (with additional arguments passed to that function as
necessary). NOTE: As
bootMer() takes only a fitted model as its first
argument (i.e. no lists), any model averaging is calculated 'post-hoc'
using the estimates in boot objects for each candidate model, rather than
during the bootstrapping process itself (i.e. the default procedure via
boot()). Results are then returned in a new boot object for each response
variable or correlated error estimate.
If supplied a list containing both mixed and non-mixed models,
with nonparametric bootstrapping will still work and will treat all models
as mixed models for resampling (with a warning). This is likely a
relatively rare scenario, but may occur where the user decides that
non-mixed models perform similarly and/or cause less fitting issues than
their mixed counterparts for at least some response variables (e.g. where
random effect variance estimates are at or near zero). The data will be
resampled on the supplied random effect for all models. If nonparametric
bootstrapping is not used in this scenario however, an error will occur, as
bootMer() will only accept mixed models.
Parallel processing is used by default via the parallel package and
parallel = "snow" (and is generally recommended), but users can
specify the type of parallel processing to use, or none. If
cluster of workers is created using
makeCluster(), and the user can
specify the number of system cores to incorporate in the cluster (defaults
to all available).
bootEff() then exports all required objects and
functions to this cluster using
clusterExport(), after performing a
(rough) match of all objects and functions in the current global
environment to those referenced in the model call(s). Users should load any
required external packages prior to calling the function.
An object of class
"boot" containing the bootstrapped effects, or a
(named) list/nested list of such objects.
Bootstrapping mixed (or indeed any other) models may take a very long time when the number of replicates, observations, parameters, and/or models is high. To decrease processing time, it may be worth trying different optimisers and/or other options to generate faster estimates (always check results).
Burnham, K. P., & Anderson, D. R. (2002). Model Selection and Multimodel Inference: A Practical Information-Theoretic Approach (2nd ed.). New York: Springer-Verlag. Retrieved from https://www.springer.com/gb/book/9780387953649
Davison, A. C., & Hinkley, D. V. (1997). Bootstrap Methods and their Application. Cambridge University Press.
Ren, S., Lai, H., Tong, W., Aminzadeh, M., Hou, X., & Lai, S. (2010). Nonparametric bootstrapping for hierarchical data. Journal of Applied Statistics, 37(9), 1487–1498. doi: 10/dvfzcn
1 2 3 4 5 6 7
# Bootstrap Shipley SEM (test — 1 rep) # (set 'site' as group for resampling — highest-level random effect) bootEff(shipley.sem, R = 1, ran.eff = "site", parallel = "no") # Check estimates (use saved boot object — 1000 reps) lapply(shipley.sem.boot, "[[", 1) # original lapply(shipley.sem.boot, function(i) head(i$t)) # bootstrapped
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.