Learn R Programming

NMAR (version 0.1.2)

bootstrap_variance: Bootstrap variance estimation module

Description

Estimates the variance of a scalar estimator via bootstrap resampling for IID data or bootstrap replicate weights for survey designs.

Usage

bootstrap_variance(data, estimator_func, point_estimate, ...)

Arguments

data

A data.frame or a survey.design.

estimator_func

Function returning an object with a numeric scalar component y_hat and an optional logical component converged.

point_estimate

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.

Bootstrap-specific options

resample_guard

IID bootstrap only. A function function(indices, data) that returns TRUE to accept a resample and FALSE to reject it.

bootstrap_settings

A list of arguments forwarded to svrep::as_bootstrap_design().

bootstrap_options

Alias for bootstrap_settings.

bootstrap_type

The type argument for svrep::as_bootstrap_design().

bootstrap_mse

The mse argument for svrep::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 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.

Details

  • 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().