Bonferroni Correction
Multiple Comparisons
Twenty tests at five per cent is not five per cent
Run one hypothesis test at the five per cent level and you have a one-in-twenty chance of a false positive. Run twenty independent tests the same way and the chance of at least one false positive is about sixty-four per cent. The Bonferroni correction fixes this in the simplest possible way: divide the family-wise error rate by the number of tests, and compare each p-value to that shrunk threshold instead of to alpha.
The elegance of the correction is that it makes no assumption about how the tests relate to each other. Whether your twenty tests are independent, perfectly correlated, or something in between, the bound holds. The price of that guarantee is conservatism โ often a great deal of conservatism โ and understanding exactly how much is the substance of this lesson.
- Controls the probability of making even one false positive across a family of tests.
- Requires no assumption about dependence between the tests.
- Simple, defensible, and frequently more conservative than the situation warrants.
The problem, quantified
Before the fix, the size of the problem is worth seeing directly. The probability of at least one false positive across m independent tests at level alpha is 1 โ (1 โ alpha)^m, which approaches one as m grows. This is the same arithmetic that makes a system with many independent failure points fail often, and it is why exploratory analyses that test everything produce findings that never replicate.
import numpy as np
import pandas as pd
from scipy import stats
alpha = 0.05
# Family-wise error rate without any correction
for m in [1, 5, 10, 20, 50, 100]:
fwer = 1 - (1 - alpha) ** m
print(f"m = {m:3d} tests -> P(at least one false positive) = {fwer:.3f}")
# Expected number of false positives under the complete null
print("\nExpected false positives if all nulls are true:")
for m in [10, 50, 100]:
print(f" m = {m}: {m * alpha:.1f} on average")
# Demonstrate with a simulation: all nulls true, count rejections
rng = np.random.default_rng(0)
rejections = []
for _ in range(5000):
pvals = rng.uniform(0, 1, size=20) # all nulls true
rejections.append((pvals < alpha).sum())
rejections = np.array(rejections)
print(f"\nSimulation, 20 true nulls at alpha=0.05:")
print(f" Mean false positives: {rejections.mean():.2f}")
print(f" P(at least one): {(rejections >= 1).mean():.3f}")
That last number is the one to remember. With twenty true nulls and no correction, roughly sixty-four per cent of studies will report at least one "significant" result that is pure noise. Any pipeline that runs many tests without addressing this is manufacturing findings.
The correction itself
The correction has two equivalent forms. Adjust the threshold by dividing alpha by m, or adjust each p-value by multiplying by m. The second form is more convenient because it produces corrected p-values that can be compared to the original alpha and reported directly.
The min with one matters in practice: a p-value of 0.03 multiplied by twenty becomes 0.6, which is fine, but the adjusted values must stay inside the valid probability range or downstream code that plots or filters them will misbehave.
# Bonferroni by hand
pvalues = np.array([0.001, 0.014, 0.032, 0.041, 0.048,
0.12, 0.27, 0.45, 0.61, 0.89])
m = len(pvalues)
alpha = 0.05
bonferroni_threshold = alpha / m
p_adjusted = np.minimum(m * pvalues, 1.0)
results = pd.DataFrame({
"test": [f"T{i+1}" for i in range(m)],
"p_raw": pvalues,
"p_bonferroni": p_adjusted,
"reject_raw": pvalues < alpha,
"reject_bonferroni": p_adjusted < alpha,
})
print(results.round(4).to_string(index=False))
print(f"\nPer-test threshold: {bonferroni_threshold:.4f}")
# The statsmodels implementation, which also handles the general case
try:
from statsmodels.stats.multitest import multipletests
reject, p_adj, _, _ = multipletests(pvalues, alpha=alpha, method="bonferroni")
print(f"statsmodels adjusted: {np.round(p_adj[:5], 4)}")
print(f"rejections: {reject.sum()} of {m}")
except ImportError:
print("Install statsmodels for multipletests; the manual version above is identical.")
Comparing the two rejection columns makes the cost visible: the raw analysis rejects four tests, the corrected one rejects two. Those two extra rejections were either worth guarding against or worth losing, and the answer depends entirely on what the tests were for.
Step-down procedures: Holm and Hochberg
Bonferroni treats every test identically, which is wasteful when the p-values differ substantially. The step-down and step-up procedures improve on it by allocating the error budget adaptively: small p-values get a more generous threshold, large ones a stricter one, while still controlling the family-wise error rate exactly.
| Procedure | Type | Controls | Power vs Bonferroni |
|---|---|---|---|
| Bonferroni | single step | FWER, any dependence | baseline |
| Holm | step-down | FWER, any dependence | uniformly at least as powerful |
| Hochberg | step-up | FWER, positive dependence | more powerful when dependence is positive |
| ล idรกk | single step | FWER, independence only | slightly more powerful, assumes independence |
from statsmodels.stats.multitest import multipletests
pvalues = np.array([0.0004, 0.0031, 0.012, 0.028, 0.041,
0.073, 0.15, 0.31, 0.52, 0.88])
m = len(pvalues)
alpha = 0.05
comparison = pd.DataFrame({"p_raw": pvalues})
for method in ["bonferroni", "holm", "sidak", "holm-sidak", "fdr_bh"]:
reject, p_adj, _, _ = multipletests(pvalues, alpha=alpha, method=method)
comparison[f"reject_{method}"] = reject
comparison[f"p_{method}"] = np.round(p_adj, 4)
print(comparison[["p_raw", "reject_bonferroni", "reject_holm",
"reject_sidak", "reject_fdr_bh"]].to_string(index=False))
# How many does each method keep?
for method in ["bonferroni", "holm", "sidak", "fdr_bh"]:
n = comparison[f"reject_{method}"].sum()
print(f"{method:<12} rejects {n} of {m}")
Holm's step-down procedure is the practical recommendation whenever family-wise control is required. It dominates Bonferroni in the precise sense that it rejects every hypothesis Bonferroni rejects and sometimes more, it makes no independence assumption, and it costs nothing to use. Reaching for plain Bonferroni in preference to Holm is usually habit rather than choice, and the habit is worth dropping.
Hochberg's step-up variant is more powerful still but requires the tests to be positively dependent, which holds in many real settings โ tests that share a control group, or correlated outcomes โ but not all. When dependence structure is unknown or mixed, Holm is the safe default.
When Bonferroni is too conservative
Conservatism is not free: it costs power, and at large m the per-test threshold becomes so small that only enormous effects can survive. Seeing the threshold collapse makes the trade-off concrete.
alpha = 0.05
print("Per-test threshold as the family grows:")
for m in [1, 5, 10, 20, 50, 100, 500, 1000]:
print(f" m = {m:5d}: alpha/m = {alpha/m:.6f}")
# What effect size is still detectable at that threshold?
from scipy.stats import norm
def min_detectable_d(m, n_per_group=50, alpha=0.05, power=0.80):
"""Rough minimum Cohen's d detectable with a two-sample test."""
z_alpha = norm.ppf(1 - alpha / (2 * m))
z_beta = norm.ppf(power)
return (z_alpha + z_beta) * np.sqrt(2 / n_per_group)
print("\nMinimum detectable Cohen's d (n=50 per group, power=0.8):")
for m in [1, 10, 50, 100]:
print(f" m = {m:4d}: d >= {min_detectable_d(m):.2f}")
# The simulation: power of Bonferroni vs Holm under a mix of true effects
rng = np.random.default_rng(123)
n_tests, n_true, n_per = 40, 5, 60
true_effects = np.zeros(n_tests)
true_effects[:n_true] = 0.5 # small-to-moderate effects
def one_study(pvals):
return {
"bonf": multipletests(pvals, method="bonferroni")[0].sum(),
"holm": multipletests(pvals, method="holm")[0].sum(),
"raw": (pvals < 0.05).sum(),
}
hits = {"bonf": 0, "holm": 0, "raw": 0}
for _ in range(2000):
pvals = []
for d in true_effects:
a = rng.normal(0, 1, n_per)
b = rng.normal(d, 1, n_per)
pvals.append(stats.ttest_ind(a, b).pvalue)
r = one_study(np.array(pvals))
for k in hits:
hits[k] += min(r[k], n_true) # count true discoveries only
print(f"\nTrue positives found out of {n_true} real effects, 2000 studies:")
for k, v in hits.items():
print(f" {k:<5}: {v/2000:.2f} per study on average")
The simulation is the honest picture: Bonferroni finds fewer of the real effects than Holm at the same error control, and the gap widens as the family grows. For exploratory screens with hundreds of tests, even Holm is usually the wrong tool, and a false-discovery-rate procedure such as Benjamini-Hochberg is the appropriate family of methods โ a different error criterion, not a weaker version of the same one.
Defining the family
The correction's guarantee is only as meaningful as the definition of m, and this is where most real-world arguments happen. A family is the set of tests among which you want the probability of any false positive to be controlled, and the right boundary comes from the decisions the tests support, not from the convenience of the analysis.
- A single experiment with several pairwise comparisons is one family: three drugs against one control, three tests.
- A pre-registered primary endpoint with secondary endpoints is usually two families, each corrected within itself, with the hierarchy stated in advance.
- A genome-wide screen is one family of hundreds of thousands, which is why that field invented its own thresholds rather than using alpha over m.
- Two completely independent studies are two families; correcting across both would be theatre.
# Two families analysed separately, each with its own correction
study_a_p = np.array([0.002, 0.018, 0.044]) # three doses vs control
study_b_p = np.array([0.03, 0.22, 0.41, 0.55]) # four secondary endpoints
for name, pvals in [("Study A (primary)", study_a_p),
("Study B (secondary)", study_b_p)]:
reject, p_adj, _, _ = multipletests(pvals, alpha=0.05, method="holm")
print(f"\n{name}: m = {len(pvals)}")
for i, (raw, adj, rej) in enumerate(zip(pvals, p_adj, reject), 1):
flag = "REJECT" if rej else "keep null"
print(f" Test {i}: raw p = {raw:.3f}, adjusted = {adj:.3f} [{flag}]")
# Sensitivity: what if the family had been defined one size larger?
pvals = np.array([0.002, 0.018, 0.044, 0.09])
for m_used in [3, 4]:
thresh = 0.05 / m_used
print(f"\nUsing m = {m_used}: threshold = {thresh:.4f}, "
f"third test rejects? {0.044 < thresh}")
The sensitivity example is worth pausing on: the third test rejects under m = 3 and fails under m = 4. Whether a finding survives therefore depends on a decision made before the data were seen, which is exactly why the family definition belongs in the pre-registration or analysis plan rather than in the moment of writing up.
Reporting results
A corrected analysis must say what was corrected, how many tests were in the family, and which procedure was used. Reporting only the adjusted p-values without that context leaves the reader unable to reconstruct the error control, and reporting only the raw values alongside a sentence that "Bonferroni was applied" leaves them unable to check it.
# A reporting template that keeps everything auditable
pvalues = np.array([0.0012, 0.0089, 0.021, 0.037, 0.15])
labels = ["dose_10mg", "dose_20mg", "dose_40mg", "biomarker_a", "biomarker_b"]
alpha, method = 0.05, "holm"
reject, p_adj, _, _ = multipletests(pvalues, alpha=alpha, method=method)
report = pd.DataFrame({
"comparison": labels,
"p_raw": pvalues,
"p_adjusted": np.round(p_adj, 4),
"significant": reject,
"effect_size_d": [0.62, 0.48, 0.35, 0.21, 0.09], # report these too
})
print(report.to_string(index=False))
print(f"\nFamily: {len(pvalues)} comparisons, method: {method}, alpha: {alpha}")
# Always pair adjusted significance with effect sizes
sig = report[report["significant"]]
if len(sig):
smallest = sig["effect_size_d"].min()
print(f"Smallest significant effect size: d = {smallest:.2f}")
if smallest < 0.2:
print("Note: statistically significant but trivially small; interpret carefully.")
The effect-size column is the safeguard against a subtler failure mode. With a large enough sample, every tiny difference becomes significant under any correction, and a table of adjusted p-values with no magnitudes invites exactly that misreading. Significance answers whether a difference exists; the effect size answers whether anyone should care.
Mistakes that make the correction ineffective
Common Mistakes
Choosing m to be smaller than the tests actually run
Fix: Count every test that could have supported the same claim, including ones never reported.
Applying the correction after seeing the p-values
Fix: Fix the family and the method before analysis, or the correction is decorative.
Correcting across genuinely separate studies
Fix: Define families by the decisions they inform; two independent studies are two families.
Using plain Bonferroni when Holm is available
Fix: Holm controls the same error rate and is never less powerful.
Reporting adjusted p-values without the method and m
Fix: State the procedure, the family size, and the alpha so the control is verifiable.
Treating corrected significance as evidence of importance
Fix: Pair every adjusted p-value with an effect size and a confidence interval.
Applying family-wise control to a genome-scale screen
Fix: Use a false-discovery-rate procedure when the family runs into the hundreds or thousands.
Forgetting that dependencies make some procedures invalid
Fix: Holm works under any dependence; Hochberg and ล idรกk require assumptions you may not be able to defend.
Practices that keep the correction honest
Best Practices
- Define the family from the decisions the tests support, in advance.
- Default to Holm's step-down procedure for family-wise control.
- Report raw p-values, adjusted p-values, the method, and m together.
- Pair significance with effect sizes and confidence intervals in every table.
- Switch to false-discovery-rate control when the family is very large.
- Document the family definition in the pre-registration or analysis plan.
- Run a sensitivity check: would the conclusion survive a family one size larger?
- Treat non-significance under a harsh correction as inconclusive rather than as evidence of no effect.
Key takeaways
Key Takeaways
- Multiple testing inflates the chance of at least one false positive; with twenty tests it reaches about sixty-four per cent.
- Bonferroni divides alpha by m, giving a guarantee that holds under any dependence structure.
- The adjusted p-value form, min(m times p, 1), is what gets reported.
- Holm's step-down procedure is uniformly more powerful and equally valid; prefer it.
- The definition of m is a scientific decision, not a bookkeeping detail, and it belongs in the plan.
- Family-wise control becomes impractical at large m, where false-discovery-rate methods take over.
- Adjusted significance without an effect size invites findings nobody should act on.
Where to go next
- Multiple Testing Problem โ the broader problem this lesson solves.
- False Discovery Rate โ the alternative error criterion for large families.
- P-Values โ what the values being adjusted actually mean.
- Effect Size โ the magnitude that corrections cannot measure for you.