StatisticsHypothesis Tests3 of 8
Hypothesis Tests · 3

One-Sample z-Test for a Population Proportion

When someone claims a population proportion is a certain number and our sample comes back lower or higher, we need a way to tell whether the gap is just ordinary random luck or real evidence that the claim is wrong.

1

Setting Up the Hypotheses

To test a claimed proportion, we first write down two competing explanations for our sample: the claim itself, and what we suspect is actually true.

Suppose a trading card company claims that 20%\truth{20\%} of its packs contain a rare holographic card, written in blue as p=0.20\truth{p} = \truth{0.20}, and you open a random sample of n=100n = 100 packs only to find 12\stat{12} holographic cards, giving a sample proportion in orange of p^=0.12\stat{\hat{p}} = \stat{0.12}.

Setting Up the Hypotheses
claim\text{claim}
20%\htmlClass{lc-violet}{20\%}
nn
=100{} = 100
p^\htmlClass{lc-blue}{\hat{p}}
=0.12{} = \htmlClass{lc-blue}{0.12}
0.04\htmlClass{lc-mute}{0.04}
0.12\htmlClass{lc-blue}{0.12}
0.20\htmlClass{lc-violet}{0.20}
0.28\htmlClass{lc-mute}{0.28}
0.36\htmlClass{lc-mute}{0.36}
just bad luck?\text{just bad luck?}
Text solution
Start by assuming the company's claim is true
H0:p\displaystyle H_0: \truth{p} =0.20(null hypothesis)\displaystyle = \truth{0.20} \quad \text{(null hypothesis)}
State whether we suspect the true proportion is lower, higher, or just different
Ha:p<0.20(alternative hypothesis)\displaystyle H_a: \truth{p} < \truth{0.20} \quad \text{(alternative hypothesis)}

So our test begins by assuming p=0.20\truth{p} = \truth{0.20} is true to see whether getting a sample as low as p^=0.12\stat{\hat{p}} = \stat{0.12} could happen just by bad luck.

2

Checking Conditions Under the Null

We want to use a smooth normal bell curve centered at the claimed proportion p=0.20\truth{p} = \truth{0.20} to see how sample proportions from batches of n=100n = 100 behave.

Sample proportions p^\stat{\hat{p}} form an approximately normal bell curve around p\truth{p} when the sample is random and independent, and when we expect at least 1010 successes and 1010 failures so the curve stays away from the edges at 0%0\% and 100%100\%.

p=0.02\htmlClass{lc-violet}{p = 0.02}
np=2n\htmlClass{lc-violet}{p} = \htmlClass{lc-blue}{2}
p=0.20\htmlClass{lc-violet}{p = 0.20}
np=20n\htmlClass{lc-violet}{p} = \htmlClass{lc-blue}{20}
n(1−p)=80n(1 - \htmlClass{lc-violet}{p}) = \htmlClass{lc-orange}{80}
n=100n = 100
0\htmlClass{lc-mute}{0}
0.10\htmlClass{lc-mute}{0.10}
0.20\htmlClass{lc-mute}{0.20}
0.30\htmlClass{lc-mute}{0.30}
0.40\htmlClass{lc-mute}{0.40}
1.00\htmlClass{lc-mute}{1.00}
sample proportion p^\text{sample proportion }\htmlClass{lc-blue}{\hat{p}}

Here we have to be careful not to use p^\stat{\hat{p}} the way we did for confidence intervals:

