Learn · Part A · Chapter 1

The null world

How do I know a difference isn't just luck? Build the world where nothing changed and see where the real result lands.

The null world: 1,000 months of 200 parcels if the courier's 92 % promise holds
Playback speed

A histogram builds up as 1,000 simulated months drop in, each the number of parcels on time out of 200 when every parcel is on time with probability 0.92. Most months land between about 176 and 192. Then the real month, 176, lands, and every simulated month at least as bad lights up: their share is the p-value.

What you just saw

A courier promises that 92 % of parcels arrive on time. This month, 176 of 200 did: 88 %. Is the courier slipping, or was it just a bad month?

The animation took the promise at its word. It played 1,000 months in a world where every parcel is on time with probability 0.92, and piled up how many of the 200 arrived on time in each. That pile is the null world: what months look like when nothing has changed. Most months land within about 8 parcels of the 184 the promise predicts.

Then the real month landed at 176, and every simulated month at least as bad lit up: 31 of the 1,000, a share of 0.031. In words: if the courier really kept its promise, a month this bad or worse would turn up about 3 times in 100. That share has a name, the p-value, and chapter 3 is about it. You have just worked one out without a formula.

What hypothesis testing is for

Every interesting claim about the world is made about a population: all your customers, all the bottles coming off a line, all the parcels a courier delivers. You almost never measure the population. You measure a sample and try to reason back to the population.

That backwards step is the whole problem. A sample differs from its population by chance alone. If you weigh 25 bottles and the average comes out at 504 ml when the machine is really set to 500 ml, nothing has gone wrong: samples wobble. So when you see a difference, you face a question with real consequences:

The question every hypothesis test answers Is the pattern I see in my sample large enough that random sampling variation is an implausible explanation for it?

Hypothesis testing is an agreed procedure for answering that. It does not tell you what is true. It tells you whether your evidence is strong enough to stop believing that nothing is going on.

Building the null world

To ask whether luck could explain a result, you need to know what luck alone produces. So you suppose the dull explanation is right, here that the courier's rate really is 92 %, and work out what the data would look like. That imagined world is the null world, and the dull explanation is the null hypothesis.

Here the null world has a familiar shape. Each parcel is on time or not, with the same chance and independently of the others, so the number on time out of 200 follows the binomial distribution. (For a refresher, the Probability Lab's chapter on the binomial covers it.)

Two numbers describe it. The count we expect is \(np = 200 \times 0.92 = 184\), and the typical distance from it, the standard deviation, is \(\sqrt{np(1-p)} = \sqrt{200 \times 0.92 \times 0.08} = 3.84\) parcels. So 176 sits 8 below what the promise predicts: a little over two standard deviations.

The question is how often the null world produces a month at least that bad. Adding up the binomial probabilities of 176, 175, 174 and every count below answers it exactly:

Read it symbol by symbol. \(X\) is the number on time in a month where the promise holds; \(\binom{200}{k}\) counts the ways of choosing which k of the 200 parcels were on time; \(0.92^{k}\, 0.08^{200-k}\) is the chance of any one of those ways. The sum is 0.0306: about 3 months in 100.

Reading the share

The simulation gave 0.031 and the exact sum 0.0306. They differ because 1,000 simulated months are a sample too: with more months the share settles on the exact value (the law of large numbers). Either way the message is the same. Luck alone produces a month this bad only about 3 times in 100.

Be precise about what the share is. It is the chance of a month at least this bad if the promise holds. It is not the chance that the promise holds. The first is worked out inside the null world; the second would need to know how often couriers break their promises, which this calculation never used. Chapter 3 comes back to this, the commonest misreading in statistics.

Why it matters

The contract has a penalty clause for a courier that misses its promise. Invoking it for a month that luck alone often produces would be unfair and would sour the relationship; shrugging off a month that luck produces only 3 times in 100 may let a real slip run on. The null world turns "that looks bad" into a number you can weigh against the cost of each mistake. Chapter 2 writes the question down properly, chapter 3 sets the bar before looking, and chapter 4 counts how often each kind of mistake happens.

When this goes wrong

The null world is only as good as its model. The binomial assumes that parcels are late independently of one another. A snowstorm that holds up a whole van breaks that: late parcels come in clusters, real months vary more than the binomial says, and the share of null months at least as bad comes out too small. A result can look surprising only because the null world was drawn too narrow.

A small share also says only that luck is an unlikely explanation, not what the explanation is. The courier may be slipping, or this month may simply have been harder: more rural addresses, a bank holiday, a strike. The test tells you that something beyond chance is probably going on; finding out what is the analyst's job.

In code

What it computes Python (scipy, statsmodels) Excel
The chance of 176 or fewer on time if the promise holds binom.cdf(176, 200, 0.92) =BINOM.DIST(176, 200, 0.92, TRUE)
The same, as a one-sided exact test binomtest(176, 200, 0.92, alternative='less').pvalue =BINOM.DIST(176, 200, 0.92, TRUE)
A null world of 1,000 months months = np.random.default_rng(3).binomial(200, 0.92, size=1000) =BINOM.INV(200, 0.92, RAND())
Its share of months at least as bad as 176 (months <= 176).mean() =COUNTIF(A2:A1001, "<=176")/1000

In Excel, fill =BINOM.INV(200, 0.92, RAND()) down 1,000 rows (A2:A1001) to build the null world; it redraws on every recalculation. binom and binomtest are in scipy.stats, and np is numpy. The simulated share differs a little from run to run; the exact one does not.

Try this Open the binomial explorer with the null world's set-up and ask for P(X ≤ 176); then move 176 up to 180 and watch the share grow.
Remember: A test starts in the null world, where nothing has changed, and asks how often that world produces a result at least as extreme as yours. That share is the p-value: a small one means luck is an implausible explanation, not that you know what the real explanation is.

Practise

3 exercises

Quiz

Three questions on the chapter. Your best score is kept in this browser.

1. What does the null world in this chapter describe?
2. The exact share of null months at least as bad as 176 is 0.0306. Which reading is right?
3. Late parcels often come in clusters: one van, one storm. What does that do to a null world built from the binomial?
Answer every question first.
An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to Hypothesis Testing Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.