Hypothesis Tests

Study Sheet

Hypothesis Tests

Is the effect real, or could chance explain it?

The Logic of a Test

Concept
Null, alternative, pp-value

A test starts from the null hypothesis H0H_0 (nothing is going on: p=0.5p = 0.5, μ=100\mu = 100) and an alternative HaH_a. Compute the test statistic z=estimate−null valueSEz = \dfrac{\text{estimate} - \text{null value}}{\text{SE}}. The p-value is the probability, IF H0H_0 were true, of a result at least this extreme. Small pp (below α\alpha, usually 0.050.05) is evidence against H0H_0.

A test is a proof by contradiction with probability in place of certainty. Assume nothing is going on; ask how surprising the data would then be; if very surprising, doubt the assumption. What a pp-value does NOT measure is the probability that H0H_0 is true — it conditions on H0H_0, it does not evaluate it. And a large pp-value never proves H0H_0; it only says the data are compatible with it.

Example
A coin
−3−2−10123z = 2if H₀ is true, z is standard normal
Both shaded tails, beyond ±2, together hold 0.046: the two-sided p-value.

A coin lands heads 6060 times in 100100 flips. H0H_0: p=0.5p = 0.5; HaH_a: p≠0.5p \ne 0.5. Under H0H_0, SE =0.5⋅0.5/100=0.05= \sqrt{0.5\cdot0.5/100} = 0.05 and z=(0.6−0.5)/0.05=2z = (0.6 - 0.5)/0.05 = 2. Two-sided, both tails count: pp-value =2P(Z>2)≈0.046= 2P(Z > 2) \approx 0.046. At α=0.05\alpha = 0.05, reject H0H_0: the coin looks biased.

Example
Setting up the hypotheses

A maker claims its batteries last 4040 hours on average; a consumer group suspects less. H0H_0: μ=40\mu = 40 (the claim, the "nothing unusual" value); HaH_a: μ<40\mu < 40 (what the group wants evidence for). The hypotheses are about the population mean, never about xˉ\bar x, and they are fixed before looking at the data.

Example
The same pp, different decisions

The coin's pp-value 0.0460.046 is below α=0.05\alpha = 0.05 — reject — but above α=0.01\alpha = 0.01 — do not reject. The evidence is the same; the standard of proof differs. That is why reporting the pp-value itself is more informative than a bare "significant".

Side note
Where it goes wrong

Reading p=0.046p = 0.046 as "a 4.6%4.6\% chance the coin is fair". The pp-value assumes the coin is fair and asks how often such data would occur; the probability that the coin IS fair is a different question that a test does not answer.

Try it
Try it: one-sided

For the same coin, test HaH_a: p>0.5p > 0.5. What is the pp-value?

Show the answer

Only the upper tail now counts as "at least as extreme": P(Z>2)≈0.023P(Z > 2) \approx \mathbf{0.023}, half the two-sided value.

Errors and Power

Concept
Two ways to be wrong
H₀: μ = 100true μ = 10694100106112reject above 104.93
Shaded: the power, the chance that x̄ lands beyond the cutoff when μ is really 106.

A Type I error rejects a true H0H_0 (probability α\alpha). A Type II error fails to reject a false H0H_0 (probability β\beta). Power =1−β= 1 - \beta is the probability of correctly rejecting; it grows with sample size and effect size, and shrinks when α\alpha is made smaller.

The cutoff for rejecting is set by the null distribution alone, so that only α\alpha of its area lies beyond. Whether the test then detects a real effect depends on where the TRUE distribution sits relative to that cutoff. Moving the cutoff outward (smaller α\alpha) protects against false alarms but misses more real effects; a larger sample narrows both curves and pulls them apart, raising power without costing α\alpha.

Example
Computing power

Test H0H_0: μ=100\mu = 100 against HaH_a: μ>100\mu > 100 with σ=15\sigma = 15, n=25n = 25, α=0.05\alpha = 0.05. SE =15/5=3= 15/5 = 3, and we reject when xˉ>100+1.645⋅3=104.93\bar x > 100 + 1.645\cdot3 = 104.93. If in fact μ=106\mu = 106, then P(xˉ>104.93)=P(Z>104.93−1063)=P(Z>−0.36)≈0.64P(\bar x > 104.93) = P\left(Z > \tfrac{104.93 - 106}{3}\right) = P(Z > -0.36) \approx 0.64. The power is about 64%64\%; a real effect of 66 points is missed about a third of the time.

Example
Buying power with nn

