Algorithmadvanced
Benjamini-Yekutieli procedure
Also called BY procedure.
Run Benjamini-Hochberg at level q / (1 + 1/2 + ... + 1/m). This controls the FDR at (m_0/m) q under any dependence, at a level about ln m times smaller.
- 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
- Yoav Benjamini, Daniel Yekutieli, 2001
The Benjamini-Yekutieli procedure (BY) is the Benjamini-Hochberg procedure run at the smaller level , where is the -th harmonic number. It sorts the p-values, finds the largest with , and rejects . Its false discovery rate is at most under any dependence among the p-values, with only the validity of each null p-value assumed. That is the reason to use it. The price is power: is about , so the thresholds are 2.93 times smaller than those of BH for and 7.49 times smaller for . The factor cannot be removed in general: there are joint laws of valid p-values under which plain BH has FDR exactly .
In plain words
Benjamini-Hochberg keeps the share of false discoveries low when the tests behave independently, or when they tend to move together in the same direction. If the tests can depend on each other in strange ways, false discoveries can pile up and the guarantee fails. This method repairs that by making the bar stricter by a fixed factor that grows slowly with the number of tests: about 3 for ten tests, about 5 for a hundred, about 7.5 for a thousand. After that change the method works for any pattern of dependence. You pay for this safety with fewer discoveries, so use it only when you cannot argue that the dependence is harmless.
The problem
Input. P-values for hypotheses , and a target FDR level .
Output. The rejected set, and the adjusted p-values , with rejected exactly when .
Error rate controlled. The false discovery rate , strongly, over every configuration of true and false nulls.
Dependence and level. Arbitrary. If each null p-value is valid, , then , in finite samples. No condition is put on the joint law. The bound is attained when , by the construction in the proof. Under independence BY is just BH at , so its FDR is exactly .
The algorithm
BY(p₁, …, p_m, q) ▷ p-values in [0, 1], FDR level q- 1
c ← 1 + 1/2 + … + 1/m - 2
sort the indices so that p_(1) ≤ … ≤ p_(m) - 3
k ← m; while k ≥ 1 and m · c · p_(k) > k · q do - 4
k ← k − 1 - 5
reject H_(1), …, H_(k) - 6
run ← 1; for r ← m down to 1 do ▷ adjusted p-values - 7
run ← min(run, m · c · p_(r) / r); p̃_(r) ← run - 8
return (rejected set, p̃)
Lines L2 to L8 are the BH algorithm with replaced by . The implementation computes as an exact fraction when the inputs are fractions, and with a correctly rounded sum of floats otherwise. For very large , with , see the harmonic series.
Example
Four p-values. at . Here .
| BH threshold | BY threshold | ||
|---|---|---|---|
| 1 | 0.004 | 0.0125 | 0.006 |
| 2 | 0.011 | 0.025 | 0.012 |
| 3 | 0.02 | 0.0375 | 0.018 |
| 4 | 0.6 | 0.05 | 0.024 |
BH rejects three, since 0.02 is below 0.0375. BY rejects two: 0.011 is below 0.012, but 0.02 is above 0.018 and 0.6 is above 0.024.
The 15 p-values of Benjamini and Hochberg (1995). At , , and the BY thresholds are . The first three p-values, 0.0001, 0.0004 and 0.0019, pass, and none of 0.0095, 0.0201, ..., 0.3240 passes its threshold, so BY rejects three, against four for BH. The adjusted p-values start 0.005, 0.01, 0.0315, 0.1182, 0.2001.
The worst case for BH, by hand. Take , both nulls true, and this joint law. With probability , pick one of the two indices at random, set its p-value to and the other to 1. With probability , set both to . Otherwise set both to 1. Each p-value then has and , and it is valid. BH at rejects one hypothesis in the first case and two in the second, all of them false, so its FDR is . BY at uses in place of , and the same construction at shows that its FDR can be reached.
Correctness
The proof shows under arbitrary dependence. Write for the thresholds at level , fix a true null , and let be the event that is rejected and . The events are disjoint, and because a rejected hypothesis has . Writing as a telescoping sum gives
using only . Summing over the true nulls gives the bound. The same argument with in place of shows that plain BH has , and the construction in the proof attains this when and .
The tests check the rejections against BH at in exact rational arithmetic, and the bound under arbitrary dependence exactly. In the second check the null p-values are uniform on and are coupled through random permutations of one shared uniform index, which gives many different dependence structures with valid marginals; the FDR is summed over the 24 outcomes as a fraction. The worst-case law is built for and gives FDR exactly for BH and exactly for BY.
Proof: The Benjamini-Yekutieli procedure controls the FDR at (m_0/m) q under any dependence, and the harmonic factor is sharpfull
We prove that any step-up procedure with thresholds has false discovery rate at most under any dependence (Theorem 1). For the Benjamini-Yekutieli thresholds this is (Corollary 2). Then we build a joint law of valid null p-values under which Benjamini-Hochberg at has FDR exactly and Benjamini-Yekutieli at has FDR exactly (Theorem 3). Everything here is proved; the tests check Corollary 2 exactly on random dependence structures and Theorem 3 exactly for .
Setting. P-values with any joint law. is the set of true nulls, , and each null p-value is valid: for . . A step-up procedure with thresholds sets , with and if there is no such , and rejects . BH at level is the case , and BY at level is the case , which is what lines L1 to L5 compute (Lemma 1 in the correctness proof of the Benjamini-Hochberg procedure applies with in place of ).
Theorem 1. For every step-up procedure with thresholds and every joint law with valid null p-values,
Proof. Pointwise, , where is the event that is rejected and . Fix and write . The events are disjoint, since takes one value. On , is rejected, so . Hence for each , , because for , and so
For the telescoping sum gives . Therefore, exchanging the order of summation and using disjointness,
Each probability is at most the matching , and the coefficients are positive, so the sum is at most . Summing over the true nulls gives the theorem.
No independence or positive dependence was used: only validity at the thresholds and the fact that a step-up rejection of with needs .
Corollary 2 (Benjamini-Yekutieli). For every , the step-up procedure with has . In particular BH at has , and BY at , which is the case , has under any dependence.
Proof. With , and . So the bound of Theorem 1 is
Theorem 3 (the factor is sharp). Let and with , and if . Define the joint law of as follows. For each , with probability , choose a set of indices uniformly at random, set for and for . With the remaining probability , set every . Then every is a valid p-value with for each , and if all nulls are true, BH at level has .
Proof. The probabilities and are nonnegative and sum to 1. Fix . In case , index is in with probability , so for each , and . So . For , let be the largest with (or ); then . For the probability is 1. So is valid.
In case , exactly p-values equal and the others equal for all (for there are no others). So for , , and for . Hence . In the last case . Under the global null every rejection is false, so and .
Corollary 4. Under the law with all nulls true, BY at level has FDR exactly . So the bound of Corollary 2 is attained when .
Proof. BY at is BH at , and , so Theorem 3 applies with level and gives . (For , since .)
For the law is the example on the page: with probability one p-value is and the other is 1, with probability both are , and BH has FDR .
Adjusted p-values. Lines L6 and L7 compute . For , if and only if for some , which is , the rejection of rank . The tests check this equivalence on random vectors in exact arithmetic.
Complexity
The harmonic number takes additions at line L1, the sort at line L2 takes on a real RAM, and the rest takes . So the time is and the extra space . As for BH, the rejections alone can be found in time by counting the p-values in buckets instead of sorting.
Properties
- FDR at under any dependence. Proved, in finite samples, with only valid null p-values.
- Sharp. No constant smaller than works for every dependence with BH's linear thresholds: the construction gives FDR for BH at .
- Conservative in common cases. Under independence or PRDS, BY has FDR or less, far below .
- Between BH and Bonferroni. Its first threshold is , below the Bonferroni level . Its last threshold is . For small it is stricter than Bonferroni at the same level, and for it is more lenient, so neither rejection set contains the other in general.
- Monotone and step-up. As for BH: lowering a p-value never removes a rejection.
Variants and improvements
- Other shapes. Blanchard and Roquain showed that BH with the thresholds controls the FDR under any dependence when for a probability distribution on . BY is the case . Other choices of give more power where many rejections are expected.
- e-BH. For e-values, the BH rule controls the FDR at under any dependence without a harmonic factor. Turning p-values into e-values loses power, so this helps when the evidence comes as e-values in the first place.
- Use the dependence. When the joint law is known or can be resampled, permutation and bootstrap methods, as in the Westfall-Young procedure for the FWER, use the actual dependence and lose less.
- FWER instead. Bonferroni and Holm also work under any dependence, and for small they can reject as much as BY.
When to use it
Use BY when the FDR is the right error rate, the dependence between the tests is unknown and could be negative, and a conservative result is acceptable. Examples are two-sided tests on correlated statistics with signs of both kinds, or tests that share data in complex ways. When the tests are independent, or positively dependent as for one-sided tests on positively correlated normal statistics, plain BH is valid and much more powerful. Many analysts use BH even with mild unknown dependence, because simulations rarely show its FDR above ; BY is the choice when a proof is required.
Pitfalls
- Using it by default. Under independence BY controls the FDR at about , not . Reporting "FDR at 5%" then hides a much stricter error rate and a large loss of power.
- Writing for . , so dividing by gives a level that is too large and voids the proof. Use the exact sum, or as an upper bound.
- Applying the factor twice. Software that reports BY adjusted p-values already includes ; compare them with , not with .
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/benjamini-yekutieli-procedure/. The authors are listed in prov/HW5E27.jsonl.
"""The Benjamini-Yekutieli procedure.
It is the Benjamini-Hochberg step-up procedure run at level q / c_m, where
c_m = 1 + 1/2 + ... + 1/m. Find the largest k with p_(k) <= k q / (m c_m) and
reject H_(1), ..., H_(k). Under any dependence among the p-values, with valid
null p-values, the false discovery rate is at most (m_0 / m) q.
Comparisons are done as m c_m p <= k q. With fractions.Fraction inputs, c_m is
computed exactly as a Fraction, so the decisions are exact.
"""
import math
from collections.abc import Sequence
from fractions import Fraction
def harmonic(m: int, exact: bool = False):
"""c_m = 1 + 1/2 + ... + 1/m, as a Fraction if exact, else as a correctly summed float."""
if exact:
return sum((Fraction(1, i) for i in range(1, m + 1)), Fraction(0))
return math.fsum(1 / i for i in range(1, m + 1))
def by(p: Sequence, q) -> 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 < q <= 1:
raise ValueError("q must lie in (0, 1]")
exact = isinstance(q, Fraction) or any(isinstance(v, Fraction) for v in p)
c = harmonic(m, exact) # @line L1
order = sorted(range(m), key=lambda i: p[i]) # @line L2
k = m
while k >= 1 and m * c * p[order[k - 1]] > k * q: # @line L3
k -= 1 # @line L4
reject = [False] * m
for r in range(k): # @line L5
reject[order[r]] = True
adjusted = [0] * m
running = 1
for r in range(m - 1, -1, -1): # @line L6
running = min(running, m * c * p[order[r]] / (r + 1)) # @line L7
adjusted[order[r]] = running
return reject, adjusted # @line L8
test_benjamini_yekutieli_procedure.py 149 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/benjamini-yekutieli-procedure/. The authors are listed in prov/HW5E27.jsonl.
import itertools
import math
import random
import statistics
from fractions import Fraction
import pytest
from benjamini_yekutieli_procedure import by, harmonic
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 bh_reference(p: list, q) -> list[bool]:
"""Benjamini-Hochberg as the largest self-consistent set: S = {i : m p_i <= s q} with |S| >= s, s largest."""
m = len(p)
for s in range(m, 0, -1):
chosen = [m * v <= s * q for v in p]
if sum(chosen) >= s:
return chosen
return [False] * m
def test_harmonic() -> None:
assert harmonic(4, exact=True) == Fraction(25, 12)
assert harmonic(15) == pytest.approx(3.318228993, abs=1e-9)
def test_worked_example_by_hand() -> None:
reject, adjusted = by(BH95, 0.05)
# Thresholds k * 0.05 / (15 * 3.3182) = k * 0.0010046: 0.0019 <= 0.0030 passes, and 0.0095 > 0.0040,
# ..., 0.0459 > 0.0090, 0.3240 > 0.0100 all fail, so the last passing rank is 3.
assert [i for i, r in enumerate(reject) if r] == [0, 1, 2]
c = harmonic(15)
assert adjusted[:4] == pytest.approx([15 * c * 0.0001, 15 * c * 0.0004 / 2, 15 * c * 0.0019 / 3, 15 * c * 0.0095 / 4])
def test_equals_bh_at_reduced_level() -> None:
rng = random.Random(2001)
for _ in range(400):
m = rng.randint(1, 12)
p = [Fraction(rng.randint(0, 200), 1000) for _ in range(m)]
q = Fraction(rng.randint(1, 20), 20)
reject, adjusted = by(p, q)
assert reject == bh_reference(p, q / harmonic(m, exact=True))
assert reject == [a <= q for a in adjusted]
def test_floats_agree_with_fractions() -> None:
rng = random.Random(3)
for _ in range(300):
m = rng.randint(1, 30)
p = [rng.random() ** 4 for _ in range(m)]
fp = [Fraction(v) for v in p]
# Random floats do not fall within rounding error of a threshold, so the decisions must agree.
assert by(p, 0.1)[0] == by(fp, Fraction(1, 10))[0]
def test_invalid_input() -> None:
assert by([], 0.1) == ([], [])
with pytest.raises(ValueError):
by([0.5], 1.5)
with pytest.raises(ValueError):
by([-0.1], 0.1)
def worst_case_law(m: int, q: Fraction) -> list[tuple[Fraction, list]]:
"""A joint law of m valid null p-values under which BH at level q has FDR exactly q (1 + 1/2 + ... + 1/m).
With probability q / k, choose k indices at random, set them to k q / m, and set the rest to 1.
With the remaining probability 1 - q c_m, set all to 1. Each marginal has P(p <= k q / m) = k q / m.
"""
law = []
for k in range(1, m + 1):
subsets = list(itertools.combinations(range(m), k))
for s in subsets:
law.append((q / k / len(subsets), [k * q / m if i in s else Fraction(1) for i in range(m)]))
rest = 1 - q * harmonic(m, exact=True)
assert rest >= 0
law.append((rest, [Fraction(1)] * m))
return law
def exact_fdr(law, procedure, m0: int) -> Fraction:
total = Fraction(0)
for prob, p in law:
reject = procedure(p)
r = sum(reject)
if r:
total += prob * Fraction(sum(reject[:m0]), r)
return total
def test_bh_bound_is_attained_and_by_level_is_exact() -> None:
for m in range(1, 6):
q = Fraction(1, 4)
law = worst_case_law(m, q)
assert sum(w for w, _ in law) == 1
for i in range(m): # the marginals are valid and exact at the thresholds
for u in [Fraction(j, 40) for j in range(41)]:
assert sum(w for w, p in law if p[i] <= u) <= u
for k in range(1, m + 1):
assert sum(w for w, p in law if p[i] <= k * q / m) == k * q / m
c = harmonic(m, exact=True)
assert exact_fdr(law, lambda p: bh_reference(p, q), m) == q * c
# The same law built for level q / c makes BY at q reach FDR exactly q.
law_by = worst_case_law(m, q / c)
assert exact_fdr(law_by, lambda p: by(p, q)[0], m) == q
def test_bound_under_arbitrary_dependence_exactly() -> None:
"""Null p-values uniform on {1/n, ..., 1}, coupled through random permutations of one uniform index."""
rng = random.Random(7)
n = 24
for _ in range(300):
m = rng.randint(2, 6)
m0 = rng.randint(1, m)
q = Fraction(rng.randint(1, 6), 20)
perms = [rng.sample(range(1, n + 1), n) for _ in range(m)]
alt = [Fraction(rng.randint(0, n), 4 * n) for _ in range(m - m0)]
law = []
for u in range(n):
nulls = [Fraction(perms[i][u], n) for i in range(m0)]
noise = [min(Fraction(1), a + Fraction(perms[m0 + j][u], 8 * n)) for j, a in enumerate(alt)]
law.append((Fraction(1, n), nulls + noise))
c = harmonic(m, exact=True)
assert exact_fdr(law, lambda p: by(p, q)[0], m0) <= Fraction(m0, m) * q
assert exact_fdr(law, lambda p: bh_reference(p, q), m0) <= Fraction(m0, m) * q * c
def test_monte_carlo_independent() -> None:
"""Under independence BY is BH at q / c_m, so its FDR is exactly (m0/m) q / c_m."""
rng = random.Random(1165)
nd = statistics.NormalDist()
m, m0, q, reps = 20, 10, 0.2, 6000
total = 0.0
for _ in range(reps):
z = [rng.gauss(0, 1) + (3.0 if i >= m0 else 0.0) for i in range(m)]
reject, _ = by([nd.cdf(-v) for v in z], q)
r = sum(reject)
total += sum(reject[:m0]) / r if r else 0.0
target = m0 / m * q / harmonic(m)
# target = 0.0278; the false discovery proportion is in [0, 1] with mean target, so its standard deviation is
# below sqrt(target) = 0.167 and four standard errors are below 0.009.
assert abs(total / reps - target) < 0.009
assert math.isclose(target, 0.02779, abs_tol=1e-4)
History
Benjamini and Hochberg (1995) proved control of the FDR for independent test statistics. Benjamini and Yekutieli (2001) extended it to positive regression dependence on the subset of true nulls, which covers one-sided tests on positively correlated normal statistics, and showed that dividing the level by gives control under any dependence. Later work showed that this factor is the best possible for the linear thresholds, and Blanchard and Roquain placed the method in a family of dependence-free step-up rules.
References
- Yoav Benjamini and Daniel Yekutieli, The control of the false discovery rate in multiple testing under dependency, The Annals of Statistics 29(4) (2001), pages 1165 to 1188, the step-up procedure with constants k q / (m sum_(i=1..m) 1/i) and its FDR control under arbitrary dependence, and the PRDS condition for the plain procedure
- Yoav Benjamini and Yosef Hochberg, Controlling the false discovery rate, a practical and powerful approach to multiple testing, Journal of the Royal Statistical Society, Series B 57(1) (1995), pages 289 to 300, the linear step-up procedure that the Benjamini-Yekutieli procedure rescales, and the example with 15 p-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 HW5E27 Edit this page History Report an error Markdown