Statistics From Zero · Lesson 8 of 22

Is the Coin Rigged? Hypothesis Testing and the P-Value

In one sentence: To decide whether something is real or just luck, assume it's just luck and ask how surprising your result would be; the p-value is that surprise, written as a probability.

The idea

Uncle Gary flips a coin to decide who does the dishes. It's come up heads, Gary's call, an awful lot lately. Is the coin rigged, or is the family just unlucky?

You can never prove a coin is rigged by flipping it. Even a perfectly fair coin can land heads ten times in a row. What you can do is ask: if the coin were fair, how surprising would this result be? If the answer is "very surprising", you start to doubt the coin. That's all hypothesis testing is.

How it works, in four steps

It's the same logic as a courtroom. The defendant is presumed innocent (the null hypothesis). The prosecution has to produce evidence that would be very unlikely if they were innocent. "Not guilty" doesn't mean "proven innocent". It means the evidence wasn't strong enough.

The dishes coin goes on trial

Aunt Linda confiscates the coin and flips it 10 times. It lands heads 8 times.

If the coin were fair, how often would you get 8 or more heads out of 10? Counting all the possibilities, it's 56 out of 1,024, about 5.5%. That's the p-value.

Suspicious, but not quite under the traditional 5% line. One test of 10 flips can't convict the coin. Linda, who is thorough, flips it another 90 times. In 100 flips it lands heads 60 times.

The chance of 60 or more heads out of 100 from a fair coin is about 2.8%. Now the coin is officially under suspicion. Gary claims it's "just a lucky coin". Linda points out that this is exactly the problem.

Notice what happened: 60% heads over 100 flips is more convincing than 80% heads over 10. A big effect in a tiny sample is easy to get by luck. A smaller effect in a bigger sample is much harder (Lesson 6 again).

Ten flips of a fair coin: how often each number of heads turns up

012345678910heads out of 108 or more heads: 56 in 1,024, about 5.5%
Out of all 1,024 possible sequences of 10 flips. The highlighted bars are the results at least as extreme as Linda's 8 heads: that share is the p-value.

What the p-value does NOT mean

The p-value is the most misunderstood number in science. Three classic mistakes:

The trap: testing lots of things

A 5% threshold means that when nothing is going on, you'll still get a "significant" result 5% of the time, by luck. Test one thing and that's an acceptable risk. Test 20 things that all do nothing, and the chance that at least one of them looks significant is about 64%.

This is called multiple testing, and it's how a lot of nonsense gets published: try many versions, report the one that "worked". The fix is to adjust the threshold for the number of tests, or to check the winner again on fresh data it has never seen.

Why anyone outside class cares

Every trading idea we test on this site goes through exactly this. The null hypothesis is "this strategy is no better than buying a random stock on the same day". We measure how surprising the strategy's results would be if that were true, and because we usually test several versions of each idea, we correct for multiple testing. Most famous strategies don't survive the correction. Some looked significant before it, which is precisely why the correction exists.

Try it yourself

Aunt Linda claims she can tell expensive wine from cheap wine. Kevin sets up a test: 10 glasses, each one randomly filled with either expensive or cheap wine, and Linda doesn't see the bottles. She gets 9 out of 10 right.

What's the null hypothesis? Is the result statistically significant at 5%? And does it prove Linda can taste the difference?

Show the answer

Null hypothesis: Linda is guessing, so each answer is a 50/50 coin flip.

p-value: the chance of getting 9 or more right out of 10 by guessing is 11 out of 1,024, about 1.1%. That's below 5%, so the result is statistically significant. Guessing is a poor explanation.

Does it prove it? Not quite. It's strong evidence, but a 1.1% fluke still happens about once in 90 tests. If Kevin had tested the whole family and Linda was the one who did well, that's multiple testing again. The honest next step is to repeat the test with fresh glasses. If she does it again, Uncle Gary has to stop buying the cheap one and pouring it into the expensive bottle.

The words your lecturer uses

Lecturer saysIt means
Null hypothesis (H0)The boring assumption: no effect, no difference, just luck
Alternative hypothesis (H1)The interesting claim you're testing: there is an effect
Test statisticA number that summarises how far the data is from what the null hypothesis expects
p-valueIf the null hypothesis were true, the chance of a result at least this extreme
Significance level (alpha, α)The cut-off you pick in advance, usually 5%
Statistically significantThe p-value came out below the cut-off
Type I error (false positive)Rejecting the null hypothesis when it was actually true: convicting an innocent coin
Type II error (false negative)Failing to reject it when there really was an effect: letting a rigged coin go
PowerThe chance a test spots a real effect. Bigger samples give more power
One-tailed / two-tailed testWhether you only care about one direction (too many heads) or both (too many heads or too many tails)
Multiple comparisonsRunning many tests at once, which makes flukes much more likely

Three things to remember

Part of Statistics From Zero, a free beginner course by WrongStat. Not a substitute for your lecturer, but hopefully a good translator.