Bootstrap Effects
Bootstrap model effects (standardised coefficients) and optional SEM correlated errors.
bootEff( mod, R, seed = NULL, type = "nonparametric", ran.eff = NULL, cor.err = NULL, catch.err = TRUE, parallel = "snow", ncpus = NULL, cl = NULL, bM.arg = NULL, ... )
mod |
A fitted model object, or a list or nested list of such objects. |
R |
Number of bootstrap resamples to generate. |
seed |
Seed for the random number generator. If not provided, a random five-digit integer is used (see Details). |
type |
The type of bootstrapping to perform. Can be
|
ran.eff |
For nonparametric bootstrapping of mixed models, the name of the (highest-level) random effect to resample (see Details). |
cor.err |
Optional, names of SEM correlated errors to be bootstrapped.
Should be of the form: |
catch.err |
Logical, should errors generated during model fitting or
estimation be caught and |
parallel |
The type of parallel processing to use. Can be one of
|
ncpus |
Number of system cores to use for parallel processing. If
|
cl |
Optional cluster to use if |
bM.arg |
A named list of any additional arguments to |
... |
Arguments to |
bootEff
uses the boot
function
(primarily) to bootstrap standardised effects from a fitted model or list
of models (calculated using 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.
set.seed(NULL)
).
Where 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
(specifying 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 using rMapply
(remember to set a
seed).
Where names of models 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 differently-sized datasets 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
unchanged.
For mixed models with
non-nested
random effects, nonparametric resampling will not be appropriate. In these
cases, (semi-)parametric bootstrapping can be performed instead via
bootMer
in the lme4 package (with additional
arguments passed to that function as necessary). NOTE: As bootMer
takes only a fitted model as its first argument, 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,
bootEff
with nonparametric bootstrapping will still work and will
treat all models as mixed for resampling (with a warning). This is probably
a relatively rare scenario, but may occur where the user decides that
non-mixed models perform similarly and/or cause less issues than their
mixed counterparts for at least some response variables (e.g. where random
effect variance estimates are at or near zero). If nonparametric
bootstrapping is not used however, an error will occur, as bootMer
will only accept mixed models.
Parallel processing is used by default via the parallel package and
option parallel = "snow"
(and is generally recommended), but users
can specify the type of parallel processing to use, or none. If
"snow"
, a 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 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 optimizers 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. https://doi.org/dvfzcn
# Bootstrap Shipley SEM (test) # (set 'site' as group for resampling - highest-level random effect) bootEff(Shipley.SEM, ran.eff = "site", R = 1, parallel = "no") # Estimates (use saved boot object, 10000 resamples) lapply(Shipley.SEM.Boot, "[[", 1) # original lapply(Shipley.SEM.Boot, function(i) head(i$t)) # bootstrapped
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.