Estimates the variance of a scalar estimator via bootstrap resampling for IID data or bootstrap replicate weights for survey designs.
bootstrap_variance(data, estimator_func, point_estimate, ...)A data.frame or a survey.design.
Function returning an object with a numeric scalar
component y_hat and an optional logical component converged.
Numeric scalar; used for survey bootstrap variance
(passed to survey::svrVar() as coef).
Additional arguments. Some are consumed by bootstrap_variance()
itself (for example resample_guard for IID bootstrap or
bootstrap_settings/bootstrap_options/bootstrap_type/bootstrap_mse
or survey bootstrap). Remaining arguments are forwarded to estimator_func.
resample_guardIID bootstrap only. A function
function(indices, data) that returns TRUE to accept a resample
and FALSE to reject it.
bootstrap_settingsA list of arguments forwarded to svrep::as_bootstrap_design().
bootstrap_optionsAlias for bootstrap_settings.
bootstrap_typeThe type argument for svrep::as_bootstrap_design().
bootstrap_mseThe mse argument for svrep::as_bootstrap_design().
If the optional progressr package is installed, bootstrap calls
indicate progress via a progressr::progressor inside
progressr::with_progress(). Users control if and how progress is shown
by registering handlers with progressr::handlers(). When
progressr is not installed or no handlers are active, bootstrap runs
silently.
By default, bootstrap replicate evaluation runs sequentially via
base::lapply() for both IID resampling and survey replicate-weight bootstrap.
If the optional future.apply package is installed, bootstrap can use
future.apply::future_lapply(future.seed = TRUE) when the user has set
a parallel future::plan().
The backend is controlled by the package option nmar.bootstrap_apply:
"auto"(default) Use base::lapply() unless the current
future plan has more than one worker, in which case use
future.apply::future_lapply() if available.
"base"Always use base::lapply(), even
if future.apply is installed.
"future"Always use future.apply::future_lapply().
When future.apply is used, random-number streams are parallel-safe and
backend-independent under the future framework. When base::lapply()
is used, results are reproducible under set.seed() but will
likely not match the future.seed streams.
For data.frame inputs, performs IID bootstrap by resampling
rows and rerunning estimator_func on each resample, then
computing the empirical variance of the replicate estimates.
For survey.design inputs, converts the design to a bootstrap
replicate-weight design with svrep::as_bootstrap_design(),
evaluates estimator_func on each replicate weight vector by
injecting the replicate analysis weights into a copy of the input design,
and passes the resulting replicate estimates and replicate scaling factors
to survey::svrVar().