Checking Conditions Under the Null
H0H_0
:p=0.20{} : \htmlClass{lc-violet}{p} = \htmlClass{lc-violet}{0.20}
nn
=100{} = 100
p^\htmlClass{lc-blue}{\hat{p}}
=0.12{} = \htmlClass{lc-blue}{0.12}
expected successes\htmlClass{lc-blue}{\text{expected successes}}
≥10 ?{} \ge 10\,?
expected failures\htmlClass{lc-orange}{\text{expected failures}}
≥10 ?{} \ge 10\,?
p=0.20\htmlClass{lc-violet}{p = 0.20}
0\htmlClass{lc-mute}{0}
0.10\htmlClass{lc-mute}{0.10}
0.20\htmlClass{lc-violet}{0.20}
0.30\htmlClass{lc-mute}{0.30}
0.40\htmlClass{lc-mute}{0.40}
1.00\htmlClass{lc-mute}{1.00}
Text solution
Check that packs were selected at random and don't affect one another
Random and independent sampleof n=100 packs\displaystyle \begin{gathered}\text{Random and independent sample} \\ \text{of } n = 100 \text{ packs}\end{gathered}
Count expected successes and failures using the claimed p=0.20\truth{p} = \truth{0.20}, not p^=0.12\stat{\hat{p}} = \stat{0.12}
n×p=100×0.20=20≥10n×(1−p)=100×0.80=80≥10\displaystyle \begin{aligned} n \times \truth{p} &= 100 \times \truth{0.20} \\ &= \counted{20} \ge 10 \\ n \times (1 - \truth{p}) &= 100 \times 0.80 \\ &= \uncounted{80} \ge 10 \end{aligned}

Both expected counts under H0H_0 are at least 1010, so the sampling distribution of p^\stat{\hat{p}} is approximately a normal bell curve centered at 0.20\truth{0.20}.

3

Finding the Standard Deviation Under the Null

Next, we want to find how far sample proportions of n=100n = 100 packs typically vary from 0.20\truth{0.20} by pure chance, which is the standard deviation of the sampling distribution.

Sample proportions naturally vary from sample to sample by p(1−p)n\sqrt{\frac{\truth{p}(1 - \truth{p})}{n}}, and in a hypothesis test we already have a claimed value of p\truth{p} to plug into that square root.

Finding the Standard Deviation Under the Null
H0H_0
:p=0.20{} : \htmlClass{lc-violet}{p} = \htmlClass{lc-violet}{0.20}
nn
=100{} = 100
p^\htmlClass{lc-blue}{\hat{p}}
=0.12{} = \htmlClass{lc-blue}{0.12}
p=0.20\htmlClass{lc-violet}{p = 0.20}
?\htmlClass{lc-pink}{?}
0.04\htmlClass{lc-mute}{0.04}
0.12\htmlClass{lc-blue}{0.12}
0.20\htmlClass{lc-violet}{0.20}
0.28\htmlClass{lc-mute}{0.28}
0.36\htmlClass{lc-mute}{0.36}
Text solution
Substitute the claimed p=0.20\truth{p} = \truth{0.20} and sample size n=100n = 100 into the standard deviation formula
p(1−p)n=0.20×0.80100=0.16100=0.4010=0.04\displaystyle \begin{aligned} \sqrt{\frac{\truth{p}(1 - \truth{p})}{n}} &= \sqrt{\frac{\truth{0.20} \times 0.80}{100}} \\ &= \sqrt{\frac{0.16}{100}} \\ &= \frac{0.40}{10} \\ &= \spread{0.04} \end{aligned}

So if the company's 20%\truth{20\%} claim is true, batches of 100100 packs typically vary up or down from 0.20\truth{0.20} by about 0.04\spread{0.04} (4\spread{4} percentage points) just by luck.

Whether our 0.08\spread{0.08} gap from 0.20\truth{0.20} to 0.12\stat{0.12} looks ordinary or unusual depends on how wide the bell curve is: a 0.08\spread{0.08} gap sits comfortably near the center of a wide curve, but far out in the left tail of a narrow one.

For the same fixed gap between our 0.12 sample and the claimed 0.20, the standard deviation of the bell curve decides whether the sample sits inside the main pile or far out in the tail.
4

Finding the z-Score and p-Value

Now we want to know how unusual our sample of p^=0.12\stat{\hat{p}} = \stat{0.12} is on that bell curve, and whether the chance of getting a sample that far from 0.20\truth{0.20} by luck is small enough to reject the company's claim.

Finding the z-Score and p-Value
H0H_0
:p=0.20{} : \htmlClass{lc-violet}{p} = \htmlClass{lc-violet}{0.20}
HaH_a
:p<0.20{} : \htmlClass{lc-violet}{p} < \htmlClass{lc-violet}{0.20}
z\htmlClass{lc-pink}{z}
=?{} = {?}
p-value\htmlClass{lc-green}{\text{p-value}}
=?{} = {?}
p=0.20\htmlClass{lc-violet}{p = 0.20}
0.04\htmlClass{lc-pink}{0.04}
0.04\htmlClass{lc-mute}{0.04}
0.12\htmlClass{lc-blue}{0.12}
0.20\htmlClass{lc-violet}{0.20}
0.28\htmlClass{lc-mute}{0.28}
0.36\htmlClass{lc-mute}{0.36}

