Algorithm Search⌘K

Algorithmcore

Holm-Bonferroni method

Also called Holm's step-down procedure, Holm procedure.

Sort the p-values and reject while the k-th smallest is at most alpha / (m - k + 1). It controls the FWER under any dependence and is uniformly more powerful than Bonferroni.

Time
Θ(m log m) worst · best
Space
Θ(m) extra
Where
m = the number of hypotheses
Properties
deterministicnot exactofflineiterative
Origin
Sture Holm, 1979

Holm's method tests mm hypotheses with strong control of the family-wise error rate under any dependence, as the Bonferroni correction does, but it rejects at least as many hypotheses, and often more. It sorts the p-values, p(1)≤⋯≤p(m)p_{(1)} \le \dots \le p_{(m)}, compares the smallest with α/m\alpha/m, the next with α/(m−1)\alpha/(m - 1), and so on, with p(k)p_{(k)} against α/(m−k+1)\alpha/(m - k + 1), and it stops at the first p-value that fails. Every hypothesis before the stop is rejected. The adjusted p-value of H(k)H_{(k)} is max⁡j≤kmin⁡(1,(m−j+1)p(j))\max_{j \le k}\min(1, (m - j + 1)p_{(j)}). The method is the shortcut of the closed testing principle with a Bonferroni test for each intersection of nulls, which is one way to see why it works.

In plain words

The Bonferroni correction makes every test pass a very strict level, as if all the hypotheses could be false alarms. Holm's method uses that strict level only for the most convincing result. Once that result is accepted as real, it no longer needs protection, so the next most convincing result is judged as if there were one test fewer, with a slightly easier level. Each step makes the level a little easier, until a result fails, and then the method stops. Nothing after the first failure is accepted. The guarantee is the same as for Bonferroni: the chance of at least one false alarm stays below the level you chose, whatever the relation between the tests.

The problem

Input. P-values p1,…,pmp_1, \dots, p_m for hypotheses H1,…,HmH_1, \dots, H_m, and a level α∈(0,1)\alpha \in (0, 1). The set of true nulls is I0I_0, with m0m_0 elements, and every null p-value is valid: P(pi≤u)≤uP(p_i \le u) \le u for i∈I0i \in I_0 and u∈[0,1]u \in [0, 1].

Output. A set of rejected hypotheses, and the adjusted p-values p~i\tilde p_i. For α<1\alpha < 1, HiH_i is rejected exactly when p~i≤α\tilde p_i \le \alpha.

Error rate controlled. Strong control of the family-wise error rate: P(V≥1)≤αP(V \ge 1) \le \alpha for every configuration I0I_0 of true nulls, where VV is the number of true nulls rejected.

Dependence. Arbitrary. The control is exact in finite samples, as an inequality, and it uses only the validity of the null p-values.

Power. Holm rejects a superset of what Bonferroni rejects, on every data set, since its first threshold is α/m\alpha/m and the others are larger. The Hochberg procedure rejects a superset of what Holm rejects, but it needs a condition on the dependence.

The algorithm

  1. HOLM(p₁, …, p_m, α) ▷ p-values in [0, 1], level α
  2. 1sort the indices so that p_(1) ≤ … ≤ p_(m)
  3. 2k ← 1; while k ≤ m and (m − k + 1) · p_(k) ≤ α do
  4. 3reject H_(k)
  5. 4k ← k + 1
  6. 5run ← 0; for k ← 1 to m do ▷ adjusted p-values
  7. 6run ← max(run, min(1, (m − k + 1) · p_(k)))
  8. 7p̃_(k) ← run
  9. 8return (rejected set, p̃)

The test at line L2 multiplies instead of dividing, so that the rejections agree with the adjusted p-values even in floating point. Tied p-values get the same decision: if p(k)=p(k+1)p_{(k)} = p_{(k+1)} and H(k)H_{(k)} passes, then H(k+1)H_{(k+1)} faces a larger threshold with the same value, so it passes too.

