Estimates the variance of a scalar estimator via bootstrap resampling for IID data or bootstrap replicate weights for survey designs.
Arguments
- data
A
data.frameor asurvey.design.- estimator_func
Function returning an object with a numeric scalar component
y_hatand an optional logical componentconverged.- point_estimate
Numeric scalar; used for survey bootstrap variance (passed to
survey::svrVar()ascoef).- ...
Additional arguments. Some are consumed by
bootstrap_variance()itself (for exampleresample_guardfor IID bootstrap orbootstrap_settings/bootstrap_options/bootstrap_type/bootstrap_mseor survey bootstrap). Remaining arguments are forwarded toestimator_func.
Details
For
data.frameinputs, performs IID bootstrap by resampling rows and rerunningestimator_funcon each resample, then computing the empirical variance of the replicate estimates.For
survey.designinputs, converts the design to a bootstrap replicate-weight design withsvrep::as_bootstrap_design(), evaluatesestimator_funcon 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 tosurvey::svrVar().
Bootstrap-specific options
resample_guardIID bootstrap only. A function
function(indices, data)that returnsTRUEto accept a resample andFALSEto reject it.bootstrap_settingsA list of arguments forwarded to
svrep::as_bootstrap_design().bootstrap_optionsAlias for
bootstrap_settings.bootstrap_typeThe
typeargument forsvrep::as_bootstrap_design().bootstrap_mseThe
mseargument forsvrep::as_bootstrap_design().
Progress Reporting
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.
Parallelization
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 usefuture.apply::future_lapply()if available."base"Always use
base::lapply(), even iffuture.applyis 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.
