Technopedia

The technologist’s encyclopedia

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:

H0:θ∈Θ0vs.H1:θ∈Θ1H_0: \theta \in \Theta_0 \quad \text{vs.} \quad H_1: \theta \in \Theta_1

A test function φ(x)∈[0,1]\varphi(x) \in [0,1] gives the probability of rejecting H0H_0 given data xx.

Details

Every test trades off two kinds of mistakes, and the whole theory is about controlling them:

The asymmetry is deliberate: H0H_0 is the “status quo” hypothesis, and we require strong evidence to overturn it. This mirrors a criminal trial: H0H_0 = innocence, and a conviction requires proof beyond reasonable doubt (small α\alpha), at the cost of letting some guilty defendants go free (large β\beta).

Worked example. A factory tests whether a machine is calibrated (H0:μ=0H_0: \mu = 0 mm offset) against H1:μ≠0H_1: \mu \neq 0. With n=25n = 25 measurements of standard deviation σ=0.1\sigma = 0.1, the test rejects when ∣Xˉ∣>1.96×0.1/5=0.0392|\bar{X}| > 1.96 \times 0.1/5 = 0.0392. Then α=0.05\alpha = 0.05 exactly, and the power at μ=0.05\mu = 0.05 is 1−β=P(∣Xˉ∣>0.0392∣μ=0.05)≈0.611 - \beta = P(|\bar{X}| > 0.0392 \mid \mu = 0.05) \approx 0.61.

Example problem. In the factory test above, what is the power at μ=0.02\mu = 0.02?

Solution

Under μ=0.02\mu = 0.02, Xˉ∼N(0.02,0.022)\bar{X} \sim N(0.02, 0.02^2) (variance σ2/n=0.012\sigma^2/n = 0.01^2… more precisely σ/n=0.02\sigma/\sqrt{n} = 0.02). Then

1−β=P ⁣(Xˉ>0.0392)+P ⁣(Xˉ<−0.0392)=Φ ⁣(−0.0392−0.020.02)+1−Φ ⁣(0.0392−0.020.02)1 - \beta = P\!\left(\bar{X} > 0.0392\right) + P\!\left(\bar{X} < -0.0392\right) = \Phi\!\left(\frac{-0.0392 - 0.02}{0.02}\right) + 1 - \Phi\!\left(\frac{0.0392 - 0.02}{0.02}\right) =Φ(−2.96)+1−Φ(0.96)≈0.0015+0.169≈0.17= \Phi(-2.96) + 1 - \Phi(0.96) \approx 0.0015 + 0.169 \approx 0.17

A small true offset is hard to detect with n=25n = 25: the power is only about 17%. To raise power, increase nn — 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 H0:θ=θ0H_0: \theta = \theta_0 against the simple alternative H1:θ=θ1H_1: \theta = \theta_1, with densities f0f_0 and f1f_1, the test that rejects when the likelihood ratio exceeds a threshold,