Example

Holm against Bonferroni. Four p-values, 0.005,0.011,0.020,0.0400.005, 0.011, 0.020, 0.040, at α=0.05\alpha = 0.05.

kk p(k)p_{(k)} threshold α/(m−k+1)\alpha/(m - k + 1) L2 adjusted p~(k)\tilde p_{(k)}
1 0.005 0.0125 reject 0.02
2 0.011 0.016667 reject 0.033
3 0.020 0.025 reject 0.04
4 0.040 0.05 reject 0.04

Holm rejects all four. Bonferroni compares each with 0.01250.0125 and rejects only the first two. The last adjusted p-value is max⁡(0.04,1⋅0.04)=0.04\max(0.04, 1 \cdot 0.04) = 0.04; at k=3k = 3 it is max⁡(0.033,2⋅0.02)=0.04\max(0.033, 2 \cdot 0.02) = 0.04.

The stop rule. For 0.02,0.02,0.90.02, 0.02, 0.9 at α=0.05\alpha = 0.05, the first comparison is 0.02>0.05/3=0.0166670.02 > 0.05/3 = 0.016667, so Holm stops and rejects nothing, even though 0.02≤0.05/20.02 \le 0.05/2. A step-up rule would reject both: this is the case where Hochberg's procedure gains.

Fifteen p-values. On the 15 p-values of Benjamini and Hochberg (1995) (0.0001, 0.0004, 0.0019, 0.0095, 0.0201, 0.0278, 0.0298, 0.0344, 0.0459, 0.3240, 0.4262, 0.5719, 0.6528, 0.7590, 1.000), the thresholds start at 0.003333, 0.003571, 0.003846 and 0.004167. The first three p-values pass and 0.0095 fails, so Holm rejects 3, as Bonferroni does. The adjusted p-values are 0.0015, 0.0056, 0.0247, 0.114, 0.2211, 0.278, 0.278, 0.278, 0.3213, and 1 for the last six. The seventh and eighth are raised from 0.2682 and 0.2752 to 0.278 by the running maximum at line L6.

Correctness

The direct argument is short. Let j∗j^* be the rank of the smallest p-value among the true nulls. Holm rejects a prefix of the sorted list, so it rejects some true null only if it reaches and rejects H(j∗)H_{(j^*)}, which needs p(j∗)≤α/(m−j∗+1)p_{(j^*)} \le \alpha/(m - j^* + 1). The j∗−1j^* - 1 hypotheses before it are all false nulls, so j∗−1≤m−m0j^* - 1 \le m - m_0, and the threshold is at most α/m0\alpha/m_0. So a false rejection implies min⁡i∈I0pi≤α/m0\min_{i \in I_0}p_i \le \alpha/m_0, and the union bound over the m0m_0 true nulls gives probability at most α\alpha.

The second argument shows where the method comes from. Under the closed testing principle, test each intersection HI=⋂i∈IHiH_I = \bigcap_{i \in I}H_i with the Bonferroni test "reject when ∣I∣min⁡i∈Ipi≤α|I|\min_{i \in I}p_i \le \alpha", and reject HiH_i when every HIH_I with i∈Ii \in I is rejected. The worst subset for H(k)H_{(k)} is a tail {(j),…,(m)}\{(j), \dots, (m)\} with j≤kj \le k, so closed testing rejects H(k)H_{(k)} exactly when (m−j+1)p(j)≤α(m - j + 1)p_{(j)} \le \alpha for all j≤kj \le k, which is Holm's rule. The correctness proof gives both arguments in full and the formula for the adjusted p-values. The tests compare Holm with closed testing over all 2m−12^m - 1 intersections, in exact rational arithmetic, for m≤8m \le 8.

Proof: Holm's method is closed testing with Bonferroni local tests, and it controls the family-wise error rate strongly under any dependencefull

