Hypothesis testing §
Hypothesis testing is the task of deciding whether a parameter lies in a specified set, based on observed data. It produces a binary decision (reject or fail to reject) with controlled error rates. It is the formal framework for making go/no-go decisions in science, quality control, and clinical trials.
Authoritative sources
Null and alternative hypotheses §
A test is defined by a partition of the parameter space:
A test function gives the probability of rejecting given data .
Details
Every test trades off two kinds of mistakes, and the whole theory is about controlling them:
- Type I error (false positive): rejecting when it is true. Probability — the size of the test.
- Type II error (false negative): failing to reject when is true. Probability for .
- Power: — the probability of correctly rejecting when . It is a function of the true , not a single number.
The asymmetry is deliberate: is the “status quo” hypothesis, and we require strong evidence to overturn it. This mirrors a criminal trial: = innocence, and a conviction requires proof beyond reasonable doubt (small ), at the cost of letting some guilty defendants go free (large ).
Worked example. A factory tests whether a machine is calibrated ( mm offset) against . With measurements of standard deviation , the test rejects when . Then exactly, and the power at is .
Example problem. In the factory test above, what is the power at ?
Solution
Under , (variance … more precisely ). Then
A small true offset is hard to detect with : the power is only about 17%. To raise power, increase — see the simulation below.
The Neyman–Pearson lemma §
The lemma is the theoretical foundation of all hypothesis testing: it identifies the single best test when both hypotheses are simple.
Lemma (Neyman–Pearson, 1933). For testing the simple null against the simple alternative , with densities and , the test that rejects when the likelihood ratio exceeds a threshold,
with chosen so that , is the most powerful test of size : no other size- test has higher power at .
Proof sketch. Let be the likelihood-ratio test and any other test of size . Consider the integral of over the sample space. By construction exactly where and where , so the integrand is nonnegative everywhere and
since . Hence has power at least as large. (Randomization on the boundary handles the case where no deterministic threshold achieves size exactly .)
Details
Worked example. Let with and . The likelihood ratio is
which is increasing in . So the most powerful test rejects for large : reject when . For , reject when , and the power is . No other size-0.05 test can do better at .
The lemma generalizes to composite alternatives through the likelihood ratio test and to composite nulls by taking the supremum over . Every classical test (z-test, t-test, chi-squared test) is either a likelihood-ratio test or an approximation to one.
Example problem. For with and , what does the Neyman–Pearson most powerful test look like?
Solution
The joint density ratio is
This is decreasing in , so the most powerful test rejects when is small (an exponential with rate 2 produces smaller sums). Choose with : since under , gives . The rejection region is — note it is not a “large statistic” test; the lemma tells you which direction to reject in.
Authoritative sources
p-value §
The p-value is the probability, under , of observing a test statistic as extreme or more extreme than the one observed:
Details
A small p-value indicates that the observed data would be unlikely if were true. The p-value is not the probability that is true. It is a tail probability computed under the assumption that holds.
Common practice: reject if (typically ). This is a decision rule, not a statement about the truth of .
The figure below shows the anatomy of a one-sided test: the null distribution of the statistic, the rejection region (red, area ), the critical value, the observed statistic, and the p-value (blue, the tail area beyond the observation).
Worked example. Testing vs. with . The test statistic is and the two-sided p-value is . With , , : , so — not significant at 5%, though a one-sided test would give (see One-sided vs. two-sided tests).
Example problem. A test statistic is standard normal under and the observed value is . What is the two-sided p-value, and would you reject at ?
Solution
Since , reject at the 5% level. Note the two-sided rule is equivalent to rejecting when ; here , consistent with the p-value conclusion.
One-sided vs. two-sided tests §
Before computing a p-value you must decide which departures from count as evidence. This choice fixes both the rejection region and the p-value formula:
- Two-sided (): reject for extreme values in either direction. Rejection region ; p-value — both tails.
- One-sided ( or ): reject only in the pre-declared direction. Rejection region ; p-value — one tail.
Details
When is each appropriate? A one-sided test is legitimate only when departures in the other direction would be practically meaningless or would lead to the same action (e.g., “is the new drug worse than placebo?” — if it is better, you would not switch). The direction must be chosen before seeing the data: choosing the side after observing the statistic doubles your effective Type I error rate, because a one-sided test at level rejects half as often as a two-sided test at the same level.
How the rejection region shifts. For the same with a normal statistic:
- Two-sided: reject when (two tails of 2.5% each).
- One-sided (upper): reject when (one tail of 5%).
The one-sided critical value is smaller, so a one-sided test is more powerful in the declared direction — but completely blind to an effect in the opposite direction. In the worked example above, is significant one-sided () but not two-sided ().
Worked example. Testing whether a new bearing has lower friction than the old one ( vs. ), with : the one-sided (lower-tail) p-value is , significant at 5%. The two-sided p-value would be , not significant. The one-sided test is appropriate here because higher friction would simply mean “keep the old bearing” — the same action as no difference.
Example problem. You observe in a test where was pre-registered. Is the result significant at ? What if had been two-sided?
Solution
One-sided: — not significant. Two-sided: — even less significant. Note that a one-sided test can never be less significant than the two-sided test on the same data (when the observed effect points in the declared direction); the gain here is a factor of 2 in the p-value, but is too small for either.
Interactive simulation: rejection region, p-value, and power §
The simulation below ties the concepts together for a one-sided z-test of vs. with observed and known . Vary the true effect , the sample size , and the significance level , and watch the null distribution, the rejection region, the p-value tail, and the power curve respond.
Likelihood ratio test §
The likelihood ratio statistic is
Under , where is the difference in dimensionality (Wilks’ theorem). The limiting distribution is covered on the Distributions page, and the asymptotic argument (a Taylor expansion of the log-likelihood around the MLE, combined with the CLT) is a direct application of Limit theorems.
Details
The likelihood ratio test (LRT) is a general-purpose test that works for composite hypotheses. It compares the best fit under the null to the best fit under the full model. It is the natural extension of the Neyman–Pearson lemma to composite hypotheses: when the alternative is composite, replacing by the supremum over (equivalently over , since ) yields a test that is asymptotically optimal.
Worked example. Testing vs. for with known . The LRT statistic is under . With , , : , compared to the critical value at — fail to reject, matching the two-sided z-test (, ).
The LRT is connected to Estimation: the numerator and denominator are both maximized likelihoods, i.e., MLEs under restricted and unrestricted parameter spaces.
Example problem. For (mean ), derive the LRT of vs. and give its large-sample form.
Solution
The unrestricted MLE is , so
i.e. , which is always and equals 0 when . Under and large , this is approximately by Wilks’ theorem, so reject when at .
Duality between tests and confidence intervals §
Hypothesis testing and Estimation are two views of the same computation:
Duality. A level- test of rejects if and only if lies outside the confidence set for .
Proof sketch. For each , let be the acceptance region. Invert it: define . Then
so is a confidence set, and by construction exactly when the test rejects. Conversely, any confidence set inverted the same way yields a level- test.
Details
Worked example. With , , , the 95% confidence interval for is
The two-sided z-test of does not reject (), consistent with the p-value computed earlier. Testing would reject, since is outside the interval — and indeed , .
This duality means every confidence interval is a family of tests, and every test is a family of confidence sets. It also clarifies interpretation: “the 95% CI contains 0” and “the p-value exceeds 0.05” are the same statement, not two independent pieces of evidence.
Example problem. A 99% confidence interval for a proportion is . At which significance levels does the test of reject?
Solution
Since is outside the 99% interval, the level- test rejects. The test also rejects at every for which the corresponding interval excludes 0.5 — i.e., for all up to the level where the interval first touches 0.5. The exact threshold is the p-value: , so the test rejects precisely when . The 99% interval excluding 0.5 tells us .
Multiple comparisons §
When testing hypotheses simultaneously, the family-wise error rate (FWER) inflates. Corrections:
- Bonferroni: reject if .
- Holm–Bonferroni: step-down procedure, uniformly more powerful than Bonferroni.
- Benjamini–Hochberg (FDR): controls the expected fraction of false discoveries.
Authoritative sources
Details
The multiple comparisons problem arises in genomics (testing millions of genes), multiple regression, and any setting with many simultaneous tests. With independent tests each at level , the probability of at least one false positive is , which is for and — the Bonferroni correction restores the family-wise rate to at the price of power.
The Benjamini–Hochberg procedure: order p-values , find the largest such that , and reject all . It controls the false discovery rate (false positives over rejections) rather than the probability of any false positive — a weaker but far more powerful guarantee, well suited to exploratory screening where some false leads are tolerable.
Worked example. Five p-values: 0.001, 0.008, 0.039, 0.041, 0.20, with , . Compare thresholds . The largest with is (, but ). BH rejects the two smallest p-values. Bonferroni would reject only one ().
Example problem. With independent tests at and no correction, what is the probability of at least one Type I error? What does Bonferroni require?
Solution
Almost certain. Bonferroni requires each individual test to use , restoring the family-wise rate to 0.05 but demanding far stronger evidence per test.
Quizz §
Quizz
Problem. A pharmaceutical company tests a new drug against a placebo. The response variable is (known variance). The null is (no effect) vs. . A sample of patients gives . (a) Compute the z-statistic and p-value. (b) Is the result significant at ? (c) What is the power at ?
Solution
(a) The test statistic is
The one-sided p-value is .
(b) Since , we reject at the 5% level. The drug shows a statistically significant positive effect.
(c) The power at is
Under , , so
The test has very high power to detect an effect of size 1. You can reproduce this with the interactive simulation above by setting , , .