StatisticsHypothesis Tests2 of 8
Hypothesis Tests · 2

p-Values

When we test a new idea on a sample and see the average change, we need a way to tell whether that change is real or just ordinary random luck.

1

What a p-Value Measures

A p-value is the probability of getting data at least as extreme as our result, assuming the null hypothesis H0H_0 is true. Instead of trying to calculate the probability of every possible way an idea could work, we start by assuming nothing changed at all and ask how surprising our sample would be by pure chance.

What a p-Value Measures
H0:fair coinH_0 : \htmlClass{lc-violet}{\text{fair coin}}
chance of 10 Heads in a row=?\text{chance of } \htmlClass{lc-blue}{\text{10 Heads in a row}} = {?}
p-value=Probability of gettingdata at least this extreme,if H0 is true\displaystyle \share{p\text{-value}} = \begin{aligned} &\text{Probability of getting} \\ &\stat{\text{data at least this extreme}}\text{,} \\ &\mathbf{if\ } \truth{H_0 \text{ is true}} \end{aligned}
2

Finding One- and Two-Sided p-Values by Simulation

We want to find the p-value for a sample average xˉ\stat{\bar{x}} by simulating how much the sample average varies by luck when H0H_0 is true.

Historically, a coffee shop has averaged μ=20\truth{\mu} = \truth{20} customers per hour. Over n=9n = 9 hours with a new sidewalk sign, the shop averages xˉ=24\stat{\bar{x}} = \stat{24} customers per hour with a standard deviation of s=6\spread{s} = \spread{6} customers. Could a 99-hour average of 24\stat{24} happen easily by ordinary luck if the true average is still 20\truth{20}?

Finding One- and Two-Sided p-Values by Simulation
μ=20 customers per hour\htmlClass{lc-violet}{\mu} = \htmlClass{lc-violet}{20}\text{ customers per hour}
nn
=9{} = 9
xˉ\htmlClass{lc-blue}{\bar{x}}
=24{} = \htmlClass{lc-blue}{24}
s\htmlClass{lc-pink}{s}
=6{} = \htmlClass{lc-pink}{6}
24−20\htmlClass{lc-blue}{24} - \htmlClass{lc-violet}{20}
=4{} = \htmlClass{lc-pink}{4}
the sign, or a lucky 9 hours?\text{the sign, or a lucky 9 hours?}
μ=20\htmlClass{lc-violet}{\mu = 20}
14\htmlClass{lc-mute}{14}
16\htmlClass{lc-blue}{16}
18\htmlClass{lc-mute}{18}
20\htmlClass{lc-mute}{20}
22\htmlClass{lc-mute}{22}
24\htmlClass{lc-blue}{24}
26\htmlClass{lc-mute}{26}
9-hour average (customers per hour)\htmlClass{lc-ink}{\text{9-hour average (customers per hour)}}
40 dots\htmlClass{lc-ink}{40\text{ dots}}
40 dots\htmlClass{lc-ink}{40\text{ dots}}

Text solution:

So the simulated p-value is 0.04\share{0.04} (4%\share{4\%}) when testing specifically for an increase, and 0.08\share{0.08} (8%\share{8\%}) when testing for a change in either direction.

Sample averages close to 20\truth{20} leave lots of simulated dots out in the tail, giving a large p-value that looks like ordinary luck. Sample averages further from 20\truth{20} leave very few dots beyond them, giving a small p-value, and the two-sided p-value is always double the one-sided p-value.

Move the result line further from the center to see the tail shrink, and how counting both tails always doubles the p-value.
3

Finding a p-Value with Standard Error and a tt-Curve

We don't need a computer simulation every time we want a p-value. To find the p-value directly from our sample numbers, we measure how many standard errors our sample average xˉ=24\stat{\bar{x}} = \stat{24} sits from the null center μ=20\truth{\mu} = \truth{20} and find the tail area under a tt-distribution.