We prove three things about HOLM. First, it controls the family-wise error rate at α\alpha for every set of true nulls and every joint law of the p-values (Theorem 1, a direct proof). Second, its rejections and its adjusted p-values are exactly those of the closed testing procedure with Bonferroni local tests (Theorem 2), so strong control also follows from the closed testing principle. Third, it rejects every hypothesis that the Bonferroni correction rejects. All results are proved; the tests check Theorem 2 by enumeration of all intersections for m≤8m \le 8, in exact rational arithmetic.

Setting. P-values p1,…,pmp_1, \dots, p_m, sorted by line L1 as p(1)≤⋯≤p(m)p_{(1)} \le \dots \le p_{(m)}, where (k)(k) is the index of rank kk; ties are broken by the order of the sort and do not change any statement below. I0I_0 is the set of true nulls, m0=∣I0∣≥1m_0 = |I_0| \ge 1, and each null p-value is valid: P(pi≤u)≤uP(p_i \le u) \le u. Fix 0<α<10 < \alpha < 1.

Lemma 1 (what the lines compute). HOLM rejects H(k)H_{(k)} if and only if (m−j+1)p(j)≤α(m - j + 1)p_{(j)} \le \alpha for every j≤kj \le k. Its adjusted p-value is p~(k)=max⁡j≤kmin⁡(1,(m−j+1)p(j))\tilde p_{(k)} = \max_{j \le k}\min(1, (m - j + 1)p_{(j)}), and H(k)H_{(k)} is rejected if and only if p~(k)≤α\tilde p_{(k)} \le \alpha.

Proof. The loop at lines L2 to L4 starts at k=1k = 1 and increases kk while the test holds, so on exit it has rejected exactly the ranks 1,…,r1, \dots, r, where r+1r + 1 is the first rank that fails, or r=mr = m. Rank kk is among them exactly when ranks 1,…,k1, \dots, k all pass, which is the first claim. The loop at lines L5 to L7 keeps the running maximum, so p~(k)\tilde p_{(k)} is as stated. Since α<1\alpha < 1, min⁡(1,x)≤α\min(1, x) \le \alpha if and only if x≤αx \le \alpha, and a maximum is at most α\alpha if and only if every term is. □\square

Theorem 1 (strong control, direct). For every I0I_0 and every joint law with valid null p-values, P(V≥1)≤αP(V \ge 1) \le \alpha.

Proof. Let j∗j^* be the smallest rank whose hypothesis is a true null, so p(j∗)=min⁡i∈I0pip_{(j^*)} = \min_{i \in I_0}p_i. By Lemma 1 the rejected set is a prefix of ranks, so if any true null is rejected, the rank j∗j^* is rejected, which needs (m−j∗+1)p(j∗)≤α(m - j^* + 1)p_{(j^*)} \le \alpha. The ranks 1,…,j∗−11, \dots, j^* - 1 all hold false nulls, so j∗−1≤m−m0j^* - 1 \le m - m_0, that is, m−j∗+1≥m0m - j^* + 1 \ge m_0. Hence a false rejection implies m0min⁡i∈I0pi≤αm_0\min_{i \in I_0}p_i \le \alpha, and

P(V≥1)≤P(min⁡i∈I0pi≤αm0)≤∑i∈I0P(pi≤αm0)≤m0⋅αm0=α.P(V \ge 1) \le P\Big(\min_{i \in I_0}p_i \le \frac{\alpha}{m_0}\Big) \le \sum_{i \in I_0}P\Big(p_i \le \frac{\alpha}{m_0}\Big) \le m_0 \cdot \frac{\alpha}{m_0} = \alpha.

The second inequality is the union bound, which needs no independence, and the third is validity. □\square

The proof uses the random rank j∗j^* only to show that the event {V≥1}\{V \ge 1\} is inside the fixed event {min⁡I0pi≤α/m0}\{\min_{I_0}p_i \le \alpha/m_0\}; no conditioning on j∗j^* is needed. That event is exactly the rejection of the intersection HI0H_{I_0} by its Bonferroni test, which is the closed testing argument in disguise.

