Algorithmadvanced
BCa bootstrap interval
Also called bias-corrected and accelerated interval, BCa interval.
Efron's bootstrap interval that shifts the percentiles by a bias correction and an acceleration from the jackknife. It is second-order accurate.
- Time
- Θ(b n + n^2 + b log b) worstΘ(b n + n^2) best
- Space
- Θ(b + n) extra
- Where
- b = the number of bootstrap replicates; n = the sample size
- Model
- Real RAM
- Properties
- randomizednot exactofflinerandomizediterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Bradley Efron, 1987
The BCa (bias-corrected and accelerated) interval is a percentile interval taken at adjusted levels. Instead of the and quantiles of the bootstrap replicates, it uses the levels and computed from a bias correction , measured by the fraction of replicates below the estimate, and an acceleration , measured by the skewness of the jackknife values. It keeps the simplicity and the range of the percentile interval, it respects monotone transformations when is fixed, and Hall (1988) showed that its one-sided coverage error is of order . That accuracy is asymptotic: the coverages on this page are measured, not proved.
In plain words
The percentile interval cuts off the same share of bootstrap values at each end. That is right only when the bootstrap values are centred on the estimate and spread out the same way on both sides. The BCa interval checks two things. First, are more than half of the bootstrap values below the estimate? If so, the bootstrap distribution sits too low, and both cut points move up. Second, does the spread of the estimate grow with its size, which shows as skewness when you leave out one data point at a time? If so, the cut points move further toward the long tail. The result is still two of the sorted bootstrap values, chosen with more care.
The problem
Input. A sample , independent and identically distributed from an unknown ; a statistic with , which estimates ; a level ; and a number of replicates .
Output. An interval that should contain with probability close to .
Definition. Let be the bootstrap distribution function of , the standard normal distribution function and . With
where , is the estimate without and is their mean, the adjusted levels are
and the BCa interval is . With and the levels are and , and it is the percentile interval.
The algorithm
BCA-INTERVAL(x_1, ..., x_n, s, α, b)- 1
θ̂ ← s(x_1, ..., x_n) - 2
for j ← 1 to b do - 3
x* ← n independent draws from x_1 .. x_n, each with probability 1/n - 4
θ*_j ← s(x*) - 5
sort the θ*_j; c ← #{j : θ*_j < θ̂} - 6
z_0 ← Φ⁻¹(c / b) - 7
a ← Σ d_i³ / (6 (Σ d_i²)^{3/2}) with d_i = θ̂_(·) - θ̂_(i), from the n leave-one-out estimates - 8
α_1, α_2 ← Φ(z_0 + (z_0 + z)/(1 - a (z_0 + z))) for z = z_{α/2} and z = z_{1-α/2} - 9
return [θ*_(⌈b α_1⌉), θ*_(⌈b α_2⌉)]
Line L6 needs ; if every replicate lies on one side of , is infinite and the implementation raises an error. Line L8 needs ; otherwise the formula breaks down and the implementation raises an error. Line L9 uses the quantile rule of the percentile interval, . The implementation also accepts a fixed value of in place of line L7.
Example
Take the right-skewed sample of values
with , the statistic the mean, , and random.Random(1).
- Lines L2 to L5: 1087 of the 2000 replicates are below 3.83, so . The bootstrap distribution of the mean has its median below , because the distribution is skewed to the right.
- Line L7: for the mean, , so is the plug-in skewness divided by . Here the skewness is and .
- Line L8: and .
- Line L9: and . The 132nd and the 1991st smallest replicates are 2.18 and 6.97.
So the interval is . Both levels moved up from and , and the interval moved right of the percentile interval . With (the bias-corrected interval) the same replicates give . The bootstrap-t interval is and the t interval .
Transformation. With fixed, the BCa interval for is the log of the interval for ; the tests check this exactly. With the jackknife estimate of , it is not: on the log scale, line L7 gives instead of , and the interval, transformed back, is . The value is the same on both scales.
Measured coverage. For samples from the exponential law with mean 1, 1000 data sets of each size with (seeds 101 and 102) gave these coverages for the true mean at the nominal level 0.95:
| method | ||
|---|---|---|
| BCa | 0.884 | 0.916 |
| percentile | 0.869 | 0.911 |
| bootstrap-t | 0.943 | 0.950 |
| t interval | 0.911 | 0.924 |
The study used the formula , which is the jackknife value for the mean. The BCa interval improves on the percentile interval and is better balanced than the t interval, with misses of below and above at . But for the mean of a small skewed sample it is still too short, because the bootstrap distribution of the mean has the plug-in variance and normal-like tails. Second-order accuracy is a statement about large . The Monte Carlo standard error of each coverage is about .
Correctness
The proof is in proofs/correctness.md. What is proved:
- Lines L5 to L9 compute the stated formulas, and with the algorithm is the percentile interval.
- does not change under a strictly increasing transformation of the statistic. With fixed, the interval respects such transformations. The jackknife value of does change, so the full algorithm respects them only approximately.
- In Efron's transformation model, where an increasing makes with standard normal, and the bootstrap follows the same model, the ideal BCa interval with the true and has coverage , exactly when and up to an error below otherwise.
What is not proved: the coverage for a general . Hall (1988) shows by Edgeworth expansions that the one-sided coverage error is under smoothness conditions; the table above is a measurement.
Proof: The BCa interval computes Efron's adjusted percentiles and is exact in his transformation modelfull
We use the pseudocode and the notation of the page. is the bootstrap distribution function of , the empirical distribution function of the replicates, the standard normal distribution function and . For any distribution function , .
This file proves what the algorithm computes, two invariance facts, and exact coverage in an idealized model. It does not prove a coverage level for a general ; that coverage is measured on the page.
Claim 1 (the algorithm computes the formulas). Line L6 sets , where is the fraction of replicates below . Line L9 returns . If and , then and , and the result is the percentile interval computed from the same replicates.
Proof. The first statement is the definition of . For the second, because they are values of , and the quantile rule of the percentile interval (its Claim 1) shows that for . For the third, put in line L8: and .
Claim 2 (z0 is invariant). Let be strictly increasing on a set that contains every value of . If the algorithm runs on the statistic with the same random numbers, line L6 gives the same .
Proof. Lines L2 to L4 draw the indices without looking at the statistic, so the replicates of the second run are , and its estimate is . Since is strictly increasing, exactly when , so is the same.
Claim 3 (transformation respecting for a fixed a). Under the conditions of Claim 2, and with the same fixed value of in both runs, if the first run returns the second returns .
Proof. By Claim 2, is the same, and and are the same, so line L8 gives the same and , and line L9 uses the same ranks and . A strictly increasing keeps the order of the replicates, so the replicate of each rank in the second run is of the replicate of that rank in the first run.
The jackknife value of line L7 is a function of the leave-one-out estimates , and changes their spacings: is not the mean of the , and the skewness of the differences changes. So the full algorithm respects transformations only approximately. On the page, is for the mean and for the log of the mean. The tests check both facts: exact equality with a fixed , and a different jackknife after the logarithm.
Claim 4 (exact coverage in the transformation model). Suppose there are numbers and and a strictly increasing bijection from the parameter range onto such that, with , and standard normal,
and the bootstrap follows the same model with in place of : with standard normal under . Let be the event , and suppose for and . Then on the ideal interval is defined, and
If , is the whole space and the coverage is exactly .
Proof. From the model, , which is positive exactly on . On the bootstrap law is
which is continuous and strictly increasing with range . In particular , so the ideal value of line L6 is the true .
Fix , let and , which is or . Solving gives the endpoint with
Now compare with , which is the same as comparing with .
- If : is the same as . Divide by and multiply by : this is , that is , that is .
- If : is the same as , which by the same steps is , that is again .
- If : , so is .
So on , exactly when , and exactly when . The coverage event therefore agrees on with the event , which has probability . Two events that agree on differ in probability by at most .
For , , and for it is ; both are at most . With the values of the page, and , this is , which is below . The model needs the exception because a normal is unbounded while must stay positive.
The method does not need to know ; it uses only , and . The two inputs are the two departures from Claim 4 of the percentile interval: allows a median bias on the normalized scale, and lets the standard deviation change with the parameter.
What is not proved. For a real , the transformation model holds only approximately, the jackknife value of is an estimate, and the bootstrap law is discrete. Efron (1987) and Hall (1988) show under smoothness conditions that the one-sided coverage error is . This file does not reproduce those expansions. The coverages on the page come from a simulation with stated seeds, with a Monte Carlo standard error of about .
Cost. Lines L2 to L4 cost , where is the cost of . Line L5 sorts and counts in . Line L7 evaluates on samples of size , which costs , that is for a linear-time statistic. Lines L6, L8 and L9 take constant time. The extra space is .
Complexity
The replicates cost for the mean, the sort costs , and the counting of line L5 costs . Line L7 computes leave-one-out estimates; done naively for a statistic that costs , this is , and for the mean it can be done in by subtracting each value from the total. Two selections at the levels and can replace the sort. The extra space is .
Properties
- Second-order accurate. For smooth statistics, the one-sided coverage error is , and the endpoints agree with those of the bootstrap-t interval up to terms of order (Hall 1988).
- Transformation respecting for a fixed , and approximately so with the jackknife , as the example shows.
- Range preserving. The endpoints are replicate values, as in the percentile interval.
- No standard error needed. Unlike the bootstrap-t interval, it needs only the statistic itself and its leave-one-out values.
- More replicates. The adjusted levels can be far in the tails, as in the example, so should be at least 1000, and better 2000 or more.
Variants and improvements
- Bias-corrected (BC) interval. Efron's earlier method sets . It corrects the median bias but not the change of the standard error with , and it is only first-order accurate.
- Acceleration from influence values. In place of the jackknife, can be computed from the empirical influence function values as . For the mean both give .
- Parametric BCa. With a parametric bootstrap, is computed from the score function of the model instead of the jackknife.
- ABC interval. DiCiccio and Efron's approximate bootstrap confidence interval replaces the resampling by a few numerical derivatives of the statistic. It gives nearly the same endpoints for smooth statistics, without Monte Carlo error.
- Iterated bootstrap calibration. A second level of bootstrap estimates the actual coverage and adjusts the nominal level. It also gives second-order or better accuracy, at the cost of evaluations.
When to use it
Use it as the default bootstrap interval for a smooth statistic without a reliable standard error formula, such as a correlation, a ratio or a quantile of moderate order, when is moderate or large. It needs only the statistic, which you must already compute. For a mean or a regression coefficient in a small skewed sample, the bootstrap-t interval covered better in the study above. For a statistic that is not smooth, such as an extreme order statistic, neither method is valid, and subsampling is the safer tool.
Pitfalls
- Ties at the estimate. Counting replicates with instead of changes when many replicates equal , as for a median. Some software splits the ties in half; state the rule.
- Extreme levels. If or is large, or can be very close to 0 or 1, and the endpoint is then an extreme replicate with a large Monte Carlo error. If , the formula is not defined.
- Wrong sign of . The jackknife differences are . The reversed sign gives an acceleration with the wrong sign, which moves the interval the wrong way.
- Small samples. The interval inherits the narrowness of the bootstrap distribution. Second-order accuracy does not mean good coverage at .
- Statistics where the bootstrap fails. The correction cannot repair an inconsistent bootstrap, for example for the sample maximum.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bca-bootstrap-interval/. The authors are listed in prov/HRG7H4.jsonl.
import math
import random
from fractions import Fraction
from statistics import NormalDist
from typing import Callable, Sequence
Statistic = Callable[[Sequence[float]], float]
STD_NORMAL = NormalDist()
def empirical_quantile(sorted_values: Sequence[float], p: float) -> float:
"""inf{t : G(t) >= p}: the ceil(b p)-th smallest value, or the smallest for p = 0."""
k = max(1, math.ceil(Fraction(p) * len(sorted_values)))
return sorted_values[k - 1]
def jackknife_acceleration(x: Sequence[float], statistic: Statistic) -> float:
"""a = sum d_i^3 / (6 (sum d_i^2)^(3/2)) with d_i = theta_(.) - theta_(i)."""
n = len(x)
loo = [statistic(list(x[:i]) + list(x[i + 1 :])) for i in range(n)]
dot = math.fsum(loo) / n
d = [dot - t for t in loo]
s2 = math.fsum(v * v for v in d)
if s2 == 0:
return 0.0
return math.fsum(v**3 for v in d) / (6.0 * s2**1.5)
def bca_levels(z0: float, a: float, alpha: float) -> tuple:
"""The adjusted levels alpha_1 and alpha_2 of Efron (1987)."""
out = []
for z in (STD_NORMAL.inv_cdf(alpha / 2), STD_NORMAL.inv_cdf(1 - alpha / 2)):
w = z0 + z
denom = 1 - a * w
if denom <= 0:
raise ValueError("the acceleration is too large for this level")
out.append(STD_NORMAL.cdf(z0 + w / denom))
return out[0], out[1]
def bca_interval(
x: Sequence[float],
statistic: Statistic,
alpha: float,
b: int,
rng: random.Random,
acceleration: float | None = None,
) -> tuple:
"""The 1 - alpha BCa interval [G^{-1}(alpha_1), G^{-1}(alpha_2)].
acceleration=None estimates a by the jackknife; a number fixes it.
Returns (lo, hi, z0, a).
"""
if not 0 < alpha < 1:
raise ValueError("alpha must be in (0, 1)")
n = len(x)
if n < 2 or b < 1:
raise ValueError("need n >= 2 and b >= 1")
theta_hat = statistic(x) # @line L1
reps = []
for _ in range(b): # @line L2
xs = [x[rng.randrange(n)] for _ in range(n)] # @line L3
reps.append(statistic(xs)) # @line L4
reps.sort()
below = sum(1 for t in reps if t < theta_hat) # @line L5
if below == 0 or below == b:
raise ValueError("all replicates lie on one side of the estimate; z0 is infinite")
z0 = STD_NORMAL.inv_cdf(below / b) # @line L6
a = jackknife_acceleration(x, statistic) if acceleration is None else acceleration # @line L7
a1, a2 = bca_levels(z0, a, alpha) # @line L8
return empirical_quantile(reps, a1), empirical_quantile(reps, a2), z0, a # @line L9
test_bca_bootstrap_interval.py 91 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bca-bootstrap-interval/. The authors are listed in prov/HRG7H4.jsonl.
import math
import random
import statistics
from statistics import NormalDist
import pytest
from bca_bootstrap_interval import bca_interval, bca_levels, empirical_quantile, jackknife_acceleration
SKEWED = [0.4, 0.9, 1.3, 1.6, 2.2, 2.8, 3.5, 4.9, 7.6, 13.1]
def fmean(xs):
return math.fsum(xs) / len(xs)
def test_acceleration_of_the_mean_is_skewness_over_6_root_n():
rng = random.Random(1)
for n in (3, 5, 10, 40):
x = [rng.expovariate(1.0) for _ in range(n)]
m = fmean(x)
m2 = math.fsum((v - m) ** 2 for v in x) / n
m3 = math.fsum((v - m) ** 3 for v in x) / n
skew = m3 / m2**1.5
assert math.isclose(jackknife_acceleration(x, fmean), skew / (6 * math.sqrt(n)), rel_tol=1e-9)
def test_acceleration_by_definition():
"""Leave-one-out values computed by hand for a tiny sample."""
x = [1.0, 2.0, 6.0]
loo = [4.0, 3.5, 1.5] # means without 1, without 2, without 6
dot = sum(loo) / 3
d = [dot - t for t in loo]
a = sum(v**3 for v in d) / (6 * sum(v * v for v in d) ** 1.5)
assert math.isclose(jackknife_acceleration(x, fmean), a, rel_tol=1e-12)
def test_levels_reduce_to_percentile():
a1, a2 = bca_levels(0.0, 0.0, 0.1)
assert math.isclose(a1, 0.05, rel_tol=1e-12) and math.isclose(a2, 0.95, rel_tol=1e-12)
a1, a2 = bca_levels(0.2, 0.05, 0.1)
z = NormalDist().inv_cdf(0.05)
assert math.isclose(a1, NormalDist().cdf(0.2 + (0.2 + z) / (1 - 0.05 * (0.2 + z))), rel_tol=1e-12)
assert a1 > 0.05 and a2 > 0.95 # a positive bias correction moves both levels up
def test_transformation_respecting_for_fixed_acceleration():
lo, hi, z0, a = bca_interval(SKEWED, fmean, 0.1, 999, random.Random(4), acceleration=0.05)
llo, lhi, lz0, _ = bca_interval(SKEWED, lambda xs: math.log(fmean(xs)), 0.1, 999, random.Random(4), acceleration=0.05)
assert lz0 == z0
assert llo == math.log(lo) and lhi == math.log(hi)
# The jackknife estimate of a is not invariant: it changes under the log.
a_mean = jackknife_acceleration(SKEWED, fmean)
a_log = jackknife_acceleration(SKEWED, lambda xs: math.log(fmean(xs)))
assert abs(a_mean - a_log) > 0.005
def test_infinite_bias_correction_is_an_error():
with pytest.raises(ValueError):
bca_interval(SKEWED, min, 0.1, 200, random.Random(1))
def test_page_example():
lo, hi, z0, a = bca_interval(SKEWED, fmean, 0.05, 2000, random.Random(1))
m = fmean(SKEWED)
assert lo < m < hi
assert z0 > 0 and a > 0 # right skew: more replicates below the mean, positive acceleration
def test_coverage_is_measured_not_proved():
rng = random.Random(9)
r, b, alpha = 300, 300, 0.05
hits = 0
for _ in range(r):
x = [rng.expovariate(1.0) for _ in range(20)]
lo, hi, _, _ = bca_interval(x, fmean, alpha, b, rng)
hits += lo <= 1.0 <= hi
cov = hits / r
assert abs(cov - (1 - alpha)) <= 4 * math.sqrt(alpha * (1 - alpha) / r) + 0.04
def test_quantile_and_errors():
assert empirical_quantile([1.0, 2.0, 3.0], 0.34) == 2.0
assert empirical_quantile([1.0, 2.0, 3.0], 0.33) == 1.0
with pytest.raises(ValueError):
bca_interval([1.0], fmean, 0.1, 10, random.Random(1))
with pytest.raises(ValueError):
bca_interval(SKEWED, fmean, 0.0, 10, random.Random(1))
History
Bradley Efron proposed the percentile interval with the bootstrap and, in 1981 and 1982, the bias-corrected interval, which adds . In Better bootstrap confidence intervals (JASA, 1987) he added the acceleration , derived the interval from a transformation model in which the standard deviation of the normalized estimate changes linearly with the parameter, and gave the jackknife estimate of . Peter Hall's 1988 paper, which used Edgeworth expansions, showed that BCa and the bootstrap-t interval are both second-order accurate, while the percentile and BC intervals are first-order accurate. DiCiccio and Efron later developed the ABC approximation and reviewed the methods.
References
- Bradley Efron, Better bootstrap confidence intervals, Journal of the American Statistical Association 82(397), 1987, pp. 171 to 185 (the BCa method, the transformation model with bias z0 and acceleration a, and the jackknife estimate of a)
- Bradley Efron and Robert J. Tibshirani, An Introduction to the Bootstrap, Chapman and Hall, 1993, Chapter 14 (better bootstrap confidence intervals, the BCa method and its formulas) and Chapter 22 (justification of the method)
- Peter Hall, Theoretical comparison of bootstrap confidence intervals, The Annals of Statistics 16(3), 1988, pp. 927 to 953 (the BCa interval is second-order accurate and second-order correct)
- A. C. Davison and D. V. Hinkley, Bootstrap Methods and their Application, Cambridge University Press, 1997, Chapter 5 (the adjusted percentile method, BCa, and its estimate of a by empirical influence values)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag HRG7H4 Edit this page History Report an error Markdown