Algorithm Search⌘K

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 mm, drawn without replacement, with m→∞m \to \infty and m/n→0m/n \to 0. Each subset is a true sample of size mm from the unknown distribution FF, 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 mm. The m-out-of-n bootstrap is a related method that draws the mm values with replacement.

In plain words

You want to know how much a statistic computed from nn points would vary over new samples. You have only one sample. Take a smaller group of mm 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 mm. If you know how the spread shrinks as the sample grows, you can scale it down to size nn. 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 mm consecutive observations instead of arbitrary subsets.
  • A limit law. There is a known rate τn\tau_n such that τn(θ^n−θ)\tau_n(\hat\theta_n - \theta) converges in law to a continuous limit JJ. The limit can be anything: it need not be normal, and it need not be known. For smooth statistics τn=n\tau_n = \sqrt n; for the maximum of a uniform sample τn=n\tau_n = n.
  • Subsample size. m→∞m \to \infty, m/n→0m/n \to 0 and τm/τn→0\tau_m/\tau_n \to 0.

Under these conditions Politis and Romano (1994) proved that the subsampling distribution converges to JJ and that the subsampling intervals have asymptotic coverage 1−α1 - \alpha. The proof uses only that a U-statistic of order mm concentrates when m/n→0m/n \to 0, so it needs much less than the bootstrap.

The template

Let Ln,mL_{n,m} be the distribution of the roots τm(θ^m,S−θ^n)\tau_m(\hat\theta_{m,S} - \hat\theta_n) over subsets SS of size mm, where θ^m,S\hat\theta_{m,S} is the statistic on the subset. It estimates the law of τn(θ^n−θ)\tau_n(\hat\theta_n - \theta), so its quantiles cpc_p give the interval [θ^n−c1−α/2/τn, θ^n−cα/2/τn][\hat\theta_n - c_{1-\alpha/2}/\tau_n,\ \hat\theta_n - c_{\alpha/2}/\tau_n].

  1. SUBSAMPLING-INTERVAL(x_1, ..., x_n, s, m, τ, α, b)
  2. 1θ̂ ← s(x_1, ..., x_n)
  3. 2for j ← 1 to b do
  4. 3S ← m distinct indices drawn uniformly from {1, ..., n}
  5. 4r_j ← τ(m) (s(x_S) - θ̂)
  6. 5sort r_1, ..., r_b
  7. 6c_lo ← r_(⌈b α/2⌉), c_hi ← r_(⌈b (1 - α/2)⌉)
  8. 7return [θ̂ - c_hi / τ(n), θ̂ - c_lo / τ(n)]

With all (nm)\binom nm subsets in place of bb random ones, this is the exact subsampling distribution, and the implementation does that when it is called without bb. Random subsets add a Monte Carlo error that vanishes as bb grows, as for the bootstrap. Politis and Romano write bb for the subsample size; this page writes mm, to keep bb 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 mm values with replacement from the data. Its subsamples are samples from F^n\hat F_n, not from FF, and contain repeated values. If m2/n→0m^2/n \to 0, a with-replacement sample of size mm 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 mm larger than nn and for smoothing, while subsampling has a simpler theory and needs weaker conditions.

Classic examples

The maximum of a uniform sample. For XiX_i uniform on (0,θ)(0, \theta), θ^=X(n)\hat\theta = X_{(n)} and n(θ−X(n))/θn(\theta - X_{(n)})/\theta is asymptotically exponential. The bootstrap fails: a resample contains X(n)X_{(n)} with probability 1−(1−1/n)n→1−e−1=0.6321 - (1 - 1/n)^n \to 1 - e^{-1} = 0.632, so the bootstrap law of n(X(n)∗−X(n))n(X^*_{(n)} - X_{(n)}) has an atom of size 0.6320.632 at 0, while the true limit is continuous. A random subset of size mm contains X(n)X_{(n)} with probability m/n→0m/n \to 0. More precisely, its maximum is the kk-th smallest value with probability (k−1m−1)/(nm)\binom{k-1}{m-1}/\binom nm; the tests check this law by listing all subsets.

For one sample of n=100n = 100 uniform values with θ=1\theta = 1 (seed 31), X(n)=0.9963X_{(n)} = 0.9963, and the exact 95% upper confidence bound is X(n)/0.051/n=1.0266X_{(n)}/0.05^{1/n} = 1.0266. With b=2000b = 2000 (seed 1) the one-sided 95% bounds X(n)−c0.05/nX_{(n)} - c_{0.05}/n were 1.00371.0037 for the bootstrap, whose roots were 0 in 63.8%63.8\% of the replicates, 1.01921.0192 for subsampling with m=10m = 10, and 1.02191.0219 for the m-out-of-n bootstrap with m=10m = 10.