Closed testing with Bonferroni local tests. For each nonempty I⊆{1,…,m}I \subseteq \{1, \dots, m\}, the local test rejects HI=⋂i∈IHiH_I = \bigcap_{i \in I}H_i when ∣I∣min⁡i∈Ipi≤α|I|\min_{i \in I}p_i \le \alpha. It has level α\alpha under HIH_I, by the union bound as above. The closed procedure rejects HiH_i when every HIH_I with i∈Ii \in I is rejected by its local test. Its adjusted p-value is p^i=max⁡I∋imin⁡(1,∣I∣min⁡j∈Ipj)\hat p_i = \max_{I \ni i}\min(1, |I|\min_{j \in I}p_j), and it rejects HiH_i exactly when p^i≤α\hat p_i \le \alpha.

Lemma 2 (tails are the worst subsets). For each rank jj let Tj={(j),(j+1),…,(m)}T_j = \{(j), (j + 1), \dots, (m)\}, with ∣Tj∣=m−j+1|T_j| = m - j + 1 and min⁡Tjp=p(j)\min_{T_j}p = p_{(j)}. If II is nonempty and jj is the smallest rank in II, then I⊆TjI \subseteq T_j, min⁡Ip=p(j)\min_I p = p_{(j)}, and ∣I∣min⁡Ip≤∣Tj∣min⁡Tjp|I|\min_I p \le |T_j|\min_{T_j}p.

Proof. Every element of II has rank at least jj, so I⊆TjI \subseteq T_j and ∣I∣≤m−j+1|I| \le m - j + 1. The element of rank jj is in II and has the smallest p-value among ranks ≥j\ge j, so min⁡Ip=p(j)=min⁡Tjp\min_I p = p_{(j)} = \min_{T_j}p. □\square

Theorem 2 (Holm is the closed procedure). For every rank kk, p^(k)=p~(k)\hat p_{(k)} = \tilde p_{(k)}. Hence the closed procedure with Bonferroni local tests and HOLM reject the same hypotheses.

Proof. Fix kk. (≤\le) Let I∋(k)I \ni (k), and let jj be its smallest rank, so j≤kj \le k. By Lemma 2, min⁡(1,∣I∣min⁡Ip)≤min⁡(1,(m−j+1)p(j))≤p~(k)\min(1, |I|\min_I p) \le \min(1, (m - j + 1)p_{(j)}) \le \tilde p_{(k)}. Taking the maximum over II gives p^(k)≤p~(k)\hat p_{(k)} \le \tilde p_{(k)}. (≥\ge) For each j≤kj \le k, the tail TjT_j contains (k)(k), so p^(k)≥min⁡(1,∣Tj∣min⁡Tjp)=min⁡(1,(m−j+1)p(j))\hat p_{(k)} \ge \min(1, |T_j|\min_{T_j}p) = \min(1, (m - j + 1)p_{(j)}). Taking the maximum over j≤kj \le k gives p^(k)≥p~(k)\hat p_{(k)} \ge \tilde p_{(k)}. The second claim follows from Lemma 1 and the rule p^i≤α\hat p_i \le \alpha. □\square

So Holm inherits strong control from the closed testing principle, which says that the closed procedure built from level-α\alpha local tests controls the family-wise error rate strongly. That principle has a two-line proof: a false rejection needs the local rejection of HI0H_{I_0}, which has probability at most α\alpha. The closed testing principle page proves it in full. The naive closed procedure checks 2m−12^m - 1 intersections; Theorem 2 shows that only the mm tails matter, which is why a sort suffices.

Theorem 3 (domination of Bonferroni). If mpi≤αmp_i \le \alpha then HOLM rejects HiH_i. More precisely, p~i≤min⁡(1,mpi)\tilde p_i \le \min(1, mp_i) for every ii.

