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
- Model
- Real RAM
- Properties
- deterministicnot exactofflineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Sture Holm, 1979
Holm's method tests 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, , compares the smallest with , the next with , and so on, with against , and it stops at the first p-value that fails. Every hypothesis before the stop is rejected. The adjusted p-value of is . 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 for hypotheses , and a level . The set of true nulls is , with elements, and every null p-value is valid: for and .
Output. A set of rejected hypotheses, and the adjusted p-values . For , is rejected exactly when .
Error rate controlled. Strong control of the family-wise error rate: for every configuration of true nulls, where 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 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
HOLM(p₁, …, p_m, α) ▷ p-values in [0, 1], level α- 1
sort the indices so that p_(1) ≤ … ≤ p_(m) - 2
k ← 1; while k ≤ m and (m − k + 1) · p_(k) ≤ α do - 3
reject H_(k) - 4
k ← k + 1 - 5
run ← 0; for k ← 1 to m do ▷ adjusted p-values - 6
run ← max(run, min(1, (m − k + 1) · p_(k))) - 7
p̃_(k) ← run - 8
return (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 and passes, then faces a larger threshold with the same value, so it passes too.
Example
Holm against Bonferroni. Four p-values, , at .
| threshold | L2 | adjusted | ||
|---|---|---|---|---|
| 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 and rejects only the first two. The last adjusted p-value is ; at it is .
The stop rule. For at , the first comparison is , so Holm stops and rejects nothing, even though . 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 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 , which needs . The hypotheses before it are all false nulls, so , and the threshold is at most . So a false rejection implies , and the union bound over the true nulls gives probability at most .
The second argument shows where the method comes from. Under the closed testing principle, test each intersection with the Bonferroni test "reject when ", and reject when every with is rejected. The worst subset for is a tail with , so closed testing rejects exactly when for all , 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 intersections, in exact rational arithmetic, for .
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 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 , in exact rational arithmetic.
Setting. P-values , sorted by line L1 as , where is the index of rank ; ties are broken by the order of the sort and do not change any statement below. is the set of true nulls, , and each null p-value is valid: . Fix .
Lemma 1 (what the lines compute). HOLM rejects if and only if for every . Its adjusted p-value is , and is rejected if and only if .
Proof. The loop at lines L2 to L4 starts at and increases while the test holds, so on exit it has rejected exactly the ranks , where is the first rank that fails, or . Rank is among them exactly when ranks all pass, which is the first claim. The loop at lines L5 to L7 keeps the running maximum, so is as stated. Since , if and only if , and a maximum is at most if and only if every term is.
Theorem 1 (strong control, direct). For every and every joint law with valid null p-values, .
Proof. Let be the smallest rank whose hypothesis is a true null, so . By Lemma 1 the rejected set is a prefix of ranks, so if any true null is rejected, the rank is rejected, which needs . The ranks all hold false nulls, so , that is, . Hence a false rejection implies , and
The second inequality is the union bound, which needs no independence, and the third is validity.
The proof uses the random rank only to show that the event is inside the fixed event ; no conditioning on is needed. That event is exactly the rejection of the intersection by its Bonferroni test, which is the closed testing argument in disguise.
Closed testing with Bonferroni local tests. For each nonempty , the local test rejects when . It has level under , by the union bound as above. The closed procedure rejects when every with is rejected by its local test. Its adjusted p-value is , and it rejects exactly when .
Lemma 2 (tails are the worst subsets). For each rank let , with and . If is nonempty and is the smallest rank in , then , , and .
Proof. Every element of has rank at least , so and . The element of rank is in and has the smallest p-value among ranks , so .
Theorem 2 (Holm is the closed procedure). For every rank , . Hence the closed procedure with Bonferroni local tests and HOLM reject the same hypotheses.
Proof. Fix . () Let , and let be its smallest rank, so . By Lemma 2, . Taking the maximum over gives . () For each , the tail contains , so . Taking the maximum over gives . The second claim follows from Lemma 1 and the rule .
So Holm inherits strong control from the closed testing principle, which says that the closed procedure built from level- local tests controls the family-wise error rate strongly. That principle has a two-line proof: a false rejection needs the local rejection of , which has probability at most . The closed testing principle page proves it in full. The naive closed procedure checks intersections; Theorem 2 shows that only the tails matter, which is why a sort suffices.
Theorem 3 (domination of Bonferroni). If then HOLM rejects . More precisely, for every .
Proof. Let have rank . For every , , since and . So , and the first claim follows by Lemma 1.
Termination and cost. The sort terminates, and each loop runs at most times with constant work per step.
Complexity
On a real RAM, sorting at line L1 takes comparisons with any optimal comparison sort, which is the sorting problem. The loops at lines L2 to L7 take . So the time is , or when the p-values arrive sorted. The extra space is for the order and the outputs.
Only the rejections are cheaper: the method rejects the smallest p-values for some , and a partial sort or repeated selection finds them in time with a heap. Closed testing done naively needs all intersections, so the shortcut turns an exponential computation into a sort.
Numerical stability. Compare with directly from the p-values. Do not form p-values as , 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 .
- 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 , Holm rejects the with the smallest p-value in . So the shortcut loses no single hypothesis that the full closed procedure would reject.
Variants and improvements
- Holm-Šidák. Replace by . This is valid under independence and for two-sided tests on a normal vector, and a little more powerful.
- Weighted Holm. With weights , compare , and at each step test the remaining against . 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 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 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 is large, control the false discovery rate instead.
Pitfalls
- Continuing after a failure. Holm stops at the first acceptance. Comparing every 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. alone can decrease in ; 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 each. Holm's step-down thresholds do not turn into intervals in the same simple way, so do not report intervals at level as if they were simultaneous.
- Changing . 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.
# 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
- 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
- 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
- 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.
| 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 7A4AQ3 Edit this page History Report an error Markdown