Same test with n=100n = 100: SE =1.5= 1.5, cutoff 100+1.645⋅1.5≈102.47100 + 1.645\cdot1.5 \approx 102.47. If μ=106\mu = 106, power =P(Z>(102.47−106)/1.5)=P(Z>−2.35)≈0.99= P(Z > (102.47 - 106)/1.5) = P(Z > -2.35) \approx 0.99. Four times the data turned a coin-flip-ish test into a near-certain one.

Example
Errors in context

A screening test's H0H_0 is "the patient is healthy". A Type I error tells a healthy patient they may be ill (anxiety, more tests); a Type II error sends an ill patient home. Which error is worse decides how small α\alpha should be — a statistical choice with real-world stakes.

Side note
Where it goes wrong

Treating "fail to reject H0H_0" as "H0H_0 is true". With power 64%64\%, a real 66-point effect goes undetected about 36%36\% of the time; a non-significant result from a small study is often just a study too small to see anything.

Try it
Try it: tightening α\alpha

In the power example, α\alpha is lowered from 0.050.05 to 0.010.01 (cutoff 100+2.326⋅3≈106.98100 + 2.326\cdot3 \approx 106.98). Does the power rise or fall, and roughly to what if μ=106\mu = 106?

Show the answer

It falls: the cutoff moves right, past the true mean. Power =P(Z>(106.98−106)/3)=P(Z>0.33)≈0.37= P(Z > (106.98 - 106)/3) = P(Z > 0.33) \approx \mathbf{0.37}. Fewer false alarms cost many more misses.

Tests for Means and Two Samples

Concept
The tt test

For a mean: t=xˉ−μ0s/nt = \dfrac{\bar x - \mu_0}{s/\sqrt n} with n−1n - 1 degrees of freedom. To compare two independent groups: t=xˉ1−xˉ2s12/n1+s22/n2t = \dfrac{\bar x_1 - \bar x_2}{\sqrt{s_1^2/n_1 + s_2^2/n_2}}. Paired data (before/after on the same subjects) uses a one-sample tt test on the differences.

Every test statistic has the same shape: (observed −- expected under H0H_0) divided by the standard error, i.e. how many SEs the data sit from the null. The two-sample SE adds variances, as independent quantities must. Pairing is powerful because each subject serves as their own control: differences cancel out everything that is constant within a person, leaving much less noise.

Example
Two groups

Group A: xˉ=78\bar x = 78, s=8s = 8, n=32n = 32. Group B: xˉ=74\bar x = 74, s=6s = 6, n=32n = 32. SE =64/32+36/32=3.125≈1.77= \sqrt{64/32 + 36/32} = \sqrt{3.125} \approx 1.77; t=4/1.77≈2.26t = 4/1.77 \approx 2.26. With about 5858 degrees of freedom, the two-sided pp-value is about 0.030.03: a real difference at the 5%5\% level.

Example
Paired differences
−2−10123456mean 3no change
Five of six changes are positive and the mean change is 3: far from the null value 0 relative to their spread.

Six students take a test before and after a review session; the score changes are 3,5,−1,4,2,53, 5, -1, 4, 2, 5. Test H0H_0: mean change =0= 0. The differences have dˉ=18/6=3\bar d = 18/6 = 3 and sd≈2.28s_d \approx 2.28, so t=3/(2.28/6)≈3.22t = 3/(2.28/\sqrt6) \approx 3.22 with 55 degrees of freedom: two-sided p≈0.023p \approx 0.023. Treating the before and after scores as two independent groups would bury this effect under the large differences BETWEEN students.

Side note
Where it goes wrong

Treating "statistically significant" as "large" or "important" — with a huge sample, a trivial difference has a tiny pp-value. Report the effect size (here, 44 points or 33 points) alongside the test.

Try it
Try it: statistic

A sample of n=25n = 25 has xˉ=52\bar x = 52, s=10s = 10; test H0H_0: μ=50\mu = 50. Compute tt.

Show the answer

SE =10/25=2= 10/\sqrt{25} = 2, so t=(52−50)/2=1t = (52 - 50)/2 = \mathbf{1} — the sample mean is one SE above the null value, not significant (the two-sided pp-value is about 0.330.33).

Why It Works

If H0H_0 is true, the test statistic follows a known distribution, so we can compute exactly how often results as extreme as ours would occur by chance alone. When that frequency is 2%2\%, one of two things is true: either H0H_0 holds and we witnessed a 11-in-5050 fluke, or H0H_0 is false. The rarer the fluke would have to be, the less comfortable the first explanation becomes. Fixing α\alpha in advance keeps us honest: it is a promise about how often we are willing to be fooled by chance, made before seeing the data.