Proof. Let ii have rank kk. For every j≤kj \le k, (m−j+1)p(j)≤m p(j)≤mp(k)=mpi(m - j + 1)p_{(j)} \le m\,p_{(j)} \le mp_{(k)} = mp_i, since m−j+1≤mm - j + 1 \le m and p(j)≤p(k)p_{(j)} \le p_{(k)}. So p~(k)≤min⁡(1,mpi)\tilde p_{(k)} \le \min(1, mp_i), and the first claim follows by Lemma 1. □\square

Termination and cost. The sort terminates, and each loop runs at most mm times with constant work per step.

Complexity

On a real RAM, sorting at line L1 takes Θ(mlog⁡m)\Theta(m\log m) comparisons with any optimal comparison sort, which is the sorting problem. The loops at lines L2 to L7 take Θ(m)\Theta(m). So the time is Θ(mlog⁡m)\Theta(m\log m), or Θ(m)\Theta(m) when the p-values arrive sorted. The extra space is Θ(m)\Theta(m) for the order and the outputs.

Only the rejections are cheaper: the method rejects the rr smallest p-values for some rr, and a partial sort or repeated selection finds them in O(m+rlog⁡m)O(m + r\log m) time with a heap. Closed testing done naively needs all 2m−12^m - 1 intersections, so the shortcut turns an exponential computation into a sort.

Numerical stability. Compare (m−k+1)p(k)(m - k + 1)p_{(k)} with α\alpha directly from the p-values. Do not form p-values as 1−CDF1 - \text{CDF}, which rounds small p-values to 0 or loses their digits; compute them from the upper tail.

Properties

  • Strong FWER control under any dependence. Proved above, with no condition except the validity of the null p-values.
  • Uniformly more powerful than Bonferroni. Every hypothesis that Bonferroni rejects, Holm rejects. The adjusted p-values satisfy p~i≤min⁡(1,mpi)\tilde p_i \le \min(1, mp_i).
  • Step-down. Holm starts from the smallest p-value and stops at the first acceptance. Its decisions depend on all the p-values, through their ranks.
  • Monotone. Lowering any p-value never removes a rejection.
  • Consonant. When the closed procedure with Bonferroni local tests rejects an intersection HIH_I, Holm rejects the HiH_i with the smallest p-value in II. So the shortcut loses no single hypothesis that the full closed procedure would reject.

Variants and improvements

  • Holm-Šidák. Replace α/(m−k+1)\alpha/(m - k + 1) by 1−(1−α)1/(m−k+1)1 - (1 - \alpha)^{1/(m - k + 1)}. This is valid under independence and for two-sided tests on a normal vector, and a little more powerful.
  • Weighted Holm. With weights wi≥0w_i \ge 0, compare pi/wip_i/w_i, and at each step test the remaining pip_i against wiα/∑j remainingwjw_i\alpha/\sum_{j \text{ remaining}}w_j. This is closed testing with weighted Bonferroni local tests.
  • Shaffer's method. When the hypotheses are logically related, as pairwise comparisons of means are, some sets of true nulls are impossible, and the threshold at step kk can use the largest number of nulls that can still be true. Shaffer proposed this in 1986.
  • Hochberg and Hommel. Closed testing with Simes local tests gives Hommel's method; its conservative shortcut is Hochberg's step-up rule with Holm's thresholds. Both need independence or positive dependence.
  • Resampling. The Westfall-Young step-down method replaces α/(m−k+1)\alpha/(m - k + 1) by a permutation quantile of the maximum statistic over the remaining hypotheses, which uses the dependence.
  • Gatekeeping and graphical methods. When the hypotheses have an order of importance, closed testing with weighted Bonferroni tests passes the level of a rejected hypothesis on to others. Holm is the case where the level is shared equally.

When to use it