Finding a p-Value with Standard Error and a t-Curve
Standard Error=?\htmlClass{lc-pink}{\text{Standard Error}} = {?}
nn
=9{} = 9
xˉ\htmlClass{lc-blue}{\bar{x}}
=24{} = \htmlClass{lc-blue}{24}
s\htmlClass{lc-pink}{s}
=6{} = \htmlClass{lc-pink}{6}
μ=20\htmlClass{lc-violet}{\mu = 20}
14\htmlClass{lc-mute}{14}
16\htmlClass{lc-blue}{16}
18\htmlClass{lc-mute}{18}
20\htmlClass{lc-mute}{20}
22\htmlClass{lc-mute}{22}
24\htmlClass{lc-blue}{24}
26\htmlClass{lc-mute}{26}
9-hour average (customers per hour)\htmlClass{lc-ink}{\text{9-hour average (customers per hour)}}
μ=20\htmlClass{lc-violet}{\mu = 20}
df=8\htmlClass{lc-ink}{\text{df} = 8}
0.040\htmlClass{lc-green}{0.040}
0.040\htmlClass{lc-green}{0.040}
14\htmlClass{lc-mute}{14}
16\htmlClass{lc-blue}{16}
18\htmlClass{lc-mute}{18}
20\htmlClass{lc-mute}{20}
22\htmlClass{lc-mute}{22}
24\htmlClass{lc-blue}{24}
26\htmlClass{lc-mute}{26}
−2\htmlClass{lc-pink}{-2}
t=0\htmlClass{lc-pink}{t = 0}
2\htmlClass{lc-pink}{2}
9-hour average (customers per hour)\htmlClass{lc-ink}{\text{9-hour average (customers per hour)}}

Text solution:

So the tt-distribution gives a one-sided p-value of 0.040\share{0.040} and a two-sided p-value of 0.080\share{0.080}, matching the simulation.

Even for the same 4\spread{4}-customer increase to 24\stat{24}, a large standard error means 24\stat{24} is only a little way above 20\truth{20} in standard errors, leaving a big tail of ordinary luck. A small standard error puts that exact same 24\stat{24} many standard errors out in the tail, giving a tiny p-value.

Even when the gap to 24 stays the same, changing the size of one standard error changes how many standard errors out 24 is and how much of the tail goes past it.
4

Comparing the p-Value to Alpha and Stating a Conclusion

To decide whether a p-value is small enough to rule out ordinary luck, we compare it to a cutoff chosen ahead of time called the significance level, α\cutoff{\alpha} (usually α=0.05\cutoff{\alpha} = \cutoff{0.05}). Comparing our one-sided (p=0.04\share{p} = \share{0.04}) and two-sided (p=0.08\share{p} = \share{0.08}) results against α=0.05\cutoff{\alpha} = \cutoff{0.05} shows both possible outcomes, and why failing to reject H0H_0 never proves H0H_0 is true.

Comparing the p-Value to Alpha and Stating a Conclusion
H0:μ=20H_0 : \htmlClass{lc-violet}{\mu} = \htmlClass{lc-violet}{20}
Ha:μ>20H_a : \htmlClass{lc-violet}{\mu} > \htmlClass{lc-violet}{20}
α=0.05\htmlClass{lc-orange}{\alpha} = \htmlClass{lc-orange}{0.05}
reject H0 ?\text{reject } H_0\,?
μ=20\htmlClass{lc-violet}{\mu = 20}
0.04\htmlClass{lc-green}{0.04}
14\htmlClass{lc-mute}{14}
16\htmlClass{lc-mute}{16}
18\htmlClass{lc-mute}{18}
20\htmlClass{lc-mute}{20}
22\htmlClass{lc-mute}{22}
24\htmlClass{lc-blue}{24}
26\htmlClass{lc-mute}{26}

Text solution:

5

Common p-Value Traps and Recap

Even when we calculate a p-value and compare it to α\cutoff{\alpha} properly, we have to avoid two common traps: reading the p-value backward as the probability that H0H_0 is true, or assuming a tiny p-value automatically means a large, practically useful effect.

Common p-Value Traps and Recap
p\displaystyle \share{p} =0.04\displaystyle = \share{0.04}
a 4% chance that H0 is true?\displaystyle \text{a } \share{4\%} \text{ chance that } \truth{H_0} \text{ is true?}

We calculate a p-value by assuming H0H_0 is 100%100\% true from the start, so the condition goes in only one direction:

p-value=Probability of gettingdata at least this extreme,if H0 is true⏟Measures how surprising the data isunder pure luck≠Probability that H0 is true,given this data⏟Common trap\displaystyle \begin{aligned} \share{p\text{-value}} &= \underbrace{\begin{aligned} &\text{Probability of getting} \\ &\stat{\text{data at least this extreme}}\text{,} \\ &\mathbf{if\ } \truth{H_0 \text{ is true}} \end{aligned}}_{\begin{gathered} \text{Measures how surprising the data is} \\ \text{under pure luck} \end{gathered}} \\ &\neq \underbrace{\begin{aligned} &\text{Probability that } \truth{H_0 \text{ is true}}\text{,} \\ &\mathbf{given\ } \stat{\text{this data}} \end{aligned}}_{\text{Common trap}} \end{aligned}

