Techniqueadvanced
Subsampling
Also called m-out-of-n bootstrap, Politis-Romano subsampling.
Approximate the sampling distribution from statistics on subsamples of size m much smaller than n. It is consistent in cases where the bootstrap fails.
Subsampling estimates the sampling distribution of a statistic from its values on subsets of the data of size , drawn without replacement, with and . Each subset is a true sample of size from the unknown distribution , not from the empirical distribution, so the method needs only that the suitably scaled statistic has some limit law. It is consistent in cases where the bootstrap fails, such as the maximum of a uniform sample, the mean with infinite variance and many nonstandard estimators. The price is a loss of accuracy where the bootstrap works, and the need to know the rate of convergence and to choose . The m-out-of-n bootstrap is a related method that draws the values with replacement.
In plain words
You want to know how much a statistic computed from points would vary over new samples. You have only one sample. Take a smaller group of points from it, without repeats, and compute the statistic on that group. Do this for many groups. Each group really is a sample from the population, so the spread of these values shows how the statistic varies for samples of size . If you know how the spread shrinks as the sample grows, you can scale it down to size . The groups must be much smaller than the full sample. Otherwise they overlap too much and look too much like the full sample and like each other.
When it applies
- Data. Independent and identically distributed observations. For a stationary time series, use blocks of consecutive observations instead of arbitrary subsets.
- A limit law. There is a known rate such that converges in law to a continuous limit . The limit can be anything: it need not be normal, and it need not be known. For smooth statistics ; for the maximum of a uniform sample .
- Subsample size. , and .
Under these conditions Politis and Romano (1994) proved that the subsampling distribution converges to and that the subsampling intervals have asymptotic coverage . The proof uses only that a U-statistic of order concentrates when , so it needs much less than the bootstrap.
The template
Let be the distribution of the roots over subsets of size , where is the statistic on the subset. It estimates the law of , so its quantiles give the interval .
SUBSAMPLING-INTERVAL(x_1, ..., x_n, s, m, τ, α, b)- 1
θ̂ ← s(x_1, ..., x_n) - 2
for j ← 1 to b do - 3
S ← m distinct indices drawn uniformly from {1, ..., n} - 4
r_j ← τ(m) (s(x_S) - θ̂) - 5
sort r_1, ..., r_b - 6
c_lo ← r_(⌈b α/2⌉), c_hi ← r_(⌈b (1 - α/2)⌉) - 7
return [θ̂ - c_hi / τ(n), θ̂ - c_lo / τ(n)]
With all subsets in place of random ones, this is the exact subsampling distribution, and the implementation does that when it is called without . Random subsets add a Monte Carlo error that vanishes as grows, as for the bootstrap. Politis and Romano write for the subsample size; this page writes , to keep for the number of replicates as on the other resampling pages.
Subsampling and the m-out-of-n bootstrap. The m-out-of-n bootstrap of Bickel, Götze and van Zwet (1997) uses the same roots and the same scaling, but draws the values with replacement from the data. Its subsamples are samples from , not from , and contain repeated values. If , a with-replacement sample of size has no repeated index with probability tending to 1, and the two methods agree asymptotically. The m-out-of-n bootstrap can be used with larger than and for smoothing, while subsampling has a simpler theory and needs weaker conditions.
Classic examples
The maximum of a uniform sample. For uniform on , and is asymptotically exponential. The bootstrap fails: a resample contains with probability , so the bootstrap law of has an atom of size at 0, while the true limit is continuous. A random subset of size contains with probability . More precisely, its maximum is the -th smallest value with probability ; the tests check this law by listing all subsets.
For one sample of uniform values with (seed 31), , and the exact 95% upper confidence bound is . With (seed 1) the one-sided 95% bounds were for the bootstrap, whose roots were 0 in of the replicates, for subsampling with , and for the m-out-of-n bootstrap with .
Measured coverage. Over 1000 data sets with and (seed 41), the one-sided 95% bound covered in this fraction of cases:
| method | coverage | |
|---|---|---|
| bootstrap | 100 | 0.766 |
| m-out-of-n bootstrap | 10 | 0.891 |
| m-out-of-n bootstrap | 20 | 0.908 |
| subsampling | 10 | 0.885 |
| subsampling | 20 | 0.898 |
| subsampling | 50 | 0.764 |
With (400 data sets, seed 43), subsampling gave with and with , and the m-out-of-n bootstrap gave with . The bootstrap stays wrong for every ; subsampling approaches the nominal level slowly, and out of is too large. These are measurements, with a Monte Carlo standard error of about for 1000 data sets and for 400.
The variance of a mean, and the delete-d jackknife. For the mean, the variance of over all subsets of size is exactly , the finite population formula. The plain subsampling estimate of rescales it by and gives , which is right only when . The delete- jackknife with uses the same subsets but rescales by , which gives exactly for every . The tests check both identities with exact fractions.
Heavy tails. For the mean of a distribution with infinite variance in the domain of attraction of a stable law, the bootstrap distribution has a random limit (Athreya 1987), while subsampling with the right rate is consistent. If the rate is unknown, it can be estimated from the spread of subsampling distributions at several values of .
Dependent data. For a stationary series, the blocks of consecutive values are the subsamples. This needs fewer conditions than the block bootstrap, but is less accurate where both work.
Variations
- All subsets or random subsets. The full set of subsets gives a U-statistic of order ; random subsets or a balanced design give the same limit at a cost of evaluations.
- Symmetric and studentized roots. Using gives symmetric intervals. Dividing each root by a standard error computed on the subset removes the need for when the statistic is studentized.
- Estimated rate. When with unknown , compare the spread of the subsampling distributions for two or more values of to estimate (Politis, Romano and Wolf 1999).
- Choice of m. Calibration by a second level of subsampling, or the minimum volatility rule, which picks the where the interval endpoints change least with .
- Extrapolation. Combining several values of can reduce the bias of order that the table shows.
- Hypothesis tests. The quantiles of the subsampling distribution of a test statistic, computed under the null or centred at the estimate, give tests with asymptotically correct level.
Pitfalls
- m too large. With not small, the subsets overlap heavily and look like the full sample. In the table, of covered only .
- m too small. With very small , the statistic on the subset is far from its limit law. A rule of thumb is to try several and look for a range where the answer is stable.
- The wrong rate. The method rescales by . A wrong rate gives intervals of the wrong length, even asymptotically.
- Centring at the estimate. The roots are centred at , not at . This adds an error of order , which is the main reason for the slow convergence in the table.
- Using it where the bootstrap works. For smooth statistics such as a mean or a correlation, the bootstrap, especially the BCa interval, is more accurate. Subsampling is the tool for cases where the bootstrap fails.
Code
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/subsampling-inference/. The authors are listed in prov/HBQCGG.jsonl.
import itertools
import math
import random
from fractions import Fraction
from typing import Callable, Sequence
Statistic = Callable[[Sequence[float]], float]
Rate = Callable[[int], float]
def empirical_quantile(sorted_values: Sequence[float], p: float) -> float:
"""inf{t : L(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 subsample_roots(
x: Sequence[float],
statistic: Statistic,
m: int,
tau: Rate,
b: int | None = None,
rng: random.Random | None = None,
) -> list:
"""The sorted roots tau(m) (theta_hat_S - theta_hat) over subsets S of size m drawn without
replacement. b=None lists all C(n, m) subsets; otherwise b subsets are drawn at random."""
n = len(x)
if not 1 <= m < n:
raise ValueError("need 1 <= m < n")
theta_hat = statistic(x) # @line L1
if b is None:
subsets = itertools.combinations(range(n), m)
else:
subsets = (rng.sample(range(n), m) for _ in range(b)) # @line L3
roots = []
for idx in subsets: # @line L2
roots.append(tau(m) * (statistic([x[i] for i in idx]) - theta_hat)) # @line L4
roots.sort() # @line L5
return roots
def subsampling_interval(
x: Sequence[float],
statistic: Statistic,
m: int,
tau: Rate,
alpha: float,
b: int | None = None,
rng: random.Random | None = None,
) -> tuple:
"""The equal-tailed 1 - alpha subsampling interval
[theta_hat - c_(1 - alpha/2)/tau(n), theta_hat - c_(alpha/2)/tau(n)]."""
if not 0 < alpha < 1:
raise ValueError("alpha must be in (0, 1)")
roots = subsample_roots(x, statistic, m, tau, b, rng)
c_lo = empirical_quantile(roots, alpha / 2) # @line L6
c_hi = empirical_quantile(roots, 1 - alpha / 2)
theta_hat, n = statistic(x), len(x)
return theta_hat - c_hi / tau(n), theta_hat - c_lo / tau(n) # @line L7
def subsampling_variance(x: Sequence, statistic: Statistic, m: int):
"""The variance of the statistic over all C(n, m) subsets, exactly (small n only)."""
values = [statistic([x[i] for i in idx]) for idx in itertools.combinations(range(len(x)), m)]
mean = sum(values[1:], values[0]) / len(values)
return sum(((v - mean) ** 2 for v in values[1:]), (values[0] - mean) ** 2) / len(values)
def m_out_of_n_roots(
x: Sequence[float], statistic: Statistic, m: int, tau: Rate, b: int, rng: random.Random
) -> list:
"""The m-out-of-n bootstrap: the same roots, but each subsample is m draws WITH replacement."""
n = len(x)
theta_hat = statistic(x)
roots = [tau(m) * (statistic([x[rng.randrange(n)] for _ in range(m)]) - theta_hat) for _ in range(b)]
roots.sort()
return roots
def max_at_rank_probability(n: int, m: int, k: int) -> Fraction:
"""P(the maximum of a uniform random m-subset is the k-th smallest of n distinct values)."""
return Fraction(math.comb(k - 1, m - 1), math.comb(n, m))
def resample_hits_maximum(n: int, m: int) -> Fraction:
"""P(a with-replacement resample of size m contains the largest of n distinct values)."""
return 1 - Fraction(n - 1, n) ** m
test_subsampling_inference.py 102 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/subsampling-inference/. The authors are listed in prov/HBQCGG.jsonl.
import itertools
import math
import random
from fractions import Fraction
import pytest
from subsampling_inference import (
empirical_quantile,
m_out_of_n_roots,
max_at_rank_probability,
resample_hits_maximum,
subsample_roots,
subsampling_interval,
subsampling_variance,
)
def fr_mean(xs):
return sum(xs, Fraction(0)) / len(xs)
def sample_variance(xs):
m = fr_mean(xs)
return sum((v - m) ** 2 for v in xs) / (len(xs) - 1)
def test_law_of_the_subset_maximum():
rng = random.Random(1)
for n in range(2, 9):
x = rng.sample(range(100), n)
order = sorted(x)
for m in range(1, n):
roots = subsample_roots(x, max, m, lambda k: 1)
counts = {v: roots.count(v - order[-1]) for v in order}
total = math.comb(n, m)
for k, v in enumerate(order, start=1):
assert Fraction(counts[v], total) == max_at_rank_probability(n, m, k)
def test_variance_of_subset_means():
rng = random.Random(2)
for n in range(3, 9):
x = [Fraction(rng.randint(-30, 30), rng.randint(1, 5)) for _ in range(n)]
s2 = sample_variance(x)
for m in range(1, n):
v = subsampling_variance(x, fr_mean, m)
assert v == s2 / m * (1 - Fraction(m, n))
# Rescaled by m/(n - m), as in the delete-d jackknife with d = n - m, it is exactly S^2/n;
# rescaled by m/n, the plain subsampling estimate, it keeps the factor 1 - m/n.
assert Fraction(m, n - m) * v == s2 / n
assert Fraction(m, n) * v == s2 / n * (1 - Fraction(m, n))
def test_bootstrap_atom_at_the_maximum():
for n in (5, 10, 100, 1000):
p = resample_hits_maximum(n, n)
# by enumeration for small n
if n == 5:
hits = sum(1 for idx in itertools.product(range(5), repeat=5) if 4 in idx)
assert p == Fraction(hits, 5**5)
assert abs(float(p) - (1 - math.exp(-1))) < 0.1
# m-out-of-n with m/n -> 0 removes the atom
assert float(resample_hits_maximum(10_000, 100)) < 0.01
def uniform_coverage(method, n, m, r, b, seed):
rng = random.Random(seed)
hits = 0
for _ in range(r):
x = [rng.random() for _ in range(n)]
if method == "subsampling":
roots = subsample_roots(x, max, m, float, b, rng)
else:
roots = m_out_of_n_roots(x, max, m, float, b, rng)
c = empirical_quantile(roots, 0.05)
upper = max(x) - c / n # one-sided 95% upper bound for theta = 1
hits += upper >= 1.0
return hits / r
def test_coverage_for_the_uniform_maximum_is_measured():
r, alpha = 300, 0.05
tol = 4 * math.sqrt(alpha * (1 - alpha) / r)
cov = uniform_coverage("subsampling", 200, 15, r, 200, 3)
assert abs(cov - 0.95) <= tol + 0.05
cov = uniform_coverage("m-out-of-n", 200, 15, r, 200, 4)
assert abs(cov - 0.95) <= tol + 0.05
def test_interval_on_the_mean_and_errors():
rng = random.Random(5)
x = [rng.gauss(10.0, 2.0) for _ in range(60)]
lo, hi = subsampling_interval(x, lambda v: math.fsum(v) / len(v), 12, math.sqrt, 0.1, 1000, rng)
assert lo < 10.0 < hi
with pytest.raises(ValueError):
subsample_roots(x, max, 60, float)
with pytest.raises(ValueError):
subsampling_interval(x, max, 5, float, 1.0, 10, rng)
Exercises
- Show that a uniform random subset of size from distinct values has its maximum at the -th smallest value with probability , and that the probability that it contains the overall maximum is .
- Show that the variance of over all subsets of size is . Then show that the delete- jackknife with gives for every .
- Compute the probability that a with-replacement sample of size from indices has no repeated index, and show that it tends to 1 when . Explain why the m-out-of-n bootstrap and subsampling then agree.
- For the uniform maximum, find the limit of for the bootstrap and for the m-out-of-n bootstrap with .
- Run the implementation on the median of normal values with and several values of , and compare the intervals with the bootstrap percentile interval.
References
- Dimitris N. Politis and Joseph P. Romano, Large sample confidence regions based on subsamples under minimal assumptions, The Annals of Statistics 22(4), 1994, pp. 2031 to 2050 (subsampling for iid and stationary data, consistency when b/n tends to 0 and a limit law exists)
- Dimitris N. Politis, Joseph P. Romano and Michael Wolf, Subsampling, Springer, 1999, Chapter 2 (subsampling for iid data) and the chapters on dependent data and on estimating the rate of convergence (general locator)
- E. L. Lehmann and Joseph P. Romano, Testing Statistical Hypotheses, 3rd edition, Springer, 2005, Section 15.7 (subsampling, and comparison with the bootstrap)
- P. J. Bickel, F. Götze and W. R. van Zwet, Resampling fewer than n observations, 1997, pp. 1 to 31 (the m-out-of-n bootstrap with replacement and its relation to subsampling without replacement)
- Peter J. Bickel and David A. Freedman, Some asymptotic theory for the bootstrap, The Annals of Statistics 9(6), 1981, pp. 1196 to 1217 (the bootstrap fails for the sample maximum of a uniform sample)
- Jun Shao and C. F. J. Wu, A general theory for jackknife variance estimation, The Annals of Statistics 17(3), 1989, pp. 1176 to 1197 (the delete-d jackknife, which uses the same subsets)
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 | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag HBQCGG Edit this page History Report an error Markdown