Use Holm wherever you would use Bonferroni and all p-values are known together: the guarantee and the assumptions are the same, and it is never worse. It is the standard default for a small family of tests with strict error control, such as the secondary end points of a trial. When the tests are independent or positively dependent, the Hochberg procedure gains a little power. When raw data are available and the tests are correlated, the Westfall-Young procedure gains more. When mm is large, control the false discovery rate instead.

Pitfalls

  • Continuing after a failure. Holm stops at the first acceptance. Comparing every p(k)p_{(k)} with its threshold and rejecting each that passes is not Holm's method and does not control the error rate.
  • Adjusted p-values without the running maximum. (m−k+1)p(k)(m - k + 1)p_{(k)} alone can decrease in kk; without line L6, a later hypothesis can get a smaller adjusted p-value than an earlier one and be "rejected" after the stop.
  • Confidence intervals. Bonferroni gives simultaneous intervals at level 1−α/m1 - \alpha/m each. Holm's step-down thresholds do not turn into intervals in the same simple way, so do not report intervals at level 1−α/(m−k+1)1 - \alpha/(m - k + 1) as if they were simultaneous.
  • Changing mm. Adding or removing hypotheses after seeing the data changes the thresholds and voids the guarantee.

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.

holm_bonferroni_method.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/holm-bonferroni-method/. The authors are listed in prov/7A4AQ3.jsonl.
"""Holm's step-down procedure for m hypotheses.

Sort the p-values, p_(1) <= ... <= p_(m), and reject H_(1), H_(2), ... while
p_(k) <= alpha / (m - k + 1); stop at the first failure. The adjusted p-value of
H_(k) is max over j <= k of min(1, (m - j + 1) p_(j)). The procedure controls the
family-wise error rate strongly at alpha under any dependence. The code works with
floats or with fractions.Fraction; with Fractions every result is exact.
"""

from collections.abc import Sequence


def holm(p: Sequence, alpha) -> tuple[list[bool], list]:
    """Return (reject, adjusted) in the original order of p."""
    m = len(p)
    if m == 0:
        return [], []
    if any(not 0 <= v <= 1 for v in p):
        raise ValueError("p-values must lie in [0, 1]")
    if not 0 <= alpha <= 1:
        raise ValueError("alpha must lie in [0, 1]")
    order = sorted(range(m), key=lambda i: p[i])  # @line L1
    reject = [False] * m
    k = 0  # 0-based rank, so the threshold is alpha / (m - k)
    while k < m and p[order[k]] * (m - k) <= alpha:  # @line L2
        reject[order[k]] = True  # @line L3
        k += 1  # @line L4
    adjusted = [0] * m
    running = 0
    for k, i in enumerate(order):  # @line L5
        running = max(running, min(1, (m - k) * p[i]))  # @line L6
        adjusted[i] = running  # @line L7
    return reject, adjusted  # @line L8
test_holm_bonferroni_method.py 149 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/holm-bonferroni-method/. The authors are listed in prov/7A4AQ3.jsonl.

import itertools
import math
import random
import statistics
from fractions import Fraction

import pytest

from holm_bonferroni_method import holm

BH95 = [0.0001, 0.0004, 0.0019, 0.0095, 0.0201, 0.0278, 0.0298, 0.0344, 0.0459, 0.3240, 0.4262, 0.5719, 0.6528, 0.7590, 1.000]


def closed_bonferroni(p: list, alpha) -> tuple[list[bool], list]:
    """Brute force: closed testing with a Bonferroni local test for every intersection H_I.

    H_I is rejected when |I| min_(i in I) p_i <= alpha. H_i is rejected when every H_I
    with i in I is rejected. The adjusted p-value of H_i is max over I containing i of
    min(1, |I| min_(j in I) p_j). All 2^m - 1 nonempty subsets are enumerated.
    """
    m = len(p)
    adjusted = [0] * m
    for size in range(1, m + 1):
        for subset in itertools.combinations(range(m), size):
            p_local = min(1, size * min(p[j] for j in subset))
            for i in subset:
                adjusted[i] = max(adjusted[i], p_local)
    reject = [all(min(1, len(s) * min(p[j] for j in s)) <= alpha for size in range(1, m + 1) for s in itertools.combinations(range(m), size) if i in s) for i in range(m)]
    return reject, adjusted


