Hypothesis Testing
A/B test results arrive with a -value; a regulator asks for “statistical significance”; a paper claims an effect is “not significant, therefore absent”. All three usages rest on a definition that is usually misstated. This page defines testing precisely, proves the theorem that determines when a test is optimal, and derives confidence sets from tests by duality; so the -value’s meaning can be read off a definition rather than remembered wrongly.
The prerequisite is decision theory: a test is a decision rule whose action space has two elements, and its errors are priced by two risks that cannot be minimised simultaneously.
Intuition
Section titled “Intuition”A test is a filter with two failure modes. Reject a true hypothesis; the false positive; or fail to reject a false one; the false negative. The Neyman–Pearson framework fixes the false-positive rate by design (the significance level) and then asks for the test that minimises false negatives. That inversion is the whole intellectual move: you do not choose a test that is “good overall”; you choose the error rate you can afford and then demand optimality subject to it.
1. The framework
Section titled “1. The framework”Definition. A hypothesis test specifies a null , an alternative , and a rejection region : reject iff .
Definition. The size of the test is ; the worst-case false positive rate under the null. The power at is .
Two properties, and the whole subject is their trade-off. Size controls how often the filter cries wolf; power measures how often it catches the signal. Both depend on , and a test with good power at one alternative can be blind at another.
Definition. A test is uniformly most powerful (UMP) at level if it has size at most and its power is at least that of every other level- test, for every .
2. The Neyman–Pearson lemma
Section titled “2. The Neyman–Pearson lemma”Theorem (Neyman–Pearson). For testing the simple null against the simple alternative , the test that rejects when the likelihood ratio ; with randomisation on the boundary to hit the level exactly; is most powerful among all level- tests.
Proof. Let be the likelihood-ratio region, with (choosing and the boundary randomisation to make this hold). Let be any other region with . Then
On we have , so ; on , , so . Splitting the integral on those two parts:
using . Hence for every competing level- .
The proof is one inequality applied twice, and the structure to remember is: the likelihood ratio orders the evidence, and the optimal test is a threshold on that order. Everything else in testing; LRTs, score tests, Wald tests, most of applied practice; is the attempt to use this test when is not a single point.
Corollary (UMP for one-sided alternatives). For one-parameter exponential families with increasing; the normal with known variance, Bernoulli, Poisson; the test rejecting for large is UMP for against .
Why UMP fails for two-sided alternatives. Consider the normal with known , testing against . The Neyman–Pearson most powerful test against the specific alternative rejects for large ; against it rejects for small . A two-sided test must spend its on both tails and is therefore less powerful than either one-sided test against that side’s alternative; so no UMP test exists. The demand “most powerful against everything” is unmeetable, and unbiasedness or invariance are the standard restrictions that restore existence.
3. Likelihood ratio tests
Section titled “3. Likelihood ratio tests”For composite hypotheses, the practical test is the likelihood ratio test: reject for small values of
Theorem (Wilks). Under regularity, when is true and specifies constraints, .
Proof sketch. Write for the unrestricted MLE and for the constrained one. Taylor-expanding the log-likelihood about and using that the score vanishes at the MLE:
with the Fisher information matrix, and is asymptotically Gaussian with covariance the inverse information on the constrained coordinates. The quadratic form then converges to a chi-squared with degrees of freedom by the definition of the multivariate normal’s quadratic form.
Wilks’ theorem is the reason a single table serves every likelihood ratio test: the null distribution of the test statistic is asymptotically parameter-free. The same asymptotic chi-squared appears for the Wald test (based on ) and the score test (based on ), all three asymptotically equivalent; they differ in finite samples and in which computation they require.
4. What a -value is
Section titled “4. What a ppp-value is”Definition. For observed data , the -value of the test statistic against is
the probability, computed under the least favourable null parameter, of seeing a result at least as extreme as the one observed.
Read the definition against the common errors:
- A -value is not the probability that is true. is fixed, not random, in the supremum; no probability statement about is being made. (That statement is a posterior, and needs a prior; page 5.)
- A -value is not the probability of the result being “due to chance”. It is a tail probability under a model.
- A large -value is not evidence for . The test was designed so that large -values occur under with high probability; failing to reject is the designed default, not a finding. Absence of evidence is not evidence of absence; and quantifying the latter requires power analysis, not the -value.
- A -value is not a measure of effect size. A tiny -value with a huge accompanies a negligible effect; the effect size and its interval are the scientific content.
Why the threshold is a design decision. is a convention, and its meaning is “we accept a 1-in-20 false positive rate”. A field testing thousands of hypotheses at expects of its true-null results to be “significant”; the multiple-testing problem, whose fixes (Bonferroni, false discovery rate control) are corrections to this design decision.
5. Confidence sets by duality
Section titled “5. Confidence sets by duality”Theorem (test–confidence duality). For each , let be the acceptance region of a level- test of . Then
is a confidence set: for every .
Proof. Fix and let be observed. Then
the last step being exactly the size condition of the test at .
The duality is not an analogy: a confidence set is the set of parameter values that would not be rejected by the corresponding test. “The 95% interval for the mean” and “the mean values the 5% test accepts” are the same object; which is why inverting a two-sided -test gives the familiar .
What the coverage statement means. is a probability over repeated draws of at fixed . For the observed , the realised set either contains or does not - there is no probability left. Reporting “there is a 95% chance the true value is in this interval” commits the very error the definition forbids; the correct reading is “this procedure covers 95% of the time it is used”.
6. The bootstrap
Section titled “6. The bootstrap”When the null distribution of is intractable, resample. The bootstrap draws resamples of size with replacement from the observed data, computes on each, and uses the empirical distribution of the -values in place of the unknown null distribution.
Why it works (one sentence, honestly). The empirical distribution converges uniformly to the true one at rate by the Glivenko–Cantelli theorem, so the plug-in distribution of converges to the true distribution of - with the bootstrap’s error one order of smaller than the naive normal approximation for smooth statistics.
The bootstrap is not a free lunch: it fails for extremes (maxima), for heavy tails where the mean is unstable, and for statistics that depend on the underlying density’s smoothness. It is an approximation to the sampling distribution, and it inherits every hypothesis of the estimator being resampled.
7. The code: the Neyman–Pearson structure, then a bootstrap
Section titled “7. The code: the Neyman–Pearson structure, then a bootstrap”Python; the UMP test’s exact power, against its normal approximation.
import numpy as npfrom scipy import stats
rng = np.random.default_rng(2026)n, alpha = 40, 0.05
# H0: theta = 0.5 vs H1: theta > 0.5, Bernoulli.# UMP test: reject for large sum(X). Exact level from the Binomial null.crit = stats.binom.isf(alpha, n, 0.5)print(f"rejection region: sum > {crit} (exact level " f"{stats.binom.sf(crit, n, 0.5):.4f})")
# Exact power at a range of alternatives -- binomial, not normal.for th in [0.5, 0.6, 0.7, 0.8]: power = stats.binom.sf(crit, n, th) normal = 1 - stats.norm.cdf((crit + 0.5 - n*th) / np.sqrt(n*th*(1-th))) print(f"theta = {th:.1f}: exact power = {power:.4f}, " f"normal approx = {normal:.4f}")# The normal approximation is good near theta = 0.5 and degrades toward# the boundary theta = 1 -- where the binomial is most skewed.R; a permutation test, the bootstrap’s sibling.
set.seed(2026)a <- c(12.9, 13.5, 12.8, 15.6, 17.2, 19.2, 12.6, 15.3, 14.4, 11.3)b <- c(12.7, 13.6, 12.0, 15.2, 16.8, 20.0, 12.0, 15.9, 16.0)observed <- mean(b) - mean(a)
# Permute group labels: under H0 the labels are exchangeable, so the# permutation distribution of the difference IS its null distribution.diffs <- replicate(20000, { z <- sample(c(a, b)); mean(z[1:length(a)]) - mean(z[-(1:length(a))])})p_perm <- mean(abs(diffs) >= abs(observed))p_t <- t.test(b, a)$p.valuecat(sprintf("permutation p = %.4f t-test p = %.4f\n", p_perm, p_t))# The two agree closely: for near-normal data the t-test is the parametric# shadow of the permutation test -- and the permutation test makes no# normality assumption at all.Common Pitfalls
Section titled “Common Pitfalls”- Stating the alternative after seeing the data. The level is a guarantee under the null for a pre-registered test; switching the tail or the hypothesis after looking doubles or triples the realised false positive rate.
- Believing “not significant” means “no effect”. It means the test did not reject. Report the confidence interval: a interval and a interval are both non-significant at the same data size, and they are scientifically opposite findings.
- Confusing the p-value with the posterior. ; the quantity a decision-maker wants is , which requires a prior and Bayes’ rule. The two are related through a base rate the -value knows nothing about.
- Repeating the test as data accumulates. Each peek is a fresh 5% chance; testing at every interim doubles the realised level to roughly 8% at two peeks and 14% at five. Sequential designs exist and are the fix.
- Bootstrapping maxima, or heavily skewed estimators, without thought. The bootstrap’s guarantee is for smooth statistics of a distribution it can approach; outside that regime the error order degrades.
Cross-References
Section titled “Cross-References”- Statistical Decision Theory; the zero–one loss of which size and power are the two coordinates.
- Measure-Theoretic Probability; the binomial and normal laws the tests run on.
- Estimation Theory; the MLE whose likelihood ratio Wilks’ theorem asymptotics.
- Bayesian Inference and Computation; the posterior, which answers the question the -value cannot.
- Statistical Learning Theory; generalisation bounds as multiple-testing corrections.