Overview
Every test can raise a false alarm, rejecting a null hypothesis that is in fact true. The significance level is the rate of false alarms you agree to tolerate, chosen before looking at the data. It fixes a cutoff, the critical value: statistics beyond it are rare enough under the null that you reject. With , a true null is rejected in about 1 experiment in 20. That rate applies per test. Run many tests and the chance that at least one raises a false alarm climbs quickly, so must be split across them. Bonferroni and Sidak are two standard ways to do the split.
A short history
Ronald Fisher proposed in 1925 that a result be called significant when its p-value falls below 0.05, about two standard deviations for a normal statistic, and treated this as a convenient guide. Jerzy Neyman and Egon Pearson made the level a formal design choice in 1933: alpha is fixed in advance as the accepted rate of false rejections. The convention of 0.05 has been questioned repeatedly, including a 2018 proposal to lower it to 0.005 for new discoveries.
How it works
- Choose before collecting data, weighing the cost of a false alarm against the cost of a miss.
- If the test is one of a family of tests, adjust: Bonferroni uses , Sidak uses .
- Convert the adjusted level into critical values from the null distribution, or , in one tail or split over two.
- Reject when the statistic falls outside the critical values, or equally when the p-value is below the adjusted level.
- Check the rule by simulation: on data where the null is true, the share of rejections should be close to .
Watch out for
- Choosing after seeing the p-value turns the test into a formality, because the threshold can always be moved to give the answer wanted.
- The value 0.05 is a convention, not a law. A safety decision may need a stricter level and an exploratory screen a looser one.
- Lowering reduces false alarms but raises the miss rate at a fixed sample size, so a very strict level can make a real effect undetectable.
- The Sidak formula and the family-wise rate assume independent tests. Bonferroni holds under any dependence but is slightly more conservative.
Use cases
When to use it
Setting the decision rule for any hypothesis test, and adjusting that rule when several tests are run together so the overall false alarm rate stays where you set it.
In industry
- Particle physics
- Physicists require five standard deviations, a one sided level of about 3 in 10 million, before announcing a discovery such as the Higgs boson in 2012.
- Clinical trials
- Confirmatory drug trials conventionally use a two sided level of 0.05, which regulators treat as 0.025 in the favourable direction.
- Genomics
- Genome wide association studies use 5 times 10 to the minus 8, since about a million independent variants are tested.
Choosing it: what must hold
- A choice made before the data are seen, and recorded.
- A judgement of how costly a false alarm is compared with a missed effect.
- A sample size planned so that the test still has adequate power at the chosen level.
- Adjustment when several tests are run, so that the overall false alarm rate stays where you set it.
When to choose something else
| If | Use instead |
|---|---|
| A false positive is very costly or many tests are run | A stricter level, or a multiple comparison correction such as Bonferroni |
| You prefer to report strength of evidence over a pass or fail verdict | The exact p-value with a confidence interval |
| Costs of both error types can be stated explicitly | A decision analysis that weighs Type I and Type II errors |
Math foundations
Definition
The significance level is the probability of a Type I error, a false rejection. You choose it. The data do not determine it.
Critical values
is the quantile of the null distribution with probability below it. A two-sided test splits evenly between the tails. For the standard normal at the cutoffs are two-sided and one-sided.
Family-wise error rate
For independent tests of true nulls, each at level . Each test avoids a false alarm with probability , and all must avoid it for the family to be clean.
Bonferroni correction
Test each hypothesis at . The bound follows because the chance of a union of events is at most the sum of their chances, so it holds whether or not the tests are independent.
Sidak correction
Solve the family-wise formula for the per-test level that makes the rate exactly under independence. It is slightly larger than , so slightly more powerful.
Symbols
- significance level of one test, or the target rate for the family
- the null hypothesis
- the test statistic
- quantile of the null distribution at probability u
- number of tests in the family, n_tests in the template
- per-test level after Bonferroni or Sidak correction
- family-wise error rate
Worked by hand
Ten independent tests, each of a true null hypothesis, with a target of .
Without correction there is a 40% chance of at least one false alarm. Bonferroni brings it to 4.89%, a little under target, and Sidak to exactly 5%.
Visual example
Loading the example.
Try this
- Slide α from 0.01 to 0.2 and count how many null experiments turn into false alarms.
- Set the tests per study to 10 with no correction: about 40% of studies report something.
- Now choose Bonferroni or Sidak and compare the two family rates with the target α.
Code sample
from impl import SignificanceLevel
from config import SignificanceLevelConfig
rule = SignificanceLevel(SignificanceLevelConfig(alpha=0.05, distribution="t", df=10))
print(rule.critical_values()) # (-2.228, 2.228)
print(rule.rejects(2.5), rule.decide(p_value=0.031))
many = SignificanceLevel(SignificanceLevelConfig(alpha=0.05, correction="bonferroni", n_tests=5))
print(many.adjusted_alpha(), many.familywise_error_rate())Read the implementation (164 lines)
"""Significance level: what alpha means, the rejection region it defines, and how to share it across tests.
NumPy and the standard library only. Normal and Student t quantiles are computed in this file (the t
distribution through the regularized incomplete beta function, quantiles by bisection).
"""
from __future__ import annotations
import math
import numpy as np
try:
from .config import SignificanceLevelConfig
except ImportError: # run from the template's own folder
from config import SignificanceLevelConfig
def _betacf(a: float, b: float, x: float) -> float:
"""Continued fraction of the incomplete beta function (modified Lentz method)."""
tiny = 1e-300
qab, qap, qam = a + b, a + 1.0, a - 1.0
c = 1.0
d = 1.0 - qab * x / qap
d = 1.0 / (d if abs(d) > tiny else tiny)
h = d
for m in range(1, 2000):
m2 = 2 * m
for aa in (
m * (b - m) * x / ((qam + m2) * (a + m2)),
-(a + m) * (qab + m) * x / ((a + m2) * (qap + m2)),
):
d = 1.0 + aa * d
d = 1.0 / (d if abs(d) > tiny else tiny)
c = 1.0 + aa / c
c = c if abs(c) > tiny else tiny
delta = d * c
h *= delta
if abs(delta - 1.0) < 1e-15:
break
return h
def betainc(a: float, b: float, x: float) -> float:
"""Regularized incomplete beta function I_x(a, b), for a, b > 0 and 0 <= x <= 1."""
if x <= 0.0:
return 0.0
if x >= 1.0:
return 1.0
front = math.exp(
math.lgamma(a + b) - math.lgamma(a) - math.lgamma(b) + a * math.log(x) + b * math.log1p(-x)
)
if x < (a + 1.0) / (a + b + 2.0):
return front * _betacf(a, b, x) / a
return 1.0 - front * _betacf(b, a, 1.0 - x) / b
def norm_cdf(z: float) -> float:
"""P(Z <= z) for a standard normal Z."""
return 0.5 * math.erfc(-z / math.sqrt(2.0))
def norm_sf(z: float) -> float:
"""P(Z > z) for a standard normal Z (the upper tail)."""
return 0.5 * math.erfc(z / math.sqrt(2.0))
def t_cdf(t: float, df: float) -> float:
"""P(T <= t) for Student's t with `df` degrees of freedom."""
tail = 0.5 * betainc(0.5 * df, 0.5, df / (df + t * t))
return 1.0 - tail if t > 0 else tail
def t_sf(t: float, df: float) -> float:
"""P(T > t) for Student's t with `df` degrees of freedom."""
return t_cdf(-t, df)
def _bisect(fn, lo: float, hi: float) -> float:
"""Root of the increasing function `fn` on [lo, hi], by bisection."""
for _ in range(100):
mid = 0.5 * (lo + hi)
if fn(mid) < 0.0:
lo = mid
else:
hi = mid
return 0.5 * (lo + hi)
def norm_ppf(p: float) -> float:
"""Quantile of the standard normal: the z with P(Z <= z) = p, for 0 < p < 1."""
if not 0.0 < p < 1.0:
raise ValueError(f"p must be in (0, 1), got {p}")
if p > 0.5:
return -norm_ppf(1.0 - p)
return _bisect(lambda z: norm_cdf(z) - p, -40.0, 0.0)
def t_ppf(p: float, df: float) -> float:
"""Quantile of Student's t: the t with P(T <= t) = p, for 0 < p < 1."""
if not 0.0 < p < 1.0:
raise ValueError(f"p must be in (0, 1), got {p}")
if p > 0.5:
return -t_ppf(1.0 - p, df)
lo = -1.0
while t_cdf(lo, df) > p:
lo *= 2.0
return _bisect(lambda t: t_cdf(t, df) - p, lo, 0.0)
class SignificanceLevel:
"""Turns alpha into a decision rule for a z or t statistic."""
def __init__(self, config: SignificanceLevelConfig | None = None) -> None:
self.config = config or SignificanceLevelConfig()
def adjusted_alpha(self) -> float:
"""The per-test alpha after the configured multiple-testing correction."""
c = self.config
if c.correction == "bonferroni":
return c.alpha / c.n_tests
if c.correction == "sidak":
return 1.0 - (1.0 - c.alpha) ** (1.0 / c.n_tests)
return c.alpha
def _quantile(self, p: float) -> float:
return norm_ppf(p) if self.config.distribution == "z" else t_ppf(p, self.config.df)
def critical_values(self) -> tuple[float, float]:
"""(lower, upper) bounds of the acceptance region; the statistic rejects when it falls outside.
For a one-sided alternative the unused bound is -inf or +inf.
"""
a = self.adjusted_alpha()
if self.config.alternative == "two-sided":
upper = self._quantile(1.0 - a / 2.0)
return -upper, upper
if self.config.alternative == "greater":
return -math.inf, self._quantile(1.0 - a)
return self._quantile(a), math.inf
def rejects(self, statistic: float) -> bool:
"""True when the test statistic lies in the rejection region."""
lower, upper = self.critical_values()
return statistic < lower or statistic > upper
def decide(self, p_value: float) -> bool:
"""True (reject the null hypothesis) when the p-value is below the adjusted alpha."""
if not 0.0 <= p_value <= 1.0:
raise ValueError(f"p_value must be in [0, 1], got {p_value}")
return p_value < self.adjusted_alpha()
def familywise_error_rate(self) -> float:
"""Chance of at least one false rejection among `n_tests` independent true nulls: 1 - (1 - a)^m,
where a is the adjusted per-test alpha."""
return 1.0 - (1.0 - self.adjusted_alpha()) ** self.config.n_tests
def simulate_false_positive_rate(self, n: int = 20, trials: int = 5000, seed: int = 0) -> float:
"""Share of true-null experiments that the rule rejects; it should come out close to alpha.
Each trial draws n standard normal values (true mean 0) and tests "mean = 0" with the configured
statistic: z uses the known standard deviation 1, t uses the sample standard deviation and needs
`df` = n - 1.
"""
if self.config.distribution == "t" and abs(self.config.df - (n - 1)) > 1e-9:
raise ValueError("for the t statistic, df must equal n - 1")
rng = np.random.default_rng(seed)
x = rng.normal(size=(trials, n))
scale = 1.0 if self.config.distribution == "z" else x.std(axis=1, ddof=1)
stats = x.mean(axis=1) / (scale / math.sqrt(n))
lower, upper = self.critical_values()
return float(np.mean((stats < lower) | (stats > upper)))- Repository
- Not published yet
- Needs
- Python 3.10 and NumPy
- Tests
- 7, run with
python3 -m unittest -v
Practice
Create SignificanceLevel() and read critical_values(), then call simulate_false_positive_rate() and compare the result with 0.05. Next use SignificanceLevelConfig(correction="bonferroni", n_tests=10) and compare adjusted_alpha(), critical_values() and familywise_error_rate() with the worked example, and repeat with correction="sidak".
Check on learning
- A lab runs 20 independent tests of effects that do not exist, each at , and publishes whichever is significant. How likely is it that it has something to publish?
A way to think about it
Use the family-wise formula with . Then consider what a reader who sees only the one published test would wrongly assume.
- Why is the one-sided critical value (1.645) closer to zero than the two-sided one (1.96) at the same , and what do you give up for the easier cutoff?
A way to think about it
Both rules put a total of 5% in the rejection region. See where each puts it, and what happens if the effect goes the other way.
- Bonferroni guarantees the family-wise rate under any dependence, yet it is called conservative. In what situation is it most wasteful?
A way to think about it
Imagine ten tests that are nearly copies of each other. How many independent chances of a false alarm are there really?
- If
simulate_false_positive_rateis run with the rule on data whose true standard deviation is 1.5 instead of 1, would the rate be above or below ?A way to think about it
The statistic divides by the assumed standard deviation. If the real spread is larger, see what happens to the spread of the statistic relative to the fixed cutoffs.