def test_worked_example_by_hand() -> None:
    reject, adjusted = holm(BH95, 0.05)
    # 0.0001 <= 0.05/15, 0.0004 <= 0.05/14, 0.0019 <= 0.05/13, and 0.0095 > 0.05/12 = 0.004167 stops.
    assert [i for i, r in enumerate(reject) if r] == [0, 1, 2]
    assert adjusted[:5] == pytest.approx([0.0015, 0.0056, 0.0247, 0.114, 0.2211])


def test_holm_beats_bonferroni_by_hand() -> None:
    p = [Fraction(5, 1000), Fraction(11, 1000), Fraction(2, 100), Fraction(4, 100)]
    reject, adjusted = holm(p, Fraction(1, 20))
    # 0.005 <= 0.0125, 0.011 <= 0.01667, 0.02 <= 0.025, 0.04 <= 0.05: all four.
    assert reject == [True, True, True, True]
    assert adjusted == [Fraction(1, 50), Fraction(33, 1000), Fraction(1, 25), Fraction(1, 25)]
    # Bonferroni at 0.05/4 = 0.0125 rejects only the first two.
    assert [4 * v <= Fraction(1, 20) for v in p] == [True, True, False, False]


def test_stops_at_first_failure() -> None:
    p = [Fraction(1, 100), Fraction(3, 100), Fraction(1, 1000)]
    reject, _ = holm(p, Fraction(1, 20))
    # Sorted: 0.001 <= 0.05/3 yes, 0.01 <= 0.025 yes, 0.03 <= 0.05 yes.
    assert reject == [True, True, True]
    reject, _ = holm([Fraction(1, 50), Fraction(1, 50), Fraction(9, 10)], Fraction(1, 20))
    # 0.02 <= 0.05/3 fails, so nothing is rejected, even though 0.02 <= 0.05/2.
    assert reject == [False, False, False]


def test_equals_closed_testing_with_bonferroni_local_tests() -> None:
    rng = random.Random(1979)
    for _ in range(300):
        m = rng.randint(1, 8)
        denom = rng.choice([20, 100, 400])
        p = [Fraction(rng.randint(0, denom), denom) for _ in range(m)]
        alpha = Fraction(rng.randint(1, 19), 100)
        assert holm(p, alpha) == closed_bonferroni(p, alpha)


def test_at_least_as_many_rejections_as_bonferroni() -> None:
    rng = random.Random(5)
    for _ in range(2000):
        m = rng.randint(1, 20)
        p = [rng.random() ** 3 for _ in range(m)]
        reject, adjusted = holm(p, 0.05)
        for i in range(m):
            if p[i] * m <= 0.05:
                assert reject[i]
            assert adjusted[i] <= min(1, m * p[i])


def test_adjusted_p_values_match_rejections_and_are_monotone() -> None:
    rng = random.Random(8)
    for _ in range(300):
        m = rng.randint(1, 10)
        p = [Fraction(rng.randint(0, 200), 200) for _ in range(m)]
        _, adjusted = holm(p, Fraction(1, 20))
        order = sorted(range(m), key=lambda i: p[i])
        assert all(adjusted[order[k]] <= adjusted[order[k + 1]] for k in range(m - 1))
        for alpha in [Fraction(k, 100) for k in range(0, 100, 3)]:
            reject, _ = holm(p, alpha)
            assert reject == [a <= alpha for a in adjusted]


def test_ties_get_the_same_decision() -> None:
    reject, adjusted = holm([0.01, 0.01, 0.01, 0.5], 0.05)
    assert reject == [True, True, True, False]
    assert adjusted[0] == adjusted[1] == adjusted[2] == pytest.approx(0.04)