Key concepts

To test a sample average xˉ\stat{\bar{x}} against a baseline H0:μ=20H_0: \truth{\mu} = \truth{20}, start by assuming H0H_0 is true and see how far out the sample result (xˉ=24\stat{\bar{x}} = \stat{24}) landed in the tail. Never count just the single exact outcome 24.0\stat{24.0}, because any single exact number has a tiny probability even right at the center. In a simulation, count all the dots at 24\stat{24} and beyond. With a formula, find how much the sample mean typically varies using Standard Error=sn=69=2\spread{\text{Standard Error}} = \tfrac{\spread{s}}{\sqrt{n}} = \tfrac{\spread{6}}{\sqrt{9}} = \spread{2}, and then convert the gap into standard errors using t=xˉ−μStandard Error=24−202=2\steps{t} = \tfrac{\stat{\bar{x}} - \truth{\mu}}{\spread{\text{Standard Error}}} = \tfrac{\stat{24} - \truth{20}}{\spread{2}} = \steps{2} with df=n−1=8\text{df} = n - 1 = 8. Check HaH_a to see which tails to count: use one tail for a one-sided test (Ha:μ>20H_a: \truth{\mu} > \truth{20} gives p=401,000=0.04\share{p} = \tfrac{40}{1{,}000} = \share{0.04}), and double it to count equally extreme results in both tails for a two-sided test (Ha:μ≠20H_a: \truth{\mu} \neq \truth{20} counts ≥24\ge \stat{24} and ≤16\le \stat{16}, giving p=801,000=0.08\share{p} = \tfrac{80}{1{,}000} = \share{0.08}). Finally, compare p\share{p} to α=0.05\cutoff{\alpha} = \cutoff{0.05}. If p<α\share{p} < \cutoff{\alpha}, reject H0H_0 (convincing evidence for HaH_a). If p≥α\share{p} \ge \cutoff{\alpha}, fail to reject H0H_0 (not enough evidence for HaH_a, which never proves H0H_0 is true). Always remember that p\share{p} is the chance of getting data at least this extreme if H0H_0 is true, not the chance that H0H_0 is true and not a measure of how big the effect is in practice.

6

Practice

1

A bakery's loaves have historically weighed an average of μ=500\truth{\mu} = \truth{500} grams. After adjusting the dough mixer, the baker weighs a random sample of loaves to test H0:μ=500H_0: \truth{\mu} = \truth{500} against Ha:μ>500H_a: \truth{\mu} > \truth{500} and gets a sample mean of xˉ=506.0\stat{\bar{x}} = \stat{506.0} grams. In a computer simulation of 1,0001{,}000 random samples assuming μ=500\truth{\mu} = \truth{500}, 33 dots land at exactly 506.0\stat{506.0} grams and 2929 dots land above 506.0\stat{506.0} grams. What is the simulated p-value, and why don't we count only the 33 dots at 506.0\stat{506.0}?

Check which dots represent pure luck giving a sample average at least as high above 500\truth{500} grams as the baker's sample.