Putting the gap and the standard deviation together gives the test formula:

z=p^−p⏞gap from the claimp(1−p)n⏟standard deviation under H0\displaystyle \left. \boxed{\displaystyle \steps{z} = \frac{\overbrace{\stat{\hat{p}} - \truth{p}}^{\text{gap from the claim}}}{\underbrace{\sqrt{\frac{\truth{p}(1 - \truth{p})}{n}}}_{\text{standard deviation under } H_0}}} \right.
Text solution
Find how far the sample landed from the claim
p^−p\displaystyle \stat{\hat{p}} - \truth{p} =0.12−0.20\displaystyle = \stat{0.12} - \truth{0.20} =−0.08\displaystyle = \spread{-0.08}
Divide the gap by the standard deviation under H0H_0 to find how many standard deviations away the sample is
z\displaystyle \steps{z} =−0.080.04\displaystyle = \frac{\spread{-0.08}}{\spread{0.04}} =−2\displaystyle = \steps{-2}
Find the left-tail area past z=−2\steps{z} = \steps{-2} and compare it to α=0.05\cutoff{\alpha} = \cutoff{0.05}
p-value\displaystyle \share{\text{p-value}} =0.0228≈2.3%<5%  ⟹  Reject H0\displaystyle = \share{0.0228} \approx \share{2.3\%} < \cutoff{5\%} \implies \text{Reject } H_0

Since random luck when p=0.20\truth{p} = \truth{0.20} produces a sample of 0.12\stat{0.12} or lower only 2.3%\share{2.3\%} of the time, we reject H0H_0 and conclude there is convincing evidence that fewer than 20%\truth{20\%} of packs contain a holographic card.

Practical note: You already know from the 68–95–99.768\text{–}95\text{–}99.7 rule that about 95%\share{95\%} of a normal curve lies within 2\steps{2} standard deviations of the center, leaving 5%\share{5\%} split between the two tails (2.5%\share{2.5\%} in each tail). That immediately tells you that z=−2\steps{z} = \steps{-2} has a left tail of about 2.5%\share{2.5\%}, and a normal table or calculator gives the more precise 0.0228\share{0.0228}.

Ha ⁣:p<0.20H_a\!: \htmlClass{lc-violet}{p} < \htmlClass{lc-violet}{0.20}
0.04\htmlClass{lc-pink}{0.04}
2.3%\htmlClass{lc-green}{2.3\%}
p-value=2.3%\htmlClass{lc-green}{\text{p-value} = 2.3\%}
0.12\htmlClass{lc-blue}{0.12}
0.20\htmlClass{lc-violet}{0.20}
0.28\htmlClass{lc-mute}{0.28}
z=−2\htmlClass{lc-pink}{z = -2}
Ha ⁣:p≠0.20H_a\!: \htmlClass{lc-violet}{p} \neq \htmlClass{lc-violet}{0.20}
0.04\htmlClass{lc-pink}{0.04}
2.3%\htmlClass{lc-green}{2.3\%}
2.3%\htmlClass{lc-green}{2.3\%}
p-value=4.6%\htmlClass{lc-green}{\text{p-value} = 4.6\%}
0.12\htmlClass{lc-blue}{0.12}
0.20\htmlClass{lc-violet}{0.20}
0.28\htmlClass{lc-blue}{0.28}
z=−2\htmlClass{lc-pink}{z = -2}
z=2\htmlClass{lc-pink}{z = 2}

Sample proportions close to 0.20\truth{0.20} leave a left-tail area above α=5%\cutoff{\alpha} = \cutoff{5\%}. That tail area drops below 5%\cutoff{5\%} once a sample lands about 1.645\cutoff{1.645} standard deviations below 0.20\truth{0.20}, so at 0.12\stat{0.12} (z=−2\steps{z} = \steps{-2}) the tail is only 2.3%\share{2.3\%}, which is too unlikely to explain as bad luck.

As our sample lands more standard-deviation steps below the claim, the shaded left tail shrinks until getting a sample that low by chance happens less than 5% of the time.
5