φ(x)={1if f1(x)/f0(x)>k0if f1(x)/f0(x)<k\varphi(x) = \begin{cases} 1 & \text{if } f_1(x) / f_0(x) > k \\ 0 & \text{if } f_1(x) / f_0(x) < k \end{cases}

with kk chosen so that Eθ0[φ]=αE_{\theta_0}[\varphi] = \alpha, is the most powerful test of size α\alpha: no other size-α\alpha test has higher power at θ1\theta_1.

Proof sketch. Let φ∗\varphi^* be the likelihood-ratio test and φ\varphi any other test of size ≤α\leq \alpha. Consider the integral of (φ∗−φ)(f1−kf0)(\varphi^* - \varphi)(f_1 - k f_0) over the sample space. By construction φ∗=1\varphi^* = 1 exactly where f1>kf0f_1 > k f_0 and 00 where f1<kf0f_1 < k f_0, so the integrand is nonnegative everywhere and

Eθ1[φ∗]−Eθ1[φ]  ≥  k (Eθ0[φ∗]−Eθ0[φ])  ≥  0E_{\theta_1}[\varphi^*] - E_{\theta_1}[\varphi] \;\geq\; k\,\big(E_{\theta_0}[\varphi^*] - E_{\theta_0}[\varphi]\big) \;\geq\; 0

since Eθ0[φ∗]=α≥Eθ0[φ]E_{\theta_0}[\varphi^*] = \alpha \geq E_{\theta_0}[\varphi]. Hence φ∗\varphi^* has power at least as large. (Randomization on the boundary f1=kf0f_1 = k f_0 handles the case where no deterministic threshold achieves size exactly α\alpha.)

Details

Worked example. Let X∼N(θ,1)X \sim N(\theta, 1) with θ0=0\theta_0 = 0 and θ1=1\theta_1 = 1. The likelihood ratio is

f1(x)f0(x)=exp⁡ ⁣(x−12)\frac{f_1(x)}{f_0(x)} = \exp\!\left(x - \tfrac{1}{2}\right)

which is increasing in xx. So the most powerful test rejects for large xx: reject when x>z1−αx > z_{1-\alpha}. For α=0.05\alpha = 0.05, reject when x>1.645x > 1.645, and the power is Pθ=1(X>1.645)=1−Φ(0.645)≈0.26P_{\theta=1}(X > 1.645) = 1 - \Phi(0.645) \approx 0.26. No other size-0.05 test can do better at θ=1\theta = 1.

The lemma generalizes to composite alternatives through the likelihood ratio test and to composite nulls by taking the supremum over Θ0\Theta_0. Every classical test (z-test, t-test, chi-squared test) is either a likelihood-ratio test or an approximation to one.

Example problem. For X1,…,X5∼Exp(θ)X_1, \ldots, X_5 \sim \text{Exp}(\theta) with θ0=1\theta_0 = 1 and θ1=2\theta_1 = 2, what does the Neyman–Pearson most powerful test look like?

Solution

The joint density ratio is

f1(x)f0(x)=25exp⁡ ⁣(−2∑xi)exp⁡ ⁣(−∑xi)=32 e−∑xi\frac{f_1(x)}{f_0(x)} = \frac{2^5 \exp\!\left(-2\textstyle\sum x_i\right)}{\exp\!\left(-\textstyle\sum x_i\right)} = 32\, e^{-\sum x_i}

This is decreasing in T=∑xiT = \sum x_i, so the most powerful test rejects when TT is small (an exponential with rate 2 produces smaller sums). Choose cc with Pθ=1(T<c)=αP_{\theta=1}(T < c) = \alpha: since T∼Gamma(5,1)T \sim \text{Gamma}(5, 1) under H0H_0, c=2.43c = 2.43 gives α=0.05\alpha = 0.05. The rejection region is ∑Xi<2.43\sum X_i < 2.43 — 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 H0H_0, of observing a test statistic as extreme or more extreme than the one observed:

‘‘‘mathp=PH0(T(X)≥T(xobs))```math p = P_{H_0}(T(X) \geq T(x_{\text{obs}}))
Details

A small p-value indicates that the observed data would be unlikely if H0H_0 were true. The p-value is not the probability that H0H_0 is true. It is a tail probability computed under the assumption that H0H_0 holds.

Common practice: reject H0H_0 if p<αp < \alpha (typically α=0.05\alpha = 0.05). This is a decision rule, not a statement about the truth of H0H_0.

The figure below shows the anatomy of a one-sided test: the null distribution of the statistic, the rejection region (red, area α\alpha), the critical value, the observed statistic, and the p-value (blue, the tail area beyond the observation).

z (standardized test statistic, N(0,1) under H₀) critical value z₀.₀₁ = 1.645 observed z = 3 rejection region (α) p-value tail

Worked example. Testing H0:μ=0H_0: \mu = 0 vs. H1:μ≠0H_1: \mu \neq 0 with Xˉ∼N(μ,σ2/n)\bar{X} \sim N(\mu, \sigma^2/n). The test statistic is Z=Xˉ/(σ/n)Z = \bar{X}/(\sigma/\sqrt{n}) and the two-sided p-value is p=2(1−Φ(∣z∣))p = 2(1 - \Phi(|z|)). With n=50n = 50, σ=2\sigma = 2, xˉ=0.5\bar{x} = 0.5: z=0.5/(2/50)=1.77z = 0.5/(2/\sqrt{50}) = 1.77, so p=2(1−Φ(1.77))≈0.077p = 2(1 - \Phi(1.77)) \approx 0.077 — not significant at 5%, though a one-sided test would give p=0.038p = 0.038 (see One-sided vs. two-sided tests).

Example problem. A test statistic ZZ is standard normal under H0H_0 and the observed value is z=2.1z = 2.1. What is the two-sided p-value, and would you reject at α=0.05\alpha = 0.05?

Solution p=2 (1−Φ(2.1))≈2×0.0179=0.0357p = 2\,(1 - \Phi(2.1)) \approx 2 \times 0.0179 = 0.0357

Since 0.0357<0.050.0357 < 0.05, reject H0H_0 at the 5% level. Note the two-sided rule is equivalent to rejecting when ∣z∣>z1−α/2=1.96|z| > z_{1-\alpha/2} = 1.96; here 2.1>1.962.1 > 1.96, consistent with the p-value conclusion.

One-sided vs. two-sided tests

Before computing a p-value you must decide which departures from H0H_0 count as evidence. This choice fixes both the rejection region and the p-value formula:

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 α\alpha rejects half as often as a two-sided test at the same level.

How the rejection region shifts. For the same α=0.05\alpha = 0.05 with a normal statistic:

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, z=1.77z = 1.77 is significant one-sided (p=0.038p = 0.038) but not two-sided (p=0.077p = 0.077).

Worked example. Testing whether a new bearing has lower friction than the old one (H0:μ=μ0H_0: \mu = \mu_0 vs. H1:μ<μ0H_1: \mu < \mu_0), with zobs=−1.8z_{\text{obs}} = -1.8: the one-sided (lower-tail) p-value is p=Φ(−1.8)≈0.036p = \Phi(-1.8) \approx 0.036, significant at 5%. The two-sided p-value would be 0.0720.072, 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 z=1.5z = 1.5 in a test where H1:μ>0H_1: \mu > 0 was pre-registered. Is the result significant at α=0.05\alpha = 0.05? What if H1H_1 had been two-sided?

Solution

One-sided: p=1−Φ(1.5)≈0.067>0.05p = 1 - \Phi(1.5) \approx 0.067 > 0.05 — not significant. Two-sided: p=2×0.067=0.134p = 2 \times 0.067 = 0.134 — 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 z=1.5z = 1.5 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 H0:μ=0H_0: \mu = 0 vs. H1:μ>0H_1: \mu > 0 with observed xˉ=0.6\bar{x} = 0.6 and known σ=2\sigma = 2. Vary the true effect μ\mu, the sample size nn, and the significance level α\alpha, 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

Λ=sup⁡θ∈Θ0L(θ)sup⁡θ∈ΘL(θ)\Lambda = \frac{\sup_{\theta \in \Theta_0} L(\theta)}{\sup_{\theta \in \Theta} L(\theta)}

Under H0H_0, −2log⁡Λ→dχk2-2 \log \Lambda \xrightarrow{d} \chi^2_k where kk is the difference in dimensionality (Wilks’ theorem). The limiting χk2\chi^2_k 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 f1f_1 by the supremum over Θ1\Theta_1 (equivalently over Θ\Theta, since Λ≤1\Lambda \leq 1) yields a test that is asymptotically optimal.

Worked example. Testing H0:μ=0H_0: \mu = 0 vs. H1:μ≠0H_1: \mu \neq 0 for Xi∼N(μ,σ2)X_i \sim N(\mu, \sigma^2) with known σ2\sigma^2. The LRT statistic is −2log⁡Λ=nXˉ2/σ2∼χ12-2\log\Lambda = n\bar{X}^2/\sigma^2 \sim \chi^2_1 under H0H_0. With n=50n = 50, σ=2\sigma = 2, xˉ=0.5\bar{x} = 0.5: −2log⁡Λ=50×0.25/4=3.125-2\log\Lambda = 50 \times 0.25/4 = 3.125, compared to the χ12\chi^2_1 critical value 3.843.84 at α=0.05\alpha = 0.05 — fail to reject, matching the two-sided z-test (z=1.77z = 1.77, z2=3.125z^2 = 3.125).

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 X1,…,Xn∼Exp(θ)X_1, \ldots, X_n \sim \text{Exp}(\theta) (mean 1/θ1/\theta), derive the LRT of H0:θ=θ0H_0: \theta = \theta_0 vs. H1:θ≠θ0H_1: \theta \neq \theta_0 and give its large-sample form.

Solution

The unrestricted MLE is θ^=1/Xˉ\hat{\theta} = 1/\bar{X}, so

−2log⁡Λ=2n[log⁡θ^θ0+θ0θ^−1]=2n[log⁡Xˉ1/θ0⋅(−1)+…]=2n[θ0θ^−1−log⁡θ0θ^]-2\log\Lambda = 2n\left[\log\frac{\hat{\theta}}{\theta_0} + \frac{\theta_0}{\hat{\theta}} - 1\right] = 2n\left[\log\frac{\bar{X}}{1/\theta_0}\cdot(-1) + \ldots\right] = 2n\left[\frac{\theta_0}{\hat{\theta}} - 1 - \log\frac{\theta_0}{\hat{\theta}}\right]

i.e. −2log⁡Λ=2n[θ0Xˉ−1−log⁡(θ0Xˉ)]-2\log\Lambda = 2n\left[\theta_0\bar{X} - 1 - \log(\theta_0 \bar{X})\right], which is always ≥0\geq 0 and equals 0 when Xˉ=1/θ0\bar{X} = 1/\theta_0. Under H0H_0 and large nn, this is approximately χ12\chi^2_1 by Wilks’ theorem, so reject when 2n[θ0Xˉ−1−log⁡(θ0Xˉ)]>3.842n[\theta_0\bar{X} - 1 - \log(\theta_0\bar{X})] > 3.84 at α=0.05\alpha = 0.05.

Duality between tests and confidence intervals

Hypothesis testing and Estimation are two views of the same computation:

Duality. A level-α\alpha test of H0:θ=θ0H_0: \theta = \theta_0 rejects H0H_0 if and only if θ0\theta_0 lies outside the (1−α)(1-\alpha) confidence set for θ\theta.

Proof sketch. For each θ0\theta_0, let A(θ0)={x:test of H0:θ=θ0 accepts}A(\theta_0) = \{x : \text{test of } H_0: \theta = \theta_0 \text{ accepts}\} be the acceptance region. Invert it: define C(x)={θ0:x∈A(θ0)}C(x) = \{\theta_0 : x \in A(\theta_0)\}. Then

Pθ(θ∈C(X))=Pθ(X∈A(θ))=1−αP_\theta(\theta \in C(X)) = P_\theta(X \in A(\theta)) = 1 - \alpha

so C(X)C(X) is a (1−α)(1-\alpha) confidence set, and by construction θ0∉C(x)\theta_0 \notin C(x) exactly when the test rejects. Conversely, any (1−α)(1-\alpha) confidence set inverted the same way yields a level-α\alpha test.

Details

Worked example. With xˉ=0.5\bar{x} = 0.5, σ=2\sigma = 2, n=50n = 50, the 95% confidence interval for μ\mu is

0.5±1.96×250=0.5±0.554=(−0.054, 1.054)0.5 \pm 1.96 \times \frac{2}{\sqrt{50}} = 0.5 \pm 0.554 = (-0.054,\ 1.054)

The two-sided z-test of H0:μ=0H_0: \mu = 0 does not reject (0∈(−0.054,1.054)0 \in (-0.054, 1.054)), consistent with the p-value 0.077>0.050.077 > 0.05 computed earlier. Testing H0:μ=1.2H_0: \mu = 1.2 would reject, since 1.21.2 is outside the interval — and indeed z=(0.5−1.2)/0.283=−2.47z = (0.5 - 1.2)/0.283 = -2.47, p=0.013<0.05p = 0.013 < 0.05.

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 (0.31,0.49)(0.31, 0.49). At which significance levels does the test of H0:p=0.5H_0: p = 0.5 reject?

Solution

Since 0.50.5 is outside the 99% interval, the level-α=0.01\alpha = 0.01 test rejects. The test also rejects at every α\alpha for which the corresponding (1−α)(1-\alpha) interval excludes 0.5 — i.e., for all α≥0.01\alpha \geq 0.01 up to the level where the interval first touches 0.5. The exact threshold is the p-value: α∗=p\alpha^* = p, so the test rejects precisely when α>p\alpha > p. The 99% interval excluding 0.5 tells us p<0.01p < 0.01.

Multiple comparisons

When testing mm hypotheses simultaneously, the family-wise error rate (FWER) inflates. Corrections:

Authoritative sources

Details

The multiple comparisons problem arises in genomics (testing millions of genes), multiple regression, and any setting with many simultaneous tests. With mm independent tests each at level α\alpha, the probability of at least one false positive is 1−(1−α)m1 - (1-\alpha)^m, which is 0.400.40 for m=10m = 10 and α=0.05\alpha = 0.05 — the Bonferroni correction restores the family-wise rate to α\alpha at the price of power.

The Benjamini–Hochberg procedure: order p-values p(1)≤⋯≤p(m)p_{(1)} \leq \cdots \leq p_{(m)}, find the largest kk such that p(k)≤kα/mp_{(k)} \leq k\alpha/m, and reject all H(1),…,H(k)H_{(1)}, \ldots, H_{(k)}. It controls the false discovery rate FDR=E[V/max⁡(R,1)]\text{FDR} = E[V/\max(R,1)] (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 α=0.05\alpha = 0.05, m=5m = 5. Compare thresholds kα/m=0.01,0.02,0.03,0.04,0.05k\alpha/m = 0.01, 0.02, 0.03, 0.04, 0.05. The largest kk with p(k)≤kα/mp_{(k)} \leq k\alpha/m is k=2k = 2 (0.008≤0.020.008 \leq 0.02, but 0.039>0.030.039 > 0.03). BH rejects the two smallest p-values. Bonferroni would reject only one (0.001<0.010.001 < 0.01).

Example problem. With m=100m = 100 independent tests at α=0.05\alpha = 0.05 and no correction, what is the probability of at least one Type I error? What does Bonferroni require?

Solution P(at least one false positive)=1−(1−0.05)100≈0.994P(\text{at least one false positive}) = 1 - (1 - 0.05)^{100} \approx 0.994

Almost certain. Bonferroni requires each individual test to use α/m=0.0005\alpha/m = 0.0005, 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 N(μ,4)N(\mu, 4) (known variance). The null is H0:μ=0H_0: \mu = 0 (no effect) vs. H1:μ>0H_1: \mu > 0. A sample of n=100n = 100 patients gives xˉ=0.6\bar{x} = 0.6. (a) Compute the z-statistic and p-value. (b) Is the result significant at α=0.05\alpha = 0.05? (c) What is the power at μ=1\mu = 1?

Solution

(a) The test statistic is

z=xˉ−0σ/n=0.62/10=3z = \frac{\bar{x} - 0}{\sigma/\sqrt{n}} = \frac{0.6}{2/10} = 3

The one-sided p-value is p=1−Φ(3)≈0.00135p = 1 - \Phi(3) \approx 0.00135.

(b) Since p≈0.00135<0.05p \approx 0.00135 < 0.05, we reject H0H_0 at the 5% level. The drug shows a statistically significant positive effect.

(c) The power at μ=1\mu = 1 is

Pμ=1(Z>z0.05)=P ⁣(Xˉ−00.2>1.645∣μ=1)=P ⁣(Xˉ>0.329)P_{\mu=1}(Z > z_{0.05}) = P\!\left(\frac{\bar{X} - 0}{0.2} > 1.645 \mid \mu = 1\right) = P\!\left(\bar{X} > 0.329\right)

Under μ=1\mu = 1, Xˉ∼N(1,0.04)\bar{X} \sim N(1, 0.04), so

Power=P ⁣(Z>0.329−10.2)=P(Z>−3.36)≈0.9996\text{Power} = P\!\left(Z > \frac{0.329 - 1}{0.2}\right) = P(Z > -3.36) \approx 0.9996

The test has very high power to detect an effect of size 1. You can reproduce this with the interactive simulation above by setting μ=1\mu = 1, n=100n = 100, α=0.05\alpha = 0.05.