To measure how often random luck gives a sample average at least this far from 500\truth{500}, we include both the dots at 506.0\stat{506.0} and the dots above 506.0\stat{506.0}:
(Watch out: Counting only the 33 dots at 506.0\stat{506.0} gives 31,000=0.003\tfrac{3}{1{,}000} = 0.003, or counting only the 2929 dots above 506.0\stat{506.0} gives 291,000=0.029\tfrac{29}{1{,}000} = 0.029. We don't count only the 33 dots at 506.0\stat{506.0} because when many outcomes are possible, any single exact number has a tiny probability, even right at the center of the distribution, so a p-value always counts our sample result and everything even more extreme in the direction of HaH_a.)
p-value\displaystyle \share{p\text{-value}} =3+291,000\displaystyle = \frac{3 + 29}{1{,}000} =321,000\displaystyle = \frac{32}{1{,}000} =0.032 (or 3.2%)\displaystyle = \share{0.032}\text{ (or } \share{3.2\%}\text{)}
2

A city bus route has historically taken an average of μ=30\truth{\mu} = \truth{30} minutes. After retiming the traffic lights, a planner tests H0:μ=30H_0: \truth{\mu} = \truth{30} against the two-sided alternative Ha:μ≠30H_a: \truth{\mu} \neq \truth{30} at α=0.05\cutoff{\alpha} = \cutoff{0.05} and gets a sample average of xˉ=27\stat{\bar{x}} = \stat{27} minutes. In 1,0001{,}000 simulated samples assuming μ=30\truth{\mu} = \truth{30}, 3535 dots land at 27\stat{27} minutes or lower and 3535 dots land at 33\stat{33} minutes or higher. Find the p-value and state the conclusion in context.

Look at the sign in Ha:μ≠30H_a: \truth{\mu} \neq \truth{30} to decide which outcomes are at least 3\spread{3} minutes away from 30\truth{30} before comparing p\share{p} to α=0.05\cutoff{\alpha} = \cutoff{0.05}.

Because Ha:μ≠30H_a: \truth{\mu} \neq \truth{30} is two-sided, any sample mean at least 3\spread{3} minutes away from 30\truth{30} in either direction (27\stat{27} or lower, or 33\stat{33} or higher) is at least as extreme as the sample result:
(Watch out: Counting only the left tail where xˉ=27\stat{\bar{x}} = \stat{27} landed gives p=351,000=0.035<0.05p = \tfrac{35}{1{,}000} = 0.035 < 0.05, which leads to the wrong decision of rejecting H0H_0 because it ignores the equally extreme right tail required by Ha:μ≠30H_a: \truth{\mu} \neq \truth{30}.)
p-value\displaystyle \share{p\text{-value}} =35+351,000\displaystyle = \frac{35 + 35}{1{,}000} =701,000\displaystyle = \frac{70}{1{,}000} =0.07 (or 7%)\displaystyle = \share{0.07}\text{ (or } \share{7\%}\text{)}
Because p=0.07≥0.05\share{p} = \share{0.07} \ge \cutoff{0.05}, we fail to reject H0H_0; we do not have convincing evidence that retiming the traffic lights changes the average trip time from 30\truth{30} minutes.
3

Students at a tutoring center have historically averaged μ=75\truth{\mu} = \truth{75} points on a placement test. A random sample of n=16n = 16 students using a new study guide averages xˉ=79\stat{\bar{x}} = \stat{79} points with a sample standard deviation of s=8\spread{s} = \spread{8} points. (a) Assuming H0:μ=75H_0: \truth{\mu} = \truth{75} is true, find the standard error, the t\steps{t}-statistic, and the degrees of freedom. (b) In this tt-distribution, the area in the right tail beyond your t\steps{t}-statistic is 0.032\share{0.032}. Using α=0.05\cutoff{\alpha} = \cutoff{0.05}, find the p-value and decision for a one-sided test (Ha:μ>75H_a: \truth{\mu} > \truth{75}) versus a two-sided test (Ha:μ≠75H_a: \truth{\mu} \neq \truth{75}).

For (a), divide s\spread{s} by n\sqrt{n} first to find how much a 1616-student average typically varies, then measure the 4\spread{4}-point gap in those standard-error units. For (b), check how the two-sided p-value relates to the one-tail area of 0.032\share{0.032}.

(a) Divide s=8\spread{s} = \spread{8} by 16\sqrt{16} to get the standard error, then divide the 4\spread{4}-point increase by the standard error:
(Watch out: Dividing s\spread{s} by n=16n = 16 instead of 16\sqrt{16} gives a standard error of 816=0.5\tfrac{8}{16} = 0.5 and t=8t = 8, or dividing the 4\spread{4}-point difference directly by s=8\spread{s} = \spread{8} without finding the standard error gives t=48=0.5t = \tfrac{4}{8} = 0.5.)
Standard Error=sn=816=2 points,t=79−752=2,df=16−1=15\displaystyle \begin{aligned} \spread{\text{Standard Error}} &= \frac{\spread{s}}{\sqrt{n}} = \frac{\spread{8}}{\sqrt{16}} = \spread{2}\text{ points}, \\ \steps{t} &= \frac{\stat{79} - \truth{75}}{\spread{2}} = \steps{2}, \\ \text{df} &= 16 - 1 = 15 \end{aligned}
(b) For the one-sided test (Ha:μ>75H_a: \truth{\mu} > \truth{75}), we use the single right-tail area: p=0.032<0.05\share{p} = \share{0.032} < \cutoff{0.05}, so we reject H0H_0 and find convincing evidence that the study guide increases average scores. For the two-sided test (Ha:μ≠75H_a: \truth{\mu} \neq \truth{75}), we count both tails:
(Watch out: Forgetting to double the tail area for Ha:μ≠75H_a: \truth{\mu} \neq \truth{75} leaves p=0.032p = 0.032 and wrongly rejects H0H_0.)
Two-sided p-value\displaystyle \text{Two-sided } \share{p\text{-value}} =2(0.032)\displaystyle = 2(\share{0.032}) =0.064\displaystyle = \share{0.064}
Because p=0.064≥0.05\share{p} = \share{0.064} \ge \cutoff{0.05}, we fail to reject H0H_0 and do not have convincing evidence that the study guide changes average scores.
4

Historically, a greenhouse's tomato plants yield an average of μ=30\truth{\mu} = \truth{30} tomatoes. A grower tests a new fertilizer on n=4n = 4 plants and gets a sample mean of xˉ=33\stat{\bar{x}} = \stat{33} tomatoes with s=6\spread{s} = \spread{6} tomatoes, giving a two-sided p-value of p=0.39\share{p} = \share{0.39}. The grower says, "Because p=0.39\share{p} = \share{0.39} is way above 0.05\cutoff{0.05}, we proved the fertilizer has zero effect." Find the standard error and explain why the grower's claim is wrong.

Calculate Standard Error=sn\spread{\text{Standard Error}} = \tfrac{\spread{s}}{\sqrt{n}} for n=4n = 4 plants and compare that typical luck variation to the 3\spread{3}-tomato gain.

(Watch out: Treating p≥0.05\share{p} \ge \cutoff{0.05} as proof that H0:μ=30H_0: \truth{\mu} = \truth{30} is true confuses not having enough evidence against H0H_0 with proving H0H_0 is true.)
Standard Error\displaystyle \spread{\text{Standard Error}} =sn\displaystyle = \frac{\spread{s}}{\sqrt{n}} =64\displaystyle = \frac{\spread{6}}{\sqrt{4}} =3 tomatoes\displaystyle = \spread{3}\text{ tomatoes}
Failing to reject H0H_0 never proves H0H_0 is true. With only n=4n = 4 plants, the sample average typically varies by ±3\pm \spread{3} tomatoes per plant just by luck, so a real improvement of 22 or 33 tomatoes per plant is only 1\steps{1} standard error or less above 30\truth{30} and cannot be separated from ordinary plant-to-plant luck in such a small sample.
5

Critique two claims about a study testing whether listening to whale songs overnight changes resting heart rate (H0:μ=70 bpmH_0: \truth{\mu} = \truth{70}\text{ bpm}, Ha:μ≠70 bpmH_a: \truth{\mu} \neq \truth{70}\text{ bpm}): (a) A small study gets p=0.03\share{p} = \share{0.03}, and a blogger writes, "There is only a 3%3\% chance the null hypothesis is true, so there is a 97%97\% chance whale songs change heart rate." (b) A huge study of 100,000100{,}000 people finds xˉ=69.95 bpm\stat{\bar{x}} = \stat{69.95}\text{ bpm} with p=0.001\share{p} = \share{0.001}, and a headline claims this tiny p-value proves a huge, medically important reduction in heart rate.

For (a), check what was assumed to be 100%100\% true when calculating p=0.03\share{p} = \share{0.03}. For (b), think about what dividing by 100,000\sqrt{100{,}000} does to the standard error when xˉ\stat{\bar{x}} is only 0.05 bpm\spread{0.05}\text{ bpm} below 70\truth{70}.

(a) (Watch out: Subtracting p=0.03\share{p} = \share{0.03} from 11 to get a 97%97\% chance H0H_0 is false flips the condition backward: it confuses the probability of the data given H0H_0 with the probability of H0H_0 given the data.) A p-value is the probability of getting data at least this extreme if H0H_0 is true, not the probability that H0H_0 is true given the data; a result this extreme happens 33 times in 100100 by pure luck even when whale songs do nothing at all.
(b) (Watch out: Treating a tiny p-value like p=0.001\share{p} = \share{0.001} as proof of a large real-world effect ignores sample size.) A tiny p-value only gives strong evidence that the true effect is not zero; with 100,000100{,}000 people, the standard error sn\tfrac{\spread{s}}{\sqrt{n}} is so tiny that even a practically meaningless 0.05 bpm\spread{0.05}\text{ bpm} difference lands several standard errors from 70\truth{70}.