def test_invalid_input() -> None:
    assert holm([], 0.05) == ([], [])
    with pytest.raises(ValueError):
        holm([0.1, -0.1], 0.05)


def test_exact_fwer_by_enumeration_on_a_grid() -> None:
    """m = 3, m_0 = 2 true nulls with independent p-values uniform on {1/10, ..., 1}; the false null has p = 1/1000.

    Count the 100 cases exactly; the family-wise error rate is at most alpha = 2/5.
    """
    alpha = Fraction(2, 5)
    grid = [Fraction(k, 10) for k in range(1, 11)]
    bad = 0
    for a, b in itertools.product(grid, repeat=2):
        reject, _ = holm([a, b, Fraction(1, 1000)], alpha)
        bad += reject[0] or reject[1]
    # With H_3 rejected first, the two nulls face 1/5 and then 2/5:
    # a false rejection needs min(a, b) <= 1/5, which has 100 - 64 = 36 cases.
    assert bad == 36
    assert Fraction(bad, 100) <= alpha


def test_monte_carlo_strong_control_under_negative_dependence() -> None:
    """m_0 = 5 nulls with p_i = (U + i/5) mod 1, which is the worst case for the union bound, and 3 strong false nulls."""
    rng = random.Random(31)
    alpha, reps, errors = 0.05, 20000, 0
    for _ in range(reps):
        u = rng.random()
        p = [(u + i / 5) % 1 for i in range(5)] + [1e-6, 2e-6, 3e-6]
        reject, _ = holm(p, alpha)
        errors += any(reject[:5])
    # After the 3 false nulls fall, each null faces alpha/5 at the first step; the events are disjoint,
    # so the exact FWER is 5 * alpha/5 = alpha. Four standard errors are 0.0062.
    assert abs(errors / reps - alpha) < 0.0062


def test_monte_carlo_fwer_with_correlated_normals() -> None:
    rng = random.Random(77)
    nd = statistics.NormalDist()
    m, m0, alpha, reps, errors = 10, 7, 0.05, 10000, 0
    for _ in range(reps):
        shared = rng.gauss(0, 1)
        z = [math.sqrt(0.6) * shared + math.sqrt(0.4) * rng.gauss(0, 1) + (4.0 if i >= m0 else 0.0) for i in range(m)]
        reject, _ = holm([1 - nd.cdf(v) for v in z], alpha)
        errors += any(reject[:m0])
    assert errors / reps <= alpha + 0.0066  # three standard errors of a proportion near 0.05

History

Sture Holm published the method in 1979 as a "sequentially rejective Bonferroni test", with a direct proof of strong control under any dependence. Marcus, Peritz and Gabriel had introduced the closed testing principle three years before, and it was soon seen that Holm's method is the shortcut of closed testing with Bonferroni local tests. Šidák's inequality gave the Holm-Šidák variant. Hochberg (1988) turned the order around into a step-up rule, and Hommel (1988) gave the full closed version with Simes tests. Weighted and graphical versions, used to test ordered families of end points in clinical trials, are later extensions of the same idea.

References

  1. Sture Holm, A simple sequentially rejective multiple test procedure, Scandinavian Journal of Statistics 6(2) (1979), pages 65 to 70, the sequentially rejective Bonferroni test and the proof that it controls the multiple level of significance under any dependence
  2. Ruth Marcus, Eric Peritz and K. R. Gabriel, On closed testing procedures with special reference to ordered analysis of variance, Biometrika 63(3) (1976), pages 655 to 660, the closed testing principle, of which Holm's method is the case with Bonferroni local tests
  3. E. L. Lehmann and Joseph P. Romano, Testing Statistical Hypotheses, third edition, Springer, 2005, Chapter 9 (multiple testing; the Holm procedure and its strong control of the family-wise error rate)

Where this leads

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 proofH1 sketch
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
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
  • a scene preset for the example