StatisticsHypothesis Tests1 of 8
Hypothesis Tests · 1

The Logic of Hypothesis Testing

When a sample result beats the old average, we need a way to tell whether something genuinely changed or we just saw a lucky streak.

1

The Null Hypothesis and the p-Value

Suppose a friend who has always made 50%\truth{50\%} of their free throws claims they improved over the summer, and then makes 15\stat{15} out of 2020 shots (75%\stat{75\%}). A significance test checks whether a streak that good is likely to happen by pure luck if nothing actually changed.

The Null Hypothesis and the p-Value
Baseline=50%\text{Baseline} = \htmlClass{lc-violet}{50\%}
Sample=1520=75%\text{Sample} = \dfrac{\htmlClass{lc-blue}{15}}{20} = \htmlClass{lc-blue}{75\%}
15\htmlClass{lc-blue}{15}
Text solution
Split the baseline and the claim into competing hypothesesBecause we can only calculate probabilities from a single exact number, we start with the baseline assumption that nothing changed and set it against the claim we want to test.
H0:p=0.50⏟null hypothesis (nothing changed)Ha:p>0.50⏟alternative hypothesis (improved)\displaystyle \begin{aligned} &\underbrace{H_0: \truth{p} = \truth{0.50}}_{\text{null hypothesis (nothing changed)}} \\[6pt] &\underbrace{H_a: \truth{p} > \truth{0.50}}_{\text{alternative hypothesis (improved)}} \end{aligned}
(The subscript 00 stands for zero change, and p\truth{p} is the friend's true shooting proportion across all shots, not the p-value.)
Find the tail probability of our sample under H0H_0Assuming the friend is still a true 50%\truth{50\%} shooter, we find the probability of making 15\stat{15} or more shots out of 2020 by random luck alone.
p-value=P(15 or more made out of 20∣p=0.50)≈0.02⏟chance of a streak at leastthis good by luck\displaystyle \underbrace{\begin{aligned} \share{\text{p-value}} &= P(\stat{\text{15}}\text{ or more made } \\ &\qquad \text{out of 20} \mid \truth{p} = \truth{0.50}) \\ &\approx \share{0.02} \end{aligned}}_{\begin{gathered} \scriptstyle \text{chance of a streak at least} \\ \scriptstyle \text{this good by luck} \end{gathered}}

So if the friend hasn't improved at all, a streak of 15\stat{15} or more out of 2020 happens only 2%\share{2\%} of the time by pure luck.

Under the p=0.50\truth{p} = \truth{0.50} curve, the tail from a just-above-average result like 11\stat{11} or 12\stat{12} shots up to 2020 holds a large share of the dots, so results like those happen all the time by luck, while the tail from 15\stat{15} up to 2020 holds almost no dots:

On the "Nothing Changed" curve, making just over 10 shots happens all the time by luck, while making 15 or more barely ever happens.
2

Rejecting vs. Failing to Reject the Null

Once we know how rarely our result happens by luck, we need a cutoff for when to stop blaming luck. That preset cutoff is called the significance level α\cutoff{\alpha} (usually 0.05\cutoff{0.05}, or 5%\cutoff{5\%}).

Rejecting vs. Failing to Reject the Null
H0:p=0.50H_0: \htmlClass{lc-violet}{p} = \htmlClass{lc-violet}{0.50}
nothing changed\text{nothing changed}
Ha:p>0.50H_a: \htmlClass{lc-violet}{p} > \htmlClass{lc-violet}{0.50}
Sample=1520=75%\text{Sample} = \dfrac{\htmlClass{lc-blue}{15}}{20} = \htmlClass{lc-blue}{75\%}
p=0.50\htmlClass{lc-violet}{p} = \htmlClass{lc-violet}{0.50}
0\htmlClass{lc-mute}{0}
5\htmlClass{lc-mute}{5}
10\htmlClass{lc-mute}{10}
15\htmlClass{lc-blue}{15}
20\htmlClass{lc-mute}{20}
shots made out of 20\htmlClass{lc-mute}{\text{shots made out of 20}}
p-value\htmlClass{lc-green}{\text{p-value}}
≈2%=0.02\htmlClass{lc-green}{\approx 2\% = 0.02}
Text solution
Compare the 15\stat{15}-shot p-value to the cutoff α\cutoff{\alpha}Because a 2%\share{2\%} tail chance is smaller than our 5%\cutoff{5\%} threshold, a streak of 15\stat{15} out of 2020 is too unlikely to blame on pure luck, so we reject H0H_0.
p-value≈0.02<α=0.05⏟statistically significant  ⟹  Reject H0⏟convincing evidence for Ha:p>0.50\displaystyle \underbrace{\share{\text{p-value}} \approx \share{0.02} < \cutoff{\alpha} = \cutoff{0.05}}_{\text{statistically significant}} \implies \underbrace{\text{Reject } H_0}_{\text{convincing evidence for } H_a: \truth{p} > \truth{0.50}}
Compare the 12\stat{12}-shot p-value to the cutoff α\cutoff{\alpha}When the friend makes 12\stat{12} out of 2020 (60%\stat{60\%}), a 50%\truth{50\%} shooter hits a streak at least that high 25%\share{25\%} of the time, so ordinary luck cannot be ruled out.
p-value≈0.25≥α=0.05⏟plausible by luck  ⟹  Fail to reject H0⏟not enough evidence for Ha\displaystyle \underbrace{\share{\text{p-value}} \approx \share{0.25} \ge \cutoff{\alpha} = \cutoff{0.05}}_{\text{plausible by luck}} \implies \underbrace{\text{Fail to reject } H_0}_{\text{not enough evidence for } H_a}

So 15\stat{15} out of 2020 convinces us the friend improved, whereas 12\stat{12} out of 2020 leaves the question open because 2020 shots isn't enough to tell a 50%\truth{50\%} shooter apart from someone who improved slightly to 55%\truth{55\%}.

Even when the friend's true shooting percentage goes up to 55%\truth{55\%} or 60%\truth{60\%}, most of their 2020-shot results still fall to the left of the 15\cutoff{15}-shot cutoff where we fail to reject H0H_0:

Even when a shooter really improves by a little, most of their tries still fall short of the cutoff and fail to reject H₀.
3

Writing Hypotheses: Parameters and Tails

To set up a significance test for a new problem, we write the baseline claim and the question we are asking as H0H_0 and HaH_a. Whether we are testing a proportion p\truth{p} or an average μ\truth{\mu}, the hypotheses always describe the true value of the whole population, never the sample we just measured.

Writing Hypotheses: Parameters and Tails
claim: 10 hours\text{claim: } \htmlClass{lc-violet}{10}\text{ hours}
xˉ=9.2 hours\htmlClass{lc-blue}{\bar{x}} = \htmlClass{lc-blue}{9.2}\text{ hours}
H0:?H_0 : {?}
Text solution
Write H0H_0 using the true population parameter and the baseline numberTo test a phone company's 10\truth{10}-hour battery claim after measuring 3030 phones with sample average xˉ=9.2\stat{\bar{x}} = \stat{9.2} hours, we set the true population average μ\truth{\mu} equal to the 10\truth{10}-hour baseline.
H0:μ=10⏟true population averageequals baseline(never H0:xˉ=9.2)\displaystyle \begin{gathered} \underbrace{H_0: \truth{\mu} = \truth{10}}_{\begin{gathered} \scriptstyle \text{true population average} \\ \scriptstyle \text{equals baseline} \end{gathered}} \\[6pt] (\text{never } H_0: \stat{\bar{x}} = \stat{9.2}) \end{gathered}
Match the direction of HaH_a to the change that matters before looking at the dataA phone buyer only cares if battery life drops below 10\truth{10} hours (left tail), a free-throw shooter only cares if accuracy rises above 0.50\truth{0.50} (right tail), and a bolt maker aiming for 10 mm\truth{10}\text{ mm} has to catch bolts that are either too small or too large (both tails).
Ha:μ<10⏟one-sided (left tail)Ha:p>0.50⏟one-sided (right tail)Ha:μ≠10⏟two-sided (both tails)\displaystyle \begin{aligned} &\underbrace{H_a: \truth{\mu} < \truth{10}}_{\text{one-sided (left tail)}} \\[6pt] &\underbrace{H_a: \truth{p} > \truth{0.50}}_{\text{one-sided (right tail)}} \\[6pt] &\underbrace{H_a: \truth{\mu} \neq \truth{10}}_{\text{two-sided (both tails)}} \end{aligned}
Ha:μ<10H_a: \htmlClass{lc-violet}{\mu} < \htmlClass{lc-violet}{10}
10\htmlClass{lc-violet}{10}
one-sided\text{one-sided}
Ha:p>0.50H_a: \htmlClass{lc-violet}{p} > \htmlClass{lc-violet}{0.50}
0.50\htmlClass{lc-violet}{0.50}
one-sided\text{one-sided}
Ha:μ≠10H_a: \htmlClass{lc-violet}{\mu} \neq \htmlClass{lc-violet}{10}
10\htmlClass{lc-violet}{10}
two-sided\text{two-sided}

Always pick one-sided or two-sided from the problem's goal before reading the sample number: even if a sample of bolts averages xˉ=9.5 mm\stat{\bar{x}} = \stat{9.5}\text{ mm}, the hypothesis is still Ha:μ≠10H_a: \truth{\mu} \neq \truth{10} because bolts that are too wide or too narrow both fail.

Key concepts

Every significance test follows the same logic:

Name the population parameter and set H0H_0 to the baseline

Use p\truth{p} for a true population proportion (H0:p=0.50H_0: \truth{p} = \truth{0.50}) and μ\truth{\mu} for a true population average (H0:μ=10H_0: \truth{\mu} = \truth{10}). The null hypothesis always gets an == sign because we need a single exact number to calculate probabilities from. We can never build the curve from HaH_a (p>0.50\truth{p} > \truth{0.50} is an infinite range of numbers), and we never put the sample result (xˉ=9.2\stat{\bar{x}} = \stat{9.2}) inside a hypothesis.

Set the direction of HaH_a from the question, not the sample

Use a one-sided alternative when only one direction counts as the change you are looking for (Ha:μ<10H_a: \truth{\mu} < \truth{10} if only shorter battery life is a problem; Ha:p>0.50H_a: \truth{p} > \truth{0.50} if testing for improvement) and a two-sided alternative (Ha:μ≠10H_a: \truth{\mu} \neq \truth{10}) whenever missing the target on either side matters.

Compare the p-value to the cutoff α\cutoff{\alpha}

The p-value is the tail probability of getting a sample at least as extreme as ours by pure luck when H0H_0 is true.

  • If p-value<α\share{\text{p-value}} < \cutoff{\alpha} (like 0.02<0.05\share{0.02} < \cutoff{0.05}), the result is statistically significant: reject H0H_0 (convincing evidence for HaH_a).
  • If p-value≥α\share{\text{p-value}} \ge \cutoff{\alpha} (like 0.25≥0.05\share{0.25} \ge \cutoff{0.05}), fail to reject H0H_0 (not enough evidence to tell a real change apart from random luck; never say H0H_0 is proven true).
4

Practice

1

A delivery service has historically arrived on time for 80% of its orders. After switching to new routing software, the manager wants to test whether the on-time rate has improved. In a sample of 50 deliveries with the new software, 44 (88%) arrive on time. Write the null and alternative hypotheses and define the parameter you use.

Are we tracking an average measurement or the proportion of deliveries that arrive on time, and which percentage is the historical baseline versus the sample result?

We are testing a population proportion, so we let p\truth{p} be the true proportion of all deliveries that arrive on time with the new software. The historical baseline is 0.80\truth{0.80}, and the manager is testing for an improvement (>>). Be careful not to plug the sample result 0.88\stat{0.88} into the hypotheses (writing H0:p=0.88H_0: \truth{p} = \stat{0.88} or Ha:p=0.88H_a: \truth{p} = \stat{0.88}); 0.88\stat{0.88} is just the evidence from the 5050 sampled deliveries and is only used later to find the p-value.
H0:p\displaystyle H_0: \truth{p} =0.80Ha:p>0.80\displaystyle = \truth{0.80} \qquad H_a: \truth{p} > \truth{0.80}
where p\truth{p} is the true proportion of all deliveries that arrive on time with the new software.
2

A coffee machine is supposed to dispense an average of 8 ounces per cup. If it dispenses too little, customers complain; if it dispenses too much, the cups overflow. A technician measures a sample of 25 cups and finds a sample average of xˉ=8.3\stat{\bar{x}} = \stat{8.3} ounces. Write the null and alternative hypotheses to test whether the machine is off target, and state whether this is a one-sided or two-sided test.

Before looking at xˉ=8.3\stat{\bar{x}} = \stat{8.3}, ask whether going below 8\truth{8} ounces, above 8\truth{8} ounces, or both causes a problem for the coffee machine.

We are testing a population average, so we let μ\truth{\mu} be the true average amount of coffee (in ounces) dispensed by the machine across all cups, with a target baseline of 8\truth{8} ounces. Don't let the sample average xˉ=8.3\stat{\bar{x}} = \stat{8.3} trick you into writing a one-sided test (Ha:μ>8H_a: \truth{\mu} > \truth{8}) or putting xˉ\stat{\bar{x}} in the hypothesis. Because dispensing too little or too much both cause problems, we have to check both tails regardless of which side the sample landed on.
H0:μ=8Ha:μ≠8(two-sided test)\displaystyle \begin{aligned} H_0: \truth{\mu} &= \truth{8} \\ H_a: \truth{\mu} &\neq \truth{8} \quad \text{(two-sided test)} \end{aligned}
3

A cereal box is advertised to contain an average of 500 grams. A consumer group weighs 40 boxes, gets a sample average of 491 grams, and writes the hypotheses as H0:xˉ=491H_0: \bar{x} = 491 and Ha:xˉ<500H_a: \bar{x} < 500. Identify the two mistakes in how these hypotheses are written and give the correct hypotheses.

Check the symbol used for the average (sample vs. population) and the number used in H0H_0 (sample result vs. advertised baseline).

First, the hypotheses are written with the sample average xˉ\stat{\bar{x}} (which we already know is 491\stat{491} grams for those 4040 boxes) instead of the true population average μ\truth{\mu} of all boxes made. Second, H0H_0 uses the sample result (491\stat{491}) instead of the advertised baseline claim (500\truth{500}). Be careful not to fix only one of the two mistakes (such as writing H0:xˉ=500H_0: \stat{\bar{x}} = \truth{500} or H0:μ=491H_0: \truth{\mu} = \stat{491}); both hypotheses must use the population parameter μ\truth{\mu} and the baseline number 500\truth{500}:
H0:μ\displaystyle H_0: \truth{\mu} =500Ha:μ<500\displaystyle = \truth{500} \qquad H_a: \truth{\mu} < \truth{500}
4

A trivia player has historically answered 25% of questions correctly (H0:p=0.25H_0: \truth{p} = \truth{0.25}). After studying, they claim they have improved (Ha:p>0.25H_a: \truth{p} > \truth{0.25}) and answer 11 out of 20 questions right (55%). If a true 25% player takes a 20-question quiz, the chance of getting 11 or more right by pure luck is 0.004 (0.4%). What is the p-value, and what conclusion should you reach using a significance level of α=0.05\cutoff{\alpha} = \cutoff{0.05}?

Which number gives the tail chance of the streak happening by luck when H0H_0 is true, and how does it compare to α=0.05\cutoff{\alpha} = \cutoff{0.05}?

The p-value is the probability of getting a sample result at least as extreme as 11\stat{11} out of 2020 by luck alone under H0H_0, which is 0.004\share{0.004} (0.4%\share{0.4\%}). Don't confuse the p-value with the sample score 0.55\stat{0.55} or the baseline 0.25\truth{0.25}, and be careful not to misread 0.4%0.4\% as 0.40>0.050.40 > 0.05. Because p-value=0.004<α=0.05\share{\text{p-value}} = \share{0.004} < \cutoff{\alpha} = \cutoff{0.05}, the result is statistically significant: we reject H0H_0 and conclude that we have convincing evidence for HaH_a that the player's true accuracy is now greater than 25%\truth{25\%}.
5

A teacher tests whether a new study app raises average test scores above the historical baseline of 70 points (H0:μ=70H_0: \truth{\mu} = \truth{70}, Ha:μ>70H_a: \truth{\mu} > \truth{70}). A sample of 15 students using the app averages 73 points, which gives a p-value of 0.18. Using α=0.05\cutoff{\alpha} = \cutoff{0.05}, a school administrator concludes, "This proves the app has zero effect and the true average is still 70." Explain what the administrator got right and what they got wrong.

Compare the p-value 0.18\share{0.18} to α=0.05\cutoff{\alpha} = \cutoff{0.05} first, then ask whether a sample of 1515 students is large enough to rule out a small true improvement (like μ=72\truth{\mu} = \truth{72} or 73\truth{73}).

Because the p-value (0.18\share{0.18}) is greater than the cutoff α=0.05\cutoff{\alpha} = \cutoff{0.05}, a sample average of 73\stat{73} or higher happens 18%\share{18\%} of the time by normal luck when nothing changed, so the administrator is right that we cannot reject H0H_0. Where the administrator goes wrong is claiming that failing to reject H0H_0 proves H0H_0 is true: the app might have raised the true average slightly (for example, to 72\truth{72} or 73\truth{73}), and a small sample of 1515 students simply isn't large enough to tell a small gain apart from random luck. The proper conclusion is that we fail to reject H0H_0 because we do not have convincing evidence to tell whether test scores improved.
6

When testing whether a coin is biased toward heads (H0:p=0.50H_0: \truth{p} = \truth{0.50}, Ha:p>0.50H_a: \truth{p} > \truth{0.50}) after getting 16 heads in 20 tosses, a student asks: "Since we want to know if the coin is biased, why don't we build our probability curve assuming HaH_a is true instead of assuming H0H_0 is true?" Using the logic of a significance test, explain why we cannot build the curve from HaH_a.

To compute the probability of getting 16\stat{16} or more heads in 2020 flips, what single input number do you need for each flip?

To calculate the probability of getting 16\stat{16} or more heads in 2020 tosses, we need one exact probability p\truth{p} of getting heads on each flip. A common mistake is to try to build the HaH_a curve using the sample result 1620=0.80\stat{\tfrac{16}{20}} = \stat{0.80}, which treats one small sample as if it were the coin's true long-run probability. In reality, Ha:p>0.50H_a: \truth{p} > \truth{0.50} is not a single number. It is an infinite range of numbers (such as 0.52\truth{0.52}, 0.65\truth{0.65}, or 0.85\truth{0.85}), each producing a different curve. We must start by assuming H0:p=0.50H_0: \truth{p} = \truth{0.50} because the baseline is the only side with a single, exact number we can build a probability curve from.