
Bootstrap estimate, standard error and confidence interval
Source:R/variance.R
bootstrap_estimate.RdApplies a statistic to the point weights and to every bootstrap replicate, and
returns the estimate with its bootstrap standard error and a normal confidence
interval. boot_total() and boot_mean() are the two shortcuts you will use
most: a weighted total and a weighted mean of one column.
Arguments
- boot
a
weightflow_bootobject.- statistic
a function
function(w, data)returning a numeric scalar (or vector) given a weight vector and the data.- level
confidence level for the interval.
- ci_type
interval type: "normal" (default, z-based), "t" (Student t with the design degrees of freedom, wider and less anticonservative with few PSUs), or "percentile" (empirical quantiles of the valid replicates).
- df
degrees of freedom for the t interval;
NULL(default) uses the design df stored on the object (total PSUs minus strata).- variable
name of the variable to estimate.
Details
The bootstrap variance takes the replicate estimates
\(\hat\theta^{*}_b\) around the point estimate
\(\hat\theta\) (the mse = TRUE convention of survey), over the
\(R\) valid replicates (a failed replicate is dropped, not counted),
$$\widehat V_{\mathrm{boot}}(\hat\theta) = \frac{1}{R}\sum_{b=1}^{R}\big(\hat\theta^{*}_b - \hat\theta\big)^2.$$
See also
Other variance estimation:
as_svydesign(),
bootstrap_weights(),
collect_replicate_weights(),
jackknife_estimate(),
jackknife_weights()
Examples
spec <- weighting_spec(sample_survey, base_weights = pw) |>
step_calibrate(method = "raking",
margins = list(region = c(table(population$region))))
boot <- bootstrap_weights(spec, replicates = 50, strata = "region",
psu = "psu", seed = 1)
#> bootstrap replicate 25/50
#> bootstrap replicate 50/50
# a t interval with the design degrees of freedom (safer with few PSUs)
bootstrap_estimate(boot, function(w, d) sum(w * d$responded), ci_type = "t")
#> estimate se ci_lower ci_upper
#> 1 2663.277 90.4319 2483.771 2842.783