Measured coverage. Over 1000 data sets with n=100n = 100 and b=500b = 500 (seed 41), the one-sided 95% bound covered θ\theta in this fraction of cases:

method mm 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 n=1000n = 1000 (400 data sets, seed 43), subsampling gave 0.9580.958 with m=30m = 30 and 0.9500.950 with m=100m = 100, and the m-out-of-n bootstrap gave 0.9200.920 with m=30m = 30. The bootstrap stays wrong for every nn; subsampling approaches the nominal level slowly, and m=50m = 50 out of 100100 is too large. These are measurements, with a Monte Carlo standard error of about 0.0070.007 for 1000 data sets and 0.0110.011 for 400.

The variance of a mean, and the delete-d jackknife. For the mean, the variance of xˉS\bar x_S over all subsets of size mm is exactly S2m(1−mn)\frac{S^2}{m}(1 - \frac mn), the finite population formula. The plain subsampling estimate of Var(xˉ)\mathrm{Var}(\bar x) rescales it by τm2/τn2=m/n\tau_m^2/\tau_n^2 = m/n and gives S2n(1−mn)\frac{S^2}{n}(1 - \frac mn), which is right only when m/n→0m/n \to 0. The delete-dd jackknife with d=n−md = n - m uses the same subsets but rescales by mn−m\frac{m}{n - m}, which gives exactly S2/nS^2/n for every mm. 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 mm.

Dependent data. For a stationary series, the n−m+1n - m + 1 blocks of mm 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 (nm)\binom nm subsets gives a U-statistic of order mm; random subsets or a balanced design give the same limit at a cost of bb evaluations.
  • Symmetric and studentized roots. Using τm∣θ^m,S−θ^n∣\tau_m\lvert\hat\theta_{m,S} - \hat\theta_n\rvert gives symmetric intervals. Dividing each root by a standard error computed on the subset removes the need for τ\tau when the statistic is studentized.
  • Estimated rate. When τn=nβ\tau_n = n^\beta with unknown β\beta, compare the spread of the subsampling distributions for two or more values of mm to estimate β\beta (Politis, Romano and Wolf 1999).
  • Choice of m. Calibration by a second level of subsampling, or the minimum volatility rule, which picks the mm where the interval endpoints change least with mm.
  • Extrapolation. Combining several values of mm can reduce the bias of order m/nm/n 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 m/nm/n not small, the subsets overlap heavily and look like the full sample. In the table, m=50m = 50 of n=100n = 100 covered only 76%76\%.
  • m too small. With very small mm, the statistic on the subset is far from its limit law. A rule of thumb is to try several mm and look for a range where the answer is stable.
  • The wrong rate. The method rescales by τm/τn\tau_m/\tau_n. A wrong rate gives intervals of the wrong length, even asymptotically.
  • Centring at the estimate. The roots are centred at θ^n\hat\theta_n, not at θ\theta. This adds an error of order τm/τn\tau_m/\tau_n, 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.

subsampling_inference.pyI0RawGitHub
# 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

  1. Show that a uniform random subset of size mm from nn distinct values has its maximum at the kk-th smallest value with probability (k−1m−1)/(nm)\binom{k-1}{m-1}/\binom nm, and that the probability that it contains the overall maximum is m/nm/n.
  2. Show that the variance of xˉS\bar x_S over all subsets of size mm is S2m(1−mn)\frac{S^2}{m}(1 - \frac mn). Then show that the delete-dd jackknife with d=n−md = n - m gives S2/nS^2/n for every mm.
  3. Compute the probability that a with-replacement sample of size mm from nn indices has no repeated index, and show that it tends to 1 when m2/n→0m^2/n \to 0. Explain why the m-out-of-n bootstrap and subsampling then agree.
  4. For the uniform maximum, find the limit of P∗(X(n)∗=X(n))P^*(X^*_{(n)} = X_{(n)}) for the bootstrap and for the m-out-of-n bootstrap with m/n→0m/n \to 0.
  5. Run the implementation on the median of n=200n = 200 normal values with τn=n\tau_n = \sqrt n and several values of mm, and compare the intervals with the bootstrap percentile interval.

References

  1. 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)
  2. 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)
  3. E. L. Lehmann and Joseph P. Romano, Testing Statistical Hypotheses, 3rd edition, Springer, 2005, Section 15.7 (subsampling, and comparison with the bootstrap)
  4. 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)
  5. 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)
  6. 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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • three classic examples