Method · Statistics Library

Bootstrap confidence interval

The bootstrap builds a confidence interval for a statistic (mean, median, SD, correlation, or regression slope) by resampling your own data thousands of times with replacement, instead of trusting a textbook formula that may assume normality.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

Normally a confidence interval comes from a formula that assumes something about the shape of the population (often that it is roughly bell-shaped). The bootstrap sidesteps that assumption by using your sample as a stand-in for the population and repeatedly drawing new 'pretend' samples FROM it, the same size as your real one, with replacement, so some rows get picked twice and others not at all.

Each pretend sample gives its own value of the statistic you care about (its own mean, its own median, whatever you chose). Do this nine thousand-plus times and you get a whole distribution of plausible values: the bootstrap distribution. The spread of that distribution is your standard error, with no formula needed, and its middle 95% (adjusted for skew) is your confidence interval.

It only works as well as your original sample represents the real population. If your sample is small, biased, or the rows are secretly linked to each other (repeated measurements, a time series), resampling them cannot manufacture information that was never collected: the bootstrap describes the data you gave it, nothing more.

Bootstrapping gives a resampling confidence interval, often called a bootstrap CI, by recomputing the statistic on many resamples drawn with replacement from your own data. The BCa interval is a refined bootstrap interval that adjusts for bias and skew in the resampled values.

Practitioner explanation

KernelStats bootstraps five statistics (mean, median, SD, Pearson correlation, and a simple regression slope) and defaults to the bias-corrected and accelerated (BCa) interval (method = BCa), with percentile and basic (reverse-percentile) offered as alternatives. n_resamples defaults to 9999 and is clamped to [100, 200000]; random_seed defaults to 42 for reproducibility, recorded on the card so a rerun matches exactly.

BCa corrects the naive percentile interval for both bias (how off-center the bootstrap distribution sits relative to the point estimate, z0) and acceleration (skewness of the sampling distribution, estimated by jackknife, a). It is generally the most accurate of the three but can be unstable for degenerate inputs (a near-constant column, or a statistic like the median under heavy ties), and the card records bca_fallback when the acceleration cannot be estimated and the interval silently degrades to percentile; this is reported, not hidden.

The resampling here is the ordinary i.i.d. bootstrap: it assumes rows are independent draws. It does NOT implement a block or cluster bootstrap, so time-series or clustered/repeated-measures data will get an interval that understates the true uncertainty if run through this function as-is: aggregate to one row per independent unit first, or use a method designed for the dependence structure.

When to use it

Consider it when

You want a confidence interval for a mean, median, SD, correlation, or regression slope and do not want to rely on a formula's normality or large-sample assumption, especially for a skewed statistic like the median, or a small or unusual-looking sample.

Use caution when

Rows that are not independent draws (repeated measures, clustered data, or a time series) need a block or cluster bootstrap, which this function does not perform. It also cannot rescue a sample that is not representative of the population you care about (a biased convenience sample resampled many times is still biased), and with very small n (under roughly 20) the interval can be misleadingly narrow because the resamples cannot explore values never observed in the original sample.

Formulas and symbols

Bootstrap standard error

SE^boot=1B−1∑b=1B(θ^b∗−θˉ∗)2\widehat{\mathrm{SE}}_{\text{boot}} = \sqrt{\dfrac{1}{B-1}\sum_{b=1}^{B}\left(\hat\theta^{*}_b - \bar\theta^{*}\right)^2}

theta-hat*_b the statistic computed on the b-th resample of B total resamples; theta-bar* their mean.

Percentile interval

[θ^(α/2)∗, θ^(1−α/2)∗]\left[\hat\theta^{*}_{(\alpha/2)},\ \hat\theta^{*}_{(1-\alpha/2)}\right]

The alpha/2 and 1-alpha/2 quantiles of the bootstrap distribution directly, with no bias or skewness correction.

BCa interval endpoints

Φ ⁣(z^0+z^0+zα/21−a^ (z^0+zα/2))\Phi\!\left(\hat z_0 + \dfrac{\hat z_0 + z_{\alpha/2}}{1 - \hat a\,(\hat z_0 + z_{\alpha/2})}\right)

Phi the standard normal CDF; z0-hat the bias correction; a-hat the jackknife-estimated acceleration; quantile of the bootstrap distribution at that adjusted percentile.

Assumptions and checks

  • Independence of observations. Correlated rows (a time series, clustered data, repeated measures on the same unit) make ordinary case resampling treat dependent observations as if they were independent draws, so the reported interval is too narrow.

    In KernelStats: Not checked by KernelStats: the engine always performs ordinary (i.i.d.) case resampling; there is no block or cluster bootstrap option, so the dependence structure must be recognized by the analyst before trusting the interval.

  • With very few observations, every resampled dataset can only reuse the small set of values actually observed, which can make the bootstrap interval too narrow and overly optimistic about how precisely the statistic is known.

    In KernelStats: Checked directly: the card flags samples smaller than n = 20 with an 'Adequate sample size' warning.

  • The bootstrap describes the sampling variability of the exact sample supplied. A sample that is not representative of the population (selection bias, a skewed convenience sample) still produces a confident-looking interval that is simply centered on the wrong value.

    In KernelStats: Not checked by KernelStats: representativeness cannot be assessed from the sample alone; the card states this as a standing limitation.

  • When the BCa method's acceleration constant cannot be estimated (a boundary or degenerate statistic), silently using the plain percentile interval instead loses BCa's correction for bias and skewness, which can matter for small or skewed samples.

    In KernelStats: Checked directly: the card reports a 'BCa stability' warning whenever this fallback to the percentile method occurs, rather than presenting the fallback interval as if it were the requested BCa interval.

Alternatives

  • One-Sample t-Test. The statistic is a mean, the sample is reasonably large or not badly skewed, and a standard parametric interval is adequate: simpler and faster, with the same interpretation.
  • Wilcoxon Signed-Rank Test. You want a hypothesis test about central tendency under non-normality rather than a resampled confidence interval specifically.

Worked example

Scenario

A 95% BCa bootstrap interval for the median body mass of 68 Chinstrap penguins, using 9999 resamples with seed 42.

Result

Point estimate (median) = 3700 g, bootstrap SE = 58 g, 95% BCa CI [3575, 3800] g.

Interpretation

The median plausibly lies between about 3.58 kg and 3.80 kg; because the interval was built without assuming a normal shape for body mass, it is trustworthy even though the median (unlike the mean) has no simple textbook formula for its standard error.

Dataset: penguins.csv

Common misconceptions

Misconception

A 95% bootstrap confidence interval means there is a 95% probability the true value lies inside this particular interval.

Correction

The 95% describes the long-run behavior of the PROCEDURE: if you repeated the whole study and rebuilt the interval many times, about 95% of those intervals would contain the true value. This one interval either contains it or does not: the probability statement is about the method, not about this specific computed interval.

Read more: Misconception: a 95% CI means a 95% probability the true value is inside it

Misconception

Running more bootstrap resamples (e.g. 9999 instead of 999) fixes a sample that is too small or unrepresentative.

Correction

Resamples are drawn from the data you already have; more resamples make the estimate of the bootstrap distribution smoother and more precise, but they cannot add information the original sample never contained. A biased or tiny original sample yields a bootstrap interval that is a precise description of that same limited sample, not a bigger or better one.

Read more: Misconception: a larger sample size fixes a biased estimate

References

  1. An Introduction to the Bootstrap, Efron, B. and Tibshirani, R. J. (1993).
  2. Bootstrap Confidence Intervals, DiCiccio, T. J. and Efron, B. (1996), Statistical Science, 11(3), 189-228.