The Four Steps of a One-Sample z-Test

Putting all four pieces together gives the complete method for testing any claimed population proportion from a single sample.

The Four Steps of a One-Sample z-Test
H0:p=0.20Ha:p<0.20\displaystyle \begin{aligned} H_0 &: \truth{p} = \truth{0.20} \\ H_a &: \truth{p} < \truth{0.20} \end{aligned}
n\displaystyle n =100,p^\displaystyle = 100, \quad \stat{\hat{p}} =0.12\displaystyle = \stat{0.12}
reject H0 at α\displaystyle \text{reject } H_0 \text{ at } \cutoff{\alpha} =0.05 ?\displaystyle = \cutoff{0.05}\,?

Key concepts

Everything in a one-sample zz-test comes down to one question at the start: are we given a claimed proportion p\truth{p} to test?

When testing a claim (H0:p=0.20H_0: \truth{p} = \truth{0.20}), use the claimed p\truth{p} everywhere

Since the test assumes the claim is true, use p=0.20\truth{p} = \truth{0.20} for both the Large Counts check (20≥10\counted{20} \ge 10 and 80≥1080 \ge 10) and the standard deviation (0.04\spread{0.04}). Your sample proportion p^=0.12\stat{\hat{p}} = \stat{0.12} only shows up once, at the end, to find the gap on top of the z\steps{z}-score:

z=p^−pp(1−p)n=0.12−0.200.04=−2\displaystyle \begin{aligned} \steps{z} &= \frac{\stat{\hat{p}} - \truth{p}}{\sqrt{\frac{\truth{p}(1 - \truth{p})}{n}}} \\ &= \frac{\stat{0.12} - \truth{0.20}}{\spread{0.04}} \\ &= \steps{-2} \end{aligned}

When NOT to use this setup

If a problem asks you to estimate an unknown proportion with a confidence interval and gives no claim to test, there is no H0H_0 value of p\truth{p}. That is when you use the actual sample counts and plug p^\stat{\hat{p}} into the square root.

Matching the tail to HaH_a

A one-sided alternative (<< or >>) uses the single tail in that direction (2.3%\share{2.3\%}). A two-sided alternative (≠\neq) counts samples that far away in both directions and doubles the single-tail area (2×2.3%=4.6%2 \times \share{2.3\%} = \share{4.6\%}). When the p-value is below α\cutoff{\alpha}, reject H0H_0.

6

Practice

1

A mobile game studio claims that 50%\truth{50\%} of its daily mystery chests contain a bonus gem. You suspect the true rate is higher, so you open a random sample of 100100 chests and find a bonus gem in 58\stat{58} of them. State the null and alternative hypotheses, find the standard deviation of the sampling distribution under H0H_0, and calculate the z\steps{z}-score for your sample.

Which proportion belongs inside the square root when you are testing a claim: the studio's claimed rate or your sample result of 58\stat{58} out of 100100?

Hypotheses
H0:p\displaystyle H_0: \truth{p} =0.50,Ha:p>0.50\displaystyle = \truth{0.50}, \quad H_a: \truth{p} > \truth{0.50}
Sample proportion
p^\displaystyle \stat{\hat{p}} =58100\displaystyle = \frac{\stat{58}}{100} =0.58\displaystyle = \stat{0.58}
Standard deviation under H0H_0 (Watch out: plugging p^=0.58\stat{\hat{p}} = \stat{0.58} into the square root gives 0.58×0.42100≈0.0494\sqrt{\frac{\stat{0.58} \times 0.42}{100}} \approx 0.0494 and a wrong z\steps{z}-score of 1.621.62; use the claimed p=0.50\truth{p} = \truth{0.50} from H0H_0.)
p(1−p)n=0.50×0.50100=0.25100=0.05\displaystyle \begin{aligned} \sqrt{\frac{\truth{p}(1 - \truth{p})}{n}} &= \sqrt{\frac{\truth{0.50} \times 0.50}{100}} \\ &= \sqrt{\frac{0.25}{100}} \\ &= \spread{0.05} \end{aligned}
z\steps{z}-score (Watch out: subtracting in the reverse order, 0.50−0.58\truth{0.50} - \stat{0.58}, flips the sign to −1.6-1.6; always compute sample minus claim, p^−p\stat{\hat{p}} - \truth{p}.)
z=0.58−0.500.05=0.080.05=1.6\displaystyle \begin{aligned} \steps{z} &= \frac{\stat{0.58} - \truth{0.50}}{\spread{0.05}} \\ &= \frac{\spread{0.08}}{\spread{0.05}} \\ &= \steps{1.6} \end{aligned}
2

A cereal company claims that 10%\truth{10\%} of its boxes contain a prize voucher. You buy a random sample of 120120 boxes to test whether the true rate is lower than 10%\truth{10\%}, and you find only 6\stat{6} vouchers (p^=0.05\stat{\hat{p}} = \stat{0.05}). Your friend says you cannot run a one-sample zz-test because your sample has fewer than 1010 successes. Is your friend right? Explain and check the Large Counts condition.

In a hypothesis test, are we checking the actual count in the sample, or the count we expect if the company's 10%\truth{10\%} claim is true?

Your friend is wrong.
(Watch out: checking the observed sample count np^=120×0.05=6<10n\stat{\hat{p}} = 120 \times \stat{0.05} = \stat{6} < 10 is the rule for a confidence interval when no claim exists, and falsely makes the test look invalid.)
In a hypothesis test we assume H0:p=0.10H_0: \truth{p} = \truth{0.10} is true and check the expected counts under the claim:
n×p=120×0.10=12 expected vouchersn×(1−p)=120×0.90=108 expected boxeswithout vouchers\displaystyle \begin{aligned} n \times \truth{p} &= 120 \times \truth{0.10} \\ &= \counted{12} \text{ expected vouchers} \\ n \times (1 - \truth{p}) &= 120 \times 0.90 \\ &= \uncounted{108} \text{ expected boxes} \\ &\quad \text{without vouchers} \end{aligned}
Because both 12≥10\counted{12} \ge 10 and 108≥10\uncounted{108} \ge 10, the Large Counts condition is met.
3

A battery manufacturer claims that 90%\truth{90\%} of its batteries last at least 1212 hours. To test H0:p=0.90H_0: \truth{p} = \truth{0.90} against Ha:p<0.90H_a: \truth{p} < \truth{0.90} at α=0.05\cutoff{\alpha} = \cutoff{0.05}, you test a random sample of 100100 batteries, find that 87\stat{87} last at least 1212 hours (p^=0.87\stat{\hat{p}} = \stat{0.87}), and get z=−1.00\steps{z} = \steps{-1.00} with a p-value of 0.1587\share{0.1587} (about 15.9%\share{15.9\%}). Does this mean there is a 15.9%15.9\% chance that the manufacturer's claim is true? State what the p-value actually means in context and what conclusion you should draw.

What are we already assuming is true when we calculate the area of that left tail?

No, the p-value is not the probability that the manufacturer's claim is true. It means that assuming the true proportion of batteries lasting at least 1212 hours really is 0.90\truth{0.90}, there is a 15.9%\share{15.9\%} chance of getting a random sample of 100100 batteries with 87%\stat{87\%} or fewer lasting at least 1212 hours just by random bad luck.
(Watch out: seeing a p-value above α=5%\cutoff{\alpha} = \cutoff{5\%} does not prove H0:p=0.90H_0: \truth{p} = \truth{0.90} is true. It only means random luck is still a believable explanation for the sample.)
Since 15.9%>5%\share{15.9\%} > \cutoff{5\%}, we do not reject H0H_0; we do not have convincing evidence that the true proportion of batteries lasting at least 1212 hours is less than 0.90\truth{0.90}.
4

A transit agency claims that 80%\truth{80\%} of its buses arrive on time. Suspecting that the true rate is lower, a commuter takes a random sample of 400400 bus arrivals, finds 256\stat{256} on time (p^=0.64\stat{\hat{p}} = \stat{0.64}), and calculates:

z\displaystyle z =0.64−0.800.64×0.36400\displaystyle = \frac{0.64 - 0.80}{\sqrt{\frac{0.64 \times 0.36}{400}}} =−0.160.024\displaystyle = \frac{-0.16}{0.024} =−6.67\displaystyle = -6.67

What mistake did the commuter make, and what is the correct z\steps{z}-score?

Compare the numbers inside the commuter's square root with H0:p=0.80H_0: \truth{p} = \truth{0.80}.

The commuter plugged the sample proportion p^=0.64\stat{\hat{p}} = \stat{0.64} into the standard deviation formula instead of the claimed proportion p=0.80\truth{p} = \truth{0.80} from H0H_0.
Correct standard deviation under H0H_0 (Watch out: forgetting to take the square root of the denominator 400400 divides 0.400.40 by 400400 instead of 2020, giving a standard deviation of 0.0010.001 and a wrong z\steps{z}-score of −160-160.)
p(1−p)n=0.80×0.20400=0.16400=0.4020=0.02\displaystyle \begin{aligned} \sqrt{\frac{\truth{p}(1 - \truth{p})}{n}} &= \sqrt{\frac{\truth{0.80} \times 0.20}{400}} \\ &= \sqrt{\frac{0.16}{400}} \\ &= \frac{0.40}{20} \\ &= \spread{0.02} \end{aligned}
Correct z\steps{z}-score
z=0.64−0.800.02=−0.160.02=−8\displaystyle \begin{aligned} \steps{z} &= \frac{\stat{0.64} - \truth{0.80}}{\spread{0.02}} \\ &= \frac{\spread{-0.16}}{\spread{0.02}} \\ &= \steps{-8} \end{aligned}
5

A factory machine is supposed to put dark-chocolate pretzels into 20%\truth{20\%} of its snack bags. A quality-control inspector wants to test whether the machine is off in either direction (H0:p=0.20H_0: \truth{p} = \truth{0.20} vs. Ha:p≠0.20H_a: \truth{p} \neq \truth{0.20}). In a random sample of 400400 bags, she finds 96\stat{96} bags with dark-chocolate pretzels. Using the fact that a single tail beyond 2\steps{2} standard deviations has area 2.3%\share{2.3\%}, find the z\steps{z}-score and the two-sided p-value, and explain how switching from a one-sided test (Ha:p>0.20H_a: \truth{p} > \truth{0.20}) to this two-sided test changes the decision if α=0.03\cutoff{\alpha} = \cutoff{0.03}.

Once you find how many standard deviations p^\stat{\hat{p}} sits above 0.20\truth{0.20}, which tails of the bell curve count as at least that far from 0.20\truth{0.20} when HaH_a has a ≠\neq sign?

Sample proportion and standard deviation under H0H_0
p^\displaystyle \stat{\hat{p}} =96400\displaystyle = \frac{\stat{96}}{400} =0.24\displaystyle = \stat{0.24}
0.20×0.80400=0.16400=0.4020=0.02\displaystyle \begin{aligned} \sqrt{\frac{\truth{0.20} \times 0.80}{400}} &= \sqrt{\frac{0.16}{400}} \\ &= \frac{0.40}{20} \\ &= \spread{0.02} \end{aligned}
z\steps{z}-score
z=0.24−0.200.02=0.040.02=2\displaystyle \begin{aligned} \steps{z} &= \frac{\stat{0.24} - \truth{0.20}}{\spread{0.02}} \\ &= \frac{\spread{0.04}}{\spread{0.02}} \\ &= \steps{2} \end{aligned}
Two-sided p-value and decision (Watch out: leaving the p-value at the single-tail area of 2.3%\share{2.3\%} ignores the left tail below z=−2\steps{z} = \steps{-2} and wrongly rejects H0H_0 at α=3%\cutoff{\alpha} = \cutoff{3\%}.) Because Ha:p≠0.20H_a: \truth{p} \neq \truth{0.20} is two-sided, we shade both tails beyond z=2\steps{z} = \steps{2} and z=−2\steps{z} = \steps{-2}:
Two-sided p-value\displaystyle \share{\text{Two-sided p-value}} =2×2.3%\displaystyle = 2 \times \share{2.3\%} =4.6%\displaystyle = \share{4.6\%}
At α=0.03\cutoff{\alpha} = \cutoff{0.03} (3%\cutoff{3\%}), a one-sided test has a p-value of 2.3%<3%\share{2.3\%} < \cutoff{3\%} and rejects H0H_0, whereas the two-sided test has a p-value of 4.6%>3%\share{4.6\%} > \cutoff{3\%} and fails to reject H0H_0.