9 The Bootstrap
9.1 Prerequisites
Answer the following questions to see if you can bypass this chapter. You can find the answers at the end of the chapter in Section 9.19.
- What is the primary problem the bootstrap is designed to solve?
- Given \(B\) bootstrap replications \(\hat\theta^*_1, \dots, \hat\theta^*_B\) of a statistic, how do you compute the bootstrap standard error?
- Why is Monte Carlo approximation used in practice rather than computing the exact bootstrap distribution over all \(n^n\) possible resamples?
9.2 Learning objectives
By the end of this chapter you should be able to:
- Explain the plug-in principle that underlies the bootstrap.
- Implement a nonparametric bootstrap in base R.
- Compute percentile, basic, BCa, and studentized bootstrap confidence intervals.
- Construct bootstrap p-values via null-enforcing resampling.
- Apply case and residual bootstrap to regression coefficients.
- Recognize when the bootstrap fails (extreme quantiles, time series, dependent data).
- Use the
bootpackage for standard cases.
9.3 Orientation
The bootstrap (Efron, 1979; Efron & Tibshirani, 1993) is, in our view, the most useful general-purpose inference tool of the last fifty years. It works when analytic standard errors are impossible or wrong. When it does fail, it fails in interesting and learnable ways. Every biostatistician should be comfortable rolling her own bootstrap.
We begin with the four decisions that require the statistician’s judgment before any resampling takes place. We then present the plug-in principle, a simple nonparametric bootstrap in base R, and the relation between the bootstrap and sampling distributions. Standard errors, confidence intervals, hypothesis tests, and Monte Carlo error are considered next, followed by the settings in which the bootstrap fails. Lastly, we shall turn to the boot package, to bootstrapping regression coefficients, and to exercises in collaborating with an LLM.
9.4 The statistician’s contribution
Suppose we hand a dataset to a large language model with the instruction to ‘bootstrap the standard error’. Before doing so, we need to make four decisions that require the statistician’s judgment. By default, an LLM will execute a nonparametric iid bootstrap. Whether that is the appropriate bootstrap for the problem at hand is a determination the model cannot make without input from the statistician.
1. Is the bootstrap appropriate for this statistic at all? The bootstrap fails for extrema (sample max, min, modes) and for non-smooth statistics (change-points, mode estimates). It also fails for heavy-tailed populations with infinite variance and for samples below about \(n = 20\). An LLM will produce a numerical answer in every case, and in these cases the number will be misleading. Recognizing which case we are in is the statistician’s job.
2. What is the dependence structure of the data? An iid bootstrap on time series, clustered data, or longitudinal repeated measures systematically underestimates variance. The confidence interval will be too narrow, sometimes dramatically so. Only the analyst can detect the dependence in the data. It then falls to the analyst to specify a block bootstrap, a cluster bootstrap, or a parametric alternative that respects the structure.
3. Which confidence-interval method matches the statistic’s behavior? The percentile method is transformation-respecting and easy to explain. Unfortunately, undercoverage is common in small samples. BCa is second-order accurate and preferred for publication. The studentized method has the best coverage, but it requires a bootstrap-within-bootstrap. An LLM typically defaults to the percentile method whether or not the bootstrap distribution is skewed. Selecting a more appropriate method is the statistician’s responsibility.
4. Is the bootstrap distribution itself plausible? We should always plot the histogram of the \(B\) replicates. Suppose it is wildly skewed, truncated sharply at a boundary, or multimodal. Then either the bootstrap is failing for one of the reasons above, or the sampling distribution is genuinely unusual. In either case, we need to investigate before accepting the number as an answer.
In the remainder of this chapter we shall develop the technical vocabulary needed to make these four decisions.
9.5 The plug-in principle
We do not know the true population distribution \(F\). We do, however, know the empirical distribution \(\hat F_n\), that is, the distribution that places probability \(1/n\) on each observed data point. The plug-in principle says that to estimate any functional \(\theta = t(F)\), we substitute \(\hat F_n\) for \(F\) and compute \(\hat\theta = t(\hat F_n)\). The sample mean, median, quantiles, variance, and correlation are all plug-in estimates.
For sampling variability, the plug-in goes one step further. The sampling distribution of \(\hat\theta - \theta\) under repeated draws from \(F\) is approximated by the distribution of \(\hat\theta^* - \hat\theta\) under repeated draws from \(\hat F_n\). We can compute the second of these by resampling. The first is what we actually want to know. The bootstrap is the computational substitution of one for the other.
The substitution is justified by the Glivenko-Cantelli theorem. That is, \(\hat F_n\) converges uniformly to \(F\) as \(n\) grows. For smooth statistics, the higher-order accurate bootstrap intervals (BCa, studentized) achieve a coverage error of \(O(1/n)\). This is faster than the \(O(1/\sqrt n)\) rate of a central-limit-theorem interval. The plain percentile bootstrap, on the other hand, is only first-order accurate (\(O(1/\sqrt n)\) coverage error), the same rate as the CLT interval. We would use it primarily for its non-parametric applicability, since it offers no gain in the order of accuracy.
Q: What is the empirical distribution \(\hat F_n\) in the bootstrap context?
A: The discrete distribution that places probability \(1/n\) on each of the \(n\) observed data points in the original sample.
9.6 A simple nonparametric bootstrap
In base R, the nonparametric bootstrap takes eight lines:
# Original data
x <- c(5, 10, 15, 20, 25)
B <- 1000
boot_means <- numeric(B)
set.seed(47)
for (b in seq_len(B)) {
resample <- sample(x, size = length(x),
replace = TRUE)
boot_means[b] <- mean(resample)
}
sd(boot_means) # bootstrap standard errorThree features of this loop define the nonparametric bootstrap:
- Same size. Each resample has the same length as the original sample.
- With replacement. Without replacement every resample would be a permutation of the original, with no new variability.
- Repeated \(B\) times. \(B\) is the number of Monte Carlo draws. About 200 draws suffice for standard errors, 1000 to 2000 for confidence intervals, and 10,000 or more for extreme quantiles.
The vector boot_means is the bootstrap distribution of the sample mean. Its sample standard deviation is the bootstrap estimate of the standard error of \(\bar x\), and its quantiles give a percentile confidence interval.
Q: Why do we sample with replacement in the bootstrap?
A: Sampling with replacement creates variability between bootstrap samples. Without replacement, every resample would be a permutation of the original data, with no new information about sampling variability.
9.7 Bootstrap and sampling distributions
The bootstrap distribution and the sampling distribution are not the same thing. We note that they differ in three ways.
First, centering. The sampling distribution is centered at the true parameter \(\theta\), whereas the bootstrap distribution is centered near the observed estimate \(\hat\theta\). For this reason the bootstrap cannot recover the location of \(\theta\) itself; it can only mimic the offset. That is, for a biased \(\hat\theta\), the mean of the replicates sits roughly the bias away from \(\hat\theta\). This offset is what the bootstrap bias estimate \(\bar\theta^* - \hat\theta\) measures.
Second, support. In principle the sampling distribution can produce any value the true distribution can. The nonparametric bootstrap distribution, by contrast, is restricted to functions of the observed values. The restriction shows up when estimating the maximum of a bounded distribution, since the bootstrap cannot produce values larger than the observed maximum.
Third, variability. The bootstrap distribution has slightly less spread than the sampling distribution, by a factor of roughly \(\sqrt{(n - 1)/n}\). The bias is negligible for large \(n\). However, it compounds with the other small-sample weaknesses of the percentile method discussed below.
The bootstrap does faithfully capture the shape of the sampling distribution. This includes its skewness, its multimodality, and the boundary effects that arise near constrained parameters (such as a correlation coefficient near \(\pm 1\)). These shape diagnostics inform the choice of confidence-interval method, to which we return below.
Q: Can the bootstrap be used to improve our point estimate \(\hat\theta\)?
A: Generally, no. The bootstrap assesses the variability of \(\hat\theta\); it does not change the point estimate. The mean of the bootstrap distribution is approximately \(\hat\theta\) itself, and a biased \(\hat\theta\) produces a bootstrap distribution biased in the same direction.
9.8 Estimating standard errors
Let \(\hat\theta^*_1, \dots, \hat\theta^*_B\) denote the bootstrap replications, and let \(\bar\theta^* = B^{-1} \sum_b \hat\theta^*_b\) denote their mean. The bootstrap estimate of the standard error of \(\hat\theta\) is then
\[ \widehat{\mathrm{SE}}_B(\hat\theta) = \sqrt{\frac{1}{B - 1} \sum_{b=1}^B (\hat\theta^*_b - \bar\theta^*)^2}. \]
In R, this is sd(boot_replicates). The bootstrap SE is of most value where an analytic formula for \(\mathrm{SE}(\hat\theta)\) is unavailable, or where such a formula depends on assumptions the data do not satisfy. Examples include medians, trimmed means, correlation coefficients, and any custom statistic we can compute from a sample.
The Monte Carlo error of the bootstrap SE is approximately \(\widehat{\mathrm{SE}}_B / \sqrt{2B}\). With \(B = 1000\) this is roughly 2.2% of the bootstrap SE itself, which is negligible for most purposes.
Q: What statistical problems might become easier if we could repeatedly sample from the population?
A: We could empirically estimate standard errors, create confidence intervals without relying on parametric assumptions, and better understand sampling distributions for complex statistics. The bootstrap approximates this ideal using resampling from the observed data.
9.9 Confidence-interval flavors
Several bootstrap confidence-interval recipes exist, and each trades simplicity for coverage accuracy. All of them assume that \(B\) is large enough to estimate the required quantiles.
Percentile interval. This is the simplest recipe. We take the \(\alpha/2\) and \(1 - \alpha/2\) quantiles of the bootstrap distribution.
# Percentile CI by hand
quantile(boot_means, c(0.025, 0.975))The percentile interval is transformation-respecting. That is, a percentile interval on \(\log \hat\theta\) exponentiates to a percentile interval on \(\hat\theta\). However, it is first-order accurate only, and it tends to undercover in small samples.
Basic interval. The basic interval reflects the bootstrap distribution around \(\hat\theta\):
\[ [2\hat\theta - q_{1 - \alpha/2},\ 2\hat\theta - q_{\alpha/2}], \]
where \(q_\alpha\) is the \(\alpha\) quantile of the bootstrap distribution. It corrects a subtle bias that the percentile method inherits from centering at \(\hat\theta\). On the minus side, it loses the transformation-respecting property.
BCa interval. The bias-corrected and accelerated interval is second-order accurate. It adjusts the percentile endpoints using a bias correction (read from the bootstrap distribution’s median) and an acceleration constant (estimated by jackknife). It is available in boot::boot.ci(type = 'bca') and is preferred for publication-grade intervals.
Studentized interval. The studentized interval bootstraps a pivot \((\hat\theta^* - \hat\theta) / \widehat{\mathrm{SE}}^*\) and then inverts it to an interval on \(\theta\). It is second-order accurate and often has the best coverage. Unfortunately, it requires a bootstrap-within-bootstrap computation to estimate the inner standard error.
In practice, we reach for the percentile interval first. We switch to BCa if the sample is small or the statistic is skewed. We use the studentized interval only when the cost of the double bootstrap is justified.
9.10 Hypothesis testing by resampling
A confidence interval and a hypothesis test answer overlapping questions about a parameter, and the bootstrap supplies both. Hypothesis testing, however, requires one extra construction. That is, resampling must occur under conditions in which the null hypothesis is true. This null enforcement step is what distinguishes a bootstrap test from a bootstrap confidence interval.
To illustrate, consider a two-sample mean comparison, \(H_0\!: \mu_A = \mu_B\). The standard construction is pool and center. We concatenate the two samples after centering each at its own sample mean. The pooled vector has mean zero by construction, and resampling from it yields two new groups whose populations have identical means. We compute the observed test statistic on the original data and repeat the calculation on each bootstrap replicate drawn from the centered pool. We then report the proportion of replicates whose absolute statistic meets or exceeds the observed.
# Pool-and-center bootstrap test of H0: mu_A = mu_B
a <- sleep$extra[sleep$group == 1]
b <- sleep$extra[sleep$group == 2]
obs_diff <- mean(a) - mean(b)
pooled <- c(a - mean(a), b - mean(b))
B <- 10000
set.seed(47)
null_diffs <- replicate(B, {
a_star <- sample(pooled, length(a), replace = TRUE)
b_star <- sample(pooled, length(b), replace = TRUE)
mean(a_star) - mean(b_star)
})
mean(abs(null_diffs) >= abs(obs_diff))The two-sided p-value is mean(abs(null_diffs) >= abs(obs_diff)). For a one-sided alternative, we drop the absolute values and adjust the comparison direction. The Monte Carlo error on the p-value is approximately \(\sqrt{p(1 - p)/B}\). This comes to around \(0.002\) near \(p = 0.05\) when \(B = 10{,}000\).
Two comparisons clarify what the bootstrap test is doing. Permutation tests also generate a null distribution, by shuffling group labels without replacement. They are exact under exchangeability and are preferable when that assumption is defensible. The bootstrap test, on the other hand, is approximate. It does, however, extend naturally to settings where exchangeability fails, such as paired data, regression coefficients, or any statistic with a bootstrap implementation. Classical t-tests make stronger distributional assumptions. A pool-and-center bootstrap parallels the equal-variance two-sample t-test, while t.test() defaults to Welch’s unequal-variance test. The methods therefore produce different p-values because they implement different null hypotheses. Monte Carlo error is not the source of the difference.
The pool-and-center construction generalizes. To test a correlation against zero, we resample pairs \((x_i, y_i^*)\) in which the \(y\) values are reshuffled to break the dependence. To test a single regression coefficient against zero, we bootstrap the residuals of the reduced model and rebuild the response under the null. In each case we design a resampling scheme under which the null is true, and then read off the tail probability of the observed statistic.
Q: Why must the bootstrap resampling step enforce the null hypothesis when conducting a test, while no such adjustment is needed for a confidence interval?
A: A confidence interval describes the variability of \(\hat\theta\) around the unknown population parameter; the bootstrap distribution centered at \(\hat\theta\) is exactly the reference distribution wanted. A hypothesis test asks whether the data are compatible with a specified null value \(\theta_0\), which requires the distribution of \(\hat\theta\) under \(\theta = \theta_0\). That in turn requires resampling from a population modified to satisfy the null.
9.11 Monte Carlo implementation
The theoretical bootstrap enumerates all \(n^n\) possible resamples with replacement. For even modest \(n\) this number is astronomical: \(n = 20\) already produces \(20^{20} \approx 10^{26}\) ordered resamples. In practice we sample a manageable number \(B\) of resamples uniformly at random. This introduces a Monte Carlo error, which is distinct from the statistical error of using a finite original sample.
The Monte Carlo error of a percentile confidence-interval endpoint is approximately \(\sqrt{\alpha(1 - \alpha)/B} / f(q_\alpha)\), where \(f\) is the density of the bootstrap distribution at the endpoint \(q_\alpha\). To illustrate, consider a roughly normal bootstrap distribution and a 95% interval with \(B = 1000\). The Monte Carlo error is then about \(0.08 \cdot \widehat{\mathrm{SE}}_B\), an order of magnitude smaller than the statistical error for typical \(n\).
Some rules of thumb follow. For standard errors \(B = 200\) suffices. For percentile or BCa confidence intervals we use \(B = 1000\) to \(2000\), and for extreme quantiles or p-values below \(0.01\) we use \(B = 10{,}000\) or more. When in doubt, we rerun with a different seed and confirm that the results are stable.
Q: What can happen if you use too few bootstrap samples (for example, \(B = 50\))?
A: Substantial Monte Carlo error. Standard-error estimates are unstable across seeds, and percentile confidence-interval endpoints are unreliable because a handful of bootstrap replicates anchor each tail quantile.
9.12 When the bootstrap fails
The bootstrap works well when the statistic is a smooth function of the data and the sample size is moderate to large. It breaks down in several recognizable patterns.
Extrema. The sample maximum of a bounded distribution cannot exceed the observed maximum in any bootstrap resample. The bootstrap distribution therefore has no mass above the observed max. Bootstrap CIs for extrema, modes, and other boundary statistics are unreliable.
Non-smooth statistics. Sample quantiles at extreme tails, modes, and change-points are not smooth functions of the empirical distribution. That is, a small change in the data can produce a large change in the estimate. The bootstrap distribution of a sample median, for instance, is discrete even for continuous data.
Small samples. For \(n < 20\) the empirical distribution is a poor estimate of the true distribution, especially in the tails. A parametric bootstrap (resampling from a fitted parametric model) or a normal approximation with bias correction may perform better.
Dependent data. An iid bootstrap on time series or clustered data destroys the dependence structure and underestimates variance. For time series we use a block bootstrap, which resamples contiguous blocks of length \(\ell\). For hierarchical data we use a cluster bootstrap, which resamples whole clusters and keeps the within-cluster structure intact.
Heavy tails. When the population has infinite variance, the bootstrap distribution converges slowly or not at all. Sample means and regression coefficients from heavy-tailed data then require trimming, robust statistics, or a parametric bootstrap with a heavy-tailed assumption.
Q: Why might bootstrap methods struggle with the sample median when the sample size is small (say, \(n = 5\))?
A: With small samples the bootstrap distribution of the median is discrete and limited to the observed values. This coarse approximation of the sampling distribution yields inaccurate standard errors and confidence intervals.
9.13 The boot package
For production use, the boot package (Canty and Ripley, based on Davison and Hinkley’s book) handles the resampling, the parallelism, and the confidence-interval calculations. The standard workflow has three steps.
library(boot)
# Step 1: define the statistic as a function of data
# and indices.
median_stat <- function(data, indices) {
median(data[indices])
}
# Step 2: run the bootstrap.
set.seed(47)
x <- c(10, 14, 18, 23, 27, 32, 38, 42, 52, 68)
b <- boot(data = x, statistic = median_stat, R = 2000)
print(b)
# Step 3: compute confidence intervals.
boot.ci(b, type = c('perc', 'basic', 'bca'))The statistic function must accept (data, indices) and return the statistic computed on data[indices] (or data[indices, ] for a data frame). The boot() function handles the resampling through the indices. This is more memory-efficient than constructing each resample as a copy of the data. For stratified designs we pass strata = group. For parallel execution we set parallel = 'multicore' (Linux/macOS) or 'snow' (portable), with ncpus = parallel::detectCores() - 1.
Several functions provide specialized bootstraps:
car::Boot()wrapsboot()for regression models, handling case resampling, residual resampling, and wild bootstrap for heteroscedastic errors.boot::tsboot()implements block bootstrap for time series.rsample::bootstraps()integrates with thetidymodelsecosystem.
Q: What is the role of the indices parameter in the boot statistic function?
A: indices carries the positions of observations selected during each resample. Rather than constructing an actual bootstrap sample and passing it to the function, boot() passes only the indices; the function subsets the original data using data[indices]. This is more memory-efficient than copying the data for every replicate.
Q: In what scenarios would you prefer traditional methods over the bootstrap?
A: When sample sizes are very small, when the statistic has a known sampling distribution under assumptions that the data plausibly satisfy, or when computational resources are limited. Traditional methods also provide analytic insights (closed-form expressions, exact distributions) that numerical methods can obscure.
9.14 Bootstrapping regression coefficients
Linear regression provides a productive testbed for the bootstrap machinery. Two resampling strategies are standard. A third merits knowing for cases in which the diagnostics fail.
Case (paired) bootstrap. We resample whole rows of the data matrix with replacement, refit the model, and record the coefficient. This makes no assumption about the conditional distribution of \(y\) given \(x\). It remains valid under heteroscedasticity, because joint resampling of \((x, y)\) preserves whatever variance structure the data contain.
Residual bootstrap. We fit the model once and extract the residuals \(e_i = y_i - \hat y_i\). We then resample the residuals with replacement to obtain \(e_i^*\) and construct synthetic responses \(y_i^* = \hat y_i + e_i^*\). Lastly, we refit the model on \((x_i, y_i^*)\). This strategy assumes that the residuals are exchangeable. That is, their distribution does not depend on the predictors. When that assumption holds, the residual bootstrap is more efficient than the case bootstrap. When it fails, residual-bootstrap intervals are too narrow, because they impose a constant-variance error structure the data lack.
Wild bootstrap. Suppose the residuals are clearly heteroscedastic but the conditional-mean structure is correct. We then set \(e_i^* = e_i v_i\), with \(v_i\) an independent random sign or a Mammen two-point variable. This preserves the conditional variance pattern while still generating a valid resampling distribution.
To illustrate, consider a case bootstrap for the slope of wt predicting mpg in mtcars:
library(boot)
set.seed(47)
slope_stat <- function(data, indices) {
fit <- lm(mpg ~ wt, data = data[indices, ])
coef(fit)[['wt']]
}
b_lm <- boot(mtcars, slope_stat, R = 2000)
boot.ci(b_lm, type = c('perc', 'bca'))
# Compare with the classical normal-theory interval
confint(lm(mpg ~ wt, data = mtcars))['wt', ]The percentile and BCa intervals from the case bootstrap are slightly wider than the classical interval from confint(). The discrepancy is informative. A residuals-versus-fitted plot for this model shows variance increasing with the fitted value. The classical interval ignores this mild heteroscedasticity by assuming constant error variance. The bootstrap absorbs it through joint resampling and produces a more defensible interval.
The choice among strategies follows from the assumptions:
- We use the case bootstrap when residual diagnostics suggest heteroscedasticity, when the model may be misspecified, or as the default in the absence of contrary information.
- We use the residual bootstrap when the residuals are clean and the conditional mean is well captured. The narrower intervals it produces are warranted only when the assumption is defensible.
- We use the wild bootstrap when heteroscedasticity is severe but the mean structure is sound. This applies particularly in small samples, where the case bootstrap may resample the same influential observation multiple times.
The same machinery extends to generalized linear models (case bootstrap on glm objects), to random-effect models (a cluster bootstrap that respects the grouping structure), and to robust regression. The car::Boot() function introduced in the previous section handles several of these cases automatically.
Q: Suppose a residuals-versus-fitted plot for a regression model shows residual spread increasing with the fitted value. Which regression bootstrap would you choose, and why?
A: The case (paired) bootstrap, because it resamples whole \((x, y)\) rows and therefore preserves any heteroscedastic variance structure in the original data. The residual bootstrap imposes a single residual distribution that does not depend on \(x\) and would systematically underestimate variability in this setting.
9.15 Collaborating with an LLM on the bootstrap
Section Section 9.4 identified the four decisions that require the statistician’s judgment. In this section we shall provide practice exercises on those decisions. Each prompt below is adversarial, in the sense that it is designed to expose a specific LLM failure mode. We treat the model’s response as a hypothesis that requires verification.
9.15.1 Correlation and the Fisher-z transformation
Prompt. ‘Bootstrap a 95% confidence interval for the correlation between waiting and eruptions in the faithful dataset.’
What to watch for. A correlation is bounded in \([-1, 1]\), so its sampling distribution is asymmetric near the boundaries. A default nonparametric percentile bootstrap on the raw correlation stays inside \([-1, 1]\), but it can be poorly calibrated there. A normal-approximation bootstrap interval (\(\hat r \pm 1.96\,\widehat{\mathrm{SE}}\)), on the other hand, can produce endpoints that fall outside \([-1, 1]\). The textbook remedy is to form the interval on the Fisher-z transformation \(\tfrac{1}{2}\log\tfrac{1+r}{1-r}\) and then back-transform. We note that this remedy matters for the normal-approximation interval. The percentile interval is transformation-respecting, so wrapping it in the Fisher-z transformation leaves its endpoints unchanged.
Verification. We inspect the code. If it reports a normal-approximation interval, does it wrap the correlation in atanh() before forming the interval and tanh() after? If not, we compare the interval against cor.test(). A noticeable discrepancy indicates that the LLM skipped the transformation. We would then ask it a follow-up on whether a normal-approximation interval is guaranteed to stay in the valid range.
9.15.2 The bootstrap maximum
Prompt. ‘Write R code to compute a 95% percentile confidence interval for the maximum of a sample drawn from runif(50, 0, 1).’
What to watch for. The bootstrap fails for extrema. The bootstrap maximum cannot exceed the observed sample maximum, so the upper CI endpoint is always the observed max itself. This hard ceiling is not a property of the true sampling distribution.
Verification. We run the code and check whether the upper endpoint equals the sample maximum. We then ask the LLM: ‘Is this interval trustworthy? What does standard bootstrap theory say about statistics defined as extrema of the sample?’ The test is whether it recovers the failure mode on its own or insists that the interval is valid.
9.15.3 Time-series mean
Prompt. We supply a ts object of monthly clinical biomarker observations over three years and ask: ‘Bootstrap the mean and a 95% confidence interval.’
What to watch for. Autocorrelated data violate the iid assumption. An iid bootstrap destroys the dependence structure and underestimates variance. It typically produces an interval much narrower than the correct one.
Verification. Does the code call boot::tsboot() or a block-bootstrap function, or does it call plain boot::boot()? If the latter, the answer is wrong. We compute acf(x) and confirm non-trivial autocorrelation. We then redo the bootstrap with tsboot(x, ..., l = round(length(x)^(1/3)), sim = 'fixed') and compare interval widths.
9.15.4 Principle in use
These three prompts exercise the four statistician’s contributions from Section 9.4. The bootstrap maximum and the time-series mean both test decision 1 (is the bootstrap appropriate for this statistic or this data?). The time-series mean also tests decision 2 (dependence structure). The correlation prompt tests decisions 3 and 4 (confidence-interval method and bootstrap-distribution shape). None of these verifications requires advanced skill. Each does require that we ask the question the LLM will not ask for us.
9.16 Exercises
- Using only base R, write
bootstrap_ci(x, stat, R = 1000, conf = 0.95)that returns a percentile confidence interval for an arbitrary statistic of a numeric vectorx. - Apply your function to compute a 95% CI for the median of a right-skewed sample (e.g.,
rexp(50, 1)). Compare to the interval fromboot::boot.ci(type = 'perc'). - Compute coverage of the percentile CI in a simulation with 2000 replicates. Does it cover at the nominal 95%? Explain any under-coverage.
9.17 Further reading
- (Efron & Tibshirani, 1986), the clearest short introduction to the percentile bootstrap.
- (Efron & Tibshirani, 1993) Chapters 13-15, BCa and studentized intervals.
- (Hesterberg, 2015), pedagogical pitfalls that appear in student work.
9.18 Practice test
The following multiple-choice questions exercise the chapter’s content. Attempt each question before expanding the answer.
9.18.1 Question 1
What is the primary purpose of the bootstrap method?
- To replace traditional statistical analysis completely
- To assess the accuracy of parameter estimates when closed-form standard errors are difficult to derive
- To create larger datasets from small samples
- To identify outliers in statistical datasets
B. The bootstrap provides approximate standard errors, bias, and confidence intervals by resampling.
9.18.2 Question 2
How does the bootstrap estimate the standard error of a statistic?
- By calculating the exact formula for every possible case
- By approximating the sampling distribution through repeatedly resampling with replacement from the observed data
- By assuming the data follows a normal distribution
- By comparing the statistic to previously established benchmarks
B. The bootstrap treats the empirical distribution of the data as a proxy for the true population distribution and resamples from it with replacement.
9.18.3 Question 3
Given \(B\) bootstrap replications of a statistic, how is the bootstrap standard error calculated?
- By taking the square root of the sample variance divided by \(n\)
- By computing the standard deviation of the \(B\) bootstrap replications
- By using a predefined formula based on the Central Limit Theorem
- By applying maximum likelihood estimation to the data
B. The bootstrap SE is the sample SD of the \(B\) bootstrap replicates.
9.18.4 Question 4
Why is Monte Carlo approximation typically used in bootstrap estimation rather than computing the exact bootstrap distribution?
- Because the exact bootstrap distribution requires evaluating all \(n^n\) possible resamples, which is computationally infeasible
- Because the Central Limit Theorem does not apply to bootstrap estimates
- Because the original dataset is always too small to be reliable
- Because exact enumeration produces biased results
A. Even for small \(n\), \(n^n\) grows very quickly. Monte Carlo samples a practical number \(B\) of resamples, and the choice of \(B\) controls the accuracy.
9.18.5 Question 5
How is the bootstrap estimate of bias for a statistic \(\hat\theta\) defined?
- The difference between the mean of the bootstrap replications and the original estimate \(\hat\theta\)
- The standard deviation of the bootstrap replications
- The skewness of the bootstrap distribution
- The difference between the median and mean of the bootstrap replications
A. Bootstrap bias is \(\bar\theta^* - \hat\theta\), where \(\bar\theta^*\) is the mean of bootstrap replicates.
9.19 Prerequisites answers
- The bootstrap assesses the sampling distribution of a statistic (its standard error, bias, and confidence interval) when a closed-form expression is unavailable, complicated, or depends on distributional assumptions the data do not satisfy.
- The bootstrap standard error is the sample standard deviation of the \(B\) bootstrap replications: \(\widehat{\mathrm{SE}}_B(\hat\theta) = \sqrt{\tfrac{1}{B-1} \sum_{b=1}^B (\hat\theta^*_b - \bar\theta^*)^2}\).
- The exact bootstrap distribution requires evaluating the statistic on all \(n^n\) possible resamples (with replacement from \(n\) observations), which is computationally infeasible for any meaningful \(n\). Monte Carlo approximation draws a manageable number \(B\) of resamples at random.