← Chapter 11
Statistics · Chapter 11

The Z‑Test for a Proportion

Sometimes the thing you measure is not a number but a yes or no — the bottle passes or fails, the seed sprouts or doesn’t, the voter says yes or no. Count the yeses, divide by the number of tries, and you have a sample proportion. A one‑proportion z‑test asks the same question every test in this chapter asks: is this proportion farther from the claimed value than sampling noise alone would plausibly push it? The arithmetic is the familiar one — gap divided by standard error — but with one twist that trips almost everyone. The standard error is built from p₀, the claimed proportion, not from the proportion you observed, because the whole calculation is conducted inside the pretend world where the claim is true. Below you can run the test end to end: set the count, watch z land on the curve, and then look at something the mean‑test never had to show you — the exact distribution of your count, one bar per possible outcome, next to the smooth normal curve the test is quietly substituting for it.

The test statistic, on the curve

This is the sampling distribution of the test statistic if H0 were true. The dark marker is your z. The pale red region is where you agreed in advance to reject; the hatched region is every result at least as extreme as yours, and its area is the p‑value. Read the two rulers under the axis: the top row is z, the bottom row is the sample proportion that produces it. Drag the marker to move your result — the count on the right follows it.
rejection region — area = α at least this extreme — area = p your test statistic z

The sample it came from

Every dot is one real trial. Filled dots are the successes; hollow dots are the rest. This is the entire dataset a proportion test ever sees — there is nothing to average, only something to count. Press the button and a genuinely new sample is drawn from the world you set on the right.

What the test approximates — and how well

Here is the part a proportion test hides. Your count can only be a whole number, so its true sampling distribution under H0 is a row of discrete bars — the binomial distribution — not a smooth curve. The z‑test replaces those bars with the normal curve drawn over them. When the bars are tall, plentiful and symmetric, the swap is nearly free. When p₀ is close to 0 or 1, or n is small, the bars pile up against a wall, the curve spills past it, and the p‑values start to lie. Shrink n on the right and watch the fit fall apart.
exact binomial — one bar per possible count counts that would reject H0 the normal curve the test uses instead

Run the whole test, over and over

A single test either rejects or it doesn’t; from one run you cannot tell whether the procedure is any good. So run it repeatedly. Each click draws a brand‑new sample of n trials from the true world, counts its successes, computes its own z and applies the same rule. Bars in the pale red zone are the runs that rejected H0.
Tests
run
0
Rejected
H0
0
Observed
rate
—
Exact long‑
run rate
—
Four studiespick one to begin

The study on the table

Set the test up

1 · Which alternative did you commit to?
2 · How much false-alarm risk will you accept?
3 · The data you actually collected
—
—
4 · The world the sample comes from
—

Do the conditions hold?

n × p₀ — expected successes—
n × (1−p₀) — expected failures—

The test, step by step, with your numbers

Sample
proportion
—x / n
Null standard
error
—√(p₀q₀/n)
Test
statistic z
—SEs from p₀
p‑value
vs α
— 

Say it right

Seven things people say after running a one‑proportion z‑test. Two of them are correct. Tap each one.
The test in one lineMeasure the gap p̂ − p₀ in units of √(p₀(1−p₀)/n), then ask how often pure sampling noise would push a count that far. That is all a one‑proportion z‑test is.

The two standard errors, and why they differ

The test divides by p₀. A confidence interval divides by p̂. This is not a typo. A hypothesis test is conducted entirely inside the hypothetical world where the claim is exactly true, so every quantity in it — including the spread of the count — is computed from the claim: SE0 = √(p₀(1−p₀)/n). A confidence interval makes no claim to test; it has only the data, so it uses what the data gave it: SE = √(p̂(1−p̂)/n). The two numbers are usually close, which is exactly why the mistake survives — but they are answers to different questions, and when p̂ sits far from p₀ they can disagree enough to flip a borderline conclusion. If a test and an interval ever seem to contradict each other on the same data, this is almost always why.
Conditions, in order of how much trouble they cause. Random, independent trials is the one no arithmetic can rescue: the standard error formula is derived from independent draws, and a large biased sample is simply a confidently wrong answer. If you are sampling people without replacement, the draws are not quite independent — the usual repair is to keep the sample under about 10% of the population, which makes the dependence too small to matter. Enough expected successes and failures is the one you can buy with sample size, and it is checked above: both n·p₀ and n·(1−p₀) should be at least 10. Note that the check uses p₀, not p̂ — again because the null world is where the p‑value is computed. Texts vary on the threshold (some say 5, some say 15); 10 is the common compromise, and none of them is a cliff edge.
When the condition fails, the fix is not a bigger warning label. It is a different test. The count really does follow a binomial distribution — the bars in the third panel are not an approximation of anything, they are the truth — so you can compute the p‑value by adding up binomial probabilities directly. That is the exact binomial test, and it needs no condition at all. The z‑test exists because for decades those sums were painful to do by hand and a single normal curve could stand in for all of them. Watch the “exact long‑run rate” tile drift away from α as you shrink n, and you are watching the price of that convenience.
One last thing the curve makes visible. Hold p̂ where it is and push n upward: z stretches away from zero while the gap between p̂ and p₀ never changes at all. The world did not move; your instrument got sharper. A defect rate of 3.1% against a claimed 3.0% will eventually produce a z of 8 if you inspect enough units, and it will still be a difference nobody would act on. Significance and importance are different questions, and a test answers only the first. The size of the effect — p̂ − p₀, in the units of the problem — is the one that decides what to do next.