Skip to content
EN - Language: English
MathematicsHigh school

Hypothesis testing and the p-value - significance tests explained step by step

· 19 min read

In short

A hypothesis test asks whether the data would be surprising if nothing special were going on - that is the null hypothesis H₀. The p-value is the probability, assuming H₀ is true, of a result at least as extreme as the observed one. If p ≤ α, the significance level set in advance (often 0.05), we reject H₀. Otherwise there are no grounds to reject it, which does not prove it true.

Words to know

Null hypothesis H₀
The claim the test starts from - usually "no effect" or "just chance", such as p = 0.5 for someone who is guessing.
Alternative hypothesis H₁
What we suspect instead, such as p > 0.5.
Test statistic
A number worked out from the sample that the decision rests on, such as the number of right answers.
p-value
The probability, worked out assuming H₀ is true, of a result at least as extreme as the one observed.
Significance level α
The threshold set before the test - we reject H₀ when p ≤ α. A common choice is 0.05.
Type I and type II errors
Rejecting H₀ when it is true (type I), and not rejecting it when it is false (type II).

What do you think?

Maya says she can taste the difference between tap water and bottled water. In a blind test she names the water in 1515 of 2020 cups correctly. If she were only guessing, how often would she do at least this well?

The idea: could it just be luck?

Maya says she can taste the difference between tap water and bottled water. To check, a friend fills 2020 cups, each at random with one or the other. Maya cannot see which is which, and for each cup she says which water it is. She gets 1515 right.

Does that prove she has a good palate? Not yet. Someone who is only guessing gets each cup right with probability 12\frac{1}{2} and could get lucky. So we ask: if Maya were only guessing, how surprising would 1515 right answers be?

That question is the whole idea of a hypothesis test:

  • assume that nothing special is going on - this is the null hypothesis H0H_0 (here: Maya is guessing),
  • work out how likely a result at least as extreme as the one we saw would be under that assumption - this is the p-value,
  • if that probability is very small, the assumption is hard to believe, and we reject it.

A small p-value does not say for certain that Maya can taste the difference. It says that guessing would rarely give such a result. The statistician Ronald Fisher explained hypothesis testing with a similar story: a lady who said she could taste whether the tea or the milk had been poured into the cup first.

Guessing or tasting? The test step by step

Go through the animation step by step with the buttons or the arrow keys. First you see Maya’s 2020 cups, then the scores of 10001000 people who only guess, all taking the same test (simulated on a computer).

the taster: 15 of 20 right

Step 1 of 7
Steps of the animation. Arrow keys move between steps.

Maya’s blind test: 20 cups, each filled at random with tap or bottled water. A tick means she named the water correctly. She got 15 of the 20 right.

The test can go wrong in two ways. If Maya is guessing, she still lands in the critical region with probability 0.0210.021 - then we would reject a true H0H_0, a type I error. If she really can taste the difference, she may still score below 1515 - a type II error. With the same α, a longer test, with more cups, makes the second kind of mistake less likely.

Try it yourself: cups, right answers and α

The sliders set the number of cups nn and the number of right answers kk. The bars show how likely each score is for someone who is guessing, and the filled bars add up to the p-value P(X≥k)P(X \ge k). Choose α to see the critical region and the decision. Then test a few hundred guessers and compare the share of them with kk or more right answers with the p-value.

5101520critical region
n = 20
k = 15
Significance level α
p-value = P(X ≥ k)
0.021
critical region
X ≥ 15
decision
reject H₀

guessers tested: 0

What to notice:

  • with n=20n = 20, k=15k = 15 gives p=0.021p = 0.021, but k=14k = 14 already gives p=0.058p = 0.058 - more than 0.050.05,
  • the same share of right answers is stronger evidence in a longer test: 66 of 88 cups gives p=0.145p = 0.145, 1515 of 2020 gives p=0.021p = 0.021, and 3030 of 4040 gives p=0.001p = 0.001,
  • a smaller α makes the critical region smaller: with n=20n = 20 and α=0.01\alpha = 0.01 it is X≥16X \ge 16, so 1515 right answers would no longer be enough,
  • with only 55 cups there is no critical region at α=0.01\alpha = 0.01: even 55 of 55 has p=0.031p = 0.031,
  • the more guessers you test, the closer the share of them with kk or more right answers comes to the p-value.

The definition

Hypotheses. A hypothesis test weighs two statements against each other. The null hypothesis H0H_0 is the claim the test starts from - usually “no effect” or a stated value, such as p=0.5p = 0.5 or μ=1000\mu = 1000 g. The alternative hypothesis H1H_1 is what we suspect instead, such as p>0.5p > 0.5, μ<1000\mu < 1000 g or μ≠500\mu \ne 500 ml.

Test statistic. A number worked out from the sample, such as the number of right answers XX. We need to know how it behaves when H0H_0 is true. If each of nn independent trials is a success with probability p0p_0, the number of successes follows the binomial distribution:

X∼B(n,p0)X \sim B(n, p_0)

The p-value. The probability, worked out assuming H0H_0 is true, of a test statistic at least as extreme as the one observed - extreme in the direction of H1H_1. For H1:p>p0H_1: p > p_0 and kk successes, it is

p=P(X≥k).p = P(X \ge k).

Significance level and decision. Before looking at the data we choose the significance level α\alpha. A common choice is 0.050.05; 0.010.01 and 0.100.10 are also used. Then:

  • if p≤αp \le \alpha, we reject H0H_0 in favour of H1H_1 - the result is statistically significant,
  • if p>αp > \alpha, there are no grounds to reject H0H_0. That does not prove H0H_0 is true: the data are simply not strong enough evidence against it.

Critical region. The values of the test statistic for which we reject H0H_0. In the tasting test with n=20n = 20 and α=0.05\alpha = 0.05 it is X≥15X \ge 15, because P(X≥15)=0.021≤0.05P(X \ge 15) = 0.021 \le 0.05 but P(X≥14)=0.058>0.05P(X \ge 14) = 0.058 > 0.05. Rejecting H0H_0 is the same as the test statistic landing in the critical region.

Two kinds of error.

  • A type I error is rejecting H0H_0 when it is true. Its probability is at most α\alpha; in the tasting test it is P(X≥15)=0.021P(X \ge 15) = 0.021.
  • A type II error is not rejecting H0H_0 when it is false. Its probability is written β\beta, and 1−β1 - \beta is the power of the test - in the animation, 0.8040.804 for a taster who is right 44 times out of 55.

One-sided and two-sided tests. With H1:p>p0H_1: p > p_0 or H1:μ<μ0H_1: \mu < \mu_0 the test is one-sided: only results far out in one direction count as extreme. With H1:μ≠μ0H_1: \mu \ne \mu_0 it is two-sided: results far out on either side count. For a statistic with a symmetric distribution, such as zz below, the two-sided p-value is twice the area of one tail.

The z-test for a mean. When the values have a known standard deviation σ\sigma, the mean xˉ\bar{x} of a sample of nn values is compared with μ0\mu_0 through

z=xˉ−μ0σ/n.z = \frac{\bar{x} - \mu_0}{\sigma / \sqrt{n}}.

The denominator σ/n\sigma/\sqrt{n} is the standard error of the mean: means of samples vary less than single values. When H0H_0 is true and the values are normally distributed, zz has the standard normal distribution N(0,1)N(0, 1), so its p-value comes from the table of Φ(z)=P(Z<z)\Phi(z) = P(Z < z). When σ\sigma is unknown and estimated from the sample, a t-test is used instead.

zz Φ(z)\Phi(z)
0.40.4 0.65540.6554
1.6451.645 0.95000.9500
1.81.8 0.96410.9641
1.961.96 0.97500.9750
22 0.97720.9772
2.3262.326 0.99000.9900
2.5762.576 0.99500.9950

So at α=0.05\alpha = 0.05 a one-sided test rejects H0H_0 when z≥1.645z \ge 1.645 (or z≤−1.645z \le -1.645, for H1:μ<μ0H_1: \mu < \mu_0), and a two-sided test when z≥1.96z \ge 1.96 or z≤−1.96z \le -1.96. At α=0.01\alpha = 0.01 the thresholds are 2.3262.326 and 2.5762.576.

Example 1: a dog and two boxes

A dog is being trained to find a treat by smell. In each of 1010 trials the treat is hidden at random in one of two boxes, and the dog picks the right box 99 times. Test at the 5% level whether the dog does better than chance.

Step 1. Write down the hypotheses

A dog that only guesses picks the right box with probability 12\frac{1}{2}; we suspect it does better.

H0:p=0.5H1:p>0.5\begin{aligned} H_0&: p = 0.5 \\ H_1&: p > 0.5 \end{aligned}

Step 2. Name the test statistic

The test statistic is the number of right picks XX. If H0H_0 is true, it follows the binomial distribution.

X∼B(10,0.5)X \sim B(10, 0.5)

Step 3. Write the p-value as a sum

The results at least as extreme as 99 right picks are 99 and 1010.

p=P(X=9)+P(X=10)p = P(X = 9) + P(X = 10)

Step 4. Work out the two probabilities

Each sequence of 1010 picks has probability 0.510=110240.5^{10} = \frac{1}{1024}. Exactly 99 right can happen in (109)=10\binom{10}{9} = 10 ways, and 1010 right in one way.

P(X=9)=101024P(X=10)=11024\begin{aligned} P(X = 9) &= \frac{10}{1024} \\ P(X = 10) &= \frac{1}{1024} \end{aligned}

Step 5. Add them up

We add the two probabilities.

p=101024+11024=111024≈0.0107\begin{aligned} p &= \frac{10}{1024} + \frac{1}{1024} \\ &= \frac{11}{1024} \\ &\approx \boxed{0.0107} \end{aligned}

Step 6. Compare with the significance level

We compare the p-value with α=0.05\alpha = 0.05.

0.0107≤0.050.0107 \le 0.05

Answer

p≈0.011≤0.05p \approx 0.011 \le 0.05, so we reject H0H_0. At the 5% level, the dog picks the right box more often than guessing would explain.

Example 2: is the machine short-filling the bags?

A machine should fill bags with a mean of 10001000 g of flour, and the masses have standard deviation σ=5\sigma = 5 g. An inspector weighs 2525 bags and finds a mean of xˉ=998\bar{x} = 998 g. Test at the 5% level whether the machine fills too little on average. Would the decision be the same at the 1% level?

Step 1. Write down the hypotheses

We suspect the mean is below 10001000 g, so the test is one-sided.

H0:μ=1000H1:μ<1000\begin{aligned} H_0&: \mu = 1000 \\ H_1&: \mu < 1000 \end{aligned}

Step 2. Work out the standard error

We divide the standard deviation by the square root of the sample size.

σn=525=1\frac{\sigma}{\sqrt{n}} = \frac{5}{\sqrt{25}} = \boxed{1}

Step 3. Work out z

We count how many standard errors the sample mean is from 10001000 g.

z=998−10001=−2\begin{aligned} z &= \frac{998 - 1000}{1} \\ &= \boxed{-2} \end{aligned}

Step 4. Find the p-value

Extreme here means a small mean, so we need the area to the left of −2-2. The table gives Φ(2)=0.9772\Phi(2) = 0.9772.

p=Φ(−2)=1−Φ(2)=1−0.9772=0.0228\begin{aligned} p &= \Phi(-2) \\ &= 1 - \Phi(2) \\ &= 1 - 0.9772 \\ &= 0.0228 \end{aligned}

Step 5. Compare with both levels

We compare the p-value with α=0.05\alpha = 0.05 and with α=0.01\alpha = 0.01.

0.0228≤0.050.0228>0.01\begin{aligned} 0.0228 &\le 0.05 \\ 0.0228 &> 0.01 \end{aligned}

Answer

p≈0.0228p \approx 0.0228. At the 5% level we reject H0H_0: the machine fills too little on average. At the 1% level there are no grounds to reject H0H_0 - the decision depends on α, which is why α is chosen before the test.

Your turn

Juice bottles are labelled 500500 ml, and the filling machine has standard deviation σ=6\sigma = 6 ml. A sample of 3636 bottles has mean xˉ=501.8\bar{x} = 501.8 ml. Test at the 5% level whether the mean differs from 500500 ml, in either direction.

Hintshow

The test is two-sided: H1:μ≠500H_1: \mu \ne 500. Work out the standard error and zz, then p=2⋅(1−Φ(z))p = 2 \cdot (1 - \Phi(z)) for a positive zz. From the table: Φ(1.8)=0.9641\Phi(1.8) = 0.9641.

Solutiontry it on your own first

Step 1. Write down the hypotheses

A mean too high or too low would both matter, so the test is two-sided.

H0:μ=500H1:μ≠500\begin{aligned} H_0&: \mu = 500 \\ H_1&: \mu \ne 500 \end{aligned}

Step 2. Work out the standard error

We divide the standard deviation by the square root of the sample size.

σn=636=1\frac{\sigma}{\sqrt{n}} = \frac{6}{\sqrt{36}} = \boxed{1}

Step 3. Work out z

We count how many standard errors the sample mean is from 500500 ml.

z=501.8−5001=1.8\begin{aligned} z &= \frac{501.8 - 500}{1} \\ &= \boxed{1.8} \end{aligned}

Step 4. Find the area of one tail

We take the area to the right of 1.81.8 from the table.

P(Z≥1.8)=1−0.9641=0.0359\begin{aligned} P(Z \ge 1.8) &= 1 - 0.9641 \\ &= 0.0359 \end{aligned}

Step 5. Double it

In a two-sided test a result just as far below 500500 ml counts too, so both tails count.

p=2⋅0.0359=0.0718\begin{aligned} p &= 2 \cdot 0.0359 \\ &= 0.0718 \end{aligned}

Step 6. Compare with the significance level

We compare the p-value with α=0.05\alpha = 0.05.

0.0718>0.050.0718 > 0.05

Answer

p≈0.072>0.05p \approx 0.072 > 0.05, so there are no grounds to reject H0H_0. The sample does not show that the mean differs from 500500 ml - but it does not prove that the mean is exactly 500500 ml either.

Common mistakes

  • “The p-value is the probability that H₀ is true.” No: the p-value is worked out assuming H0H_0 is true. It says how surprising the data would be under H0H_0, not how likely H0H_0 is. A p-value of 0.0210.021 does not mean a 2.1% chance that Maya is guessing.
  • “p > α proves H₀.” Not rejecting is not the same as proving. With 1313 of 2020 right (p=0.132p = 0.132) Maya might still have a real but weaker skill - a test of 2020 cups is too short to show it.
  • Forgetting “at least as extreme”. The p-value is a whole tail, not one result. With 1414 of 2020 right, P(X=14)=0.037P(X = 14) = 0.037 looks smaller than 0.050.05, but the p-value P(X≥14)=0.058P(X \ge 14) = 0.058 is bigger.
  • Choosing α or the side of the test after seeing the data. Both are fixed before the test. Picking them afterwards, or trying one analysis after another until one gives p≤0.05p \le 0.05, makes a false alarm more likely.
  • “Significant” means “important”. A significant result would be unlikely under H0H_0, but the effect itself may be tiny: in a large enough sample, even a very small difference gives a small p-value. How big the effect is, is a separate question.

In exams and at university

In England, hypothesis testing is part of A-level Mathematics, and it starts in the AS content. Students learn the language of hypothesis testing through a binomial model: null and alternative hypotheses, significance level, test statistic, 1-tail and 2-tail tests, critical value, critical region, acceptance region and p-value. They carry out tests for the proportion in a binomial distribution - like the tasting test on this page - and interpret the result in context. The full A-level adds a test for the mean of a normal distribution with known, given or assumed variance, as in Example 2, and interpreting a correlation coefficient using a given p-value or critical value.

In the United States, AP Statistics has units on inference for proportions and for means, which include testing hypotheses.

At university, hypothesis testing is taught in statistics courses. In the open textbook OpenIntro Statistics, for example, it comes in the chapter “Foundations for inference”, after point estimates and confidence intervals for a proportion, and the chapters that follow use it for proportions, means and other kinds of data.

Check yourself

Test yourself

A test gives p=0.03p = 0.03, and the significance level is α=0.05\alpha = 0.05. What do we decide?

What does p=0.03p = 0.03 mean?

A coin is tossed 55 times and lands heads every time. With H0:p=0.5H_0: p = 0.5 and H1:p>0.5H_1: p > 0.5, what is the p-value?

In a two-sided z-test, z=2z = 2. The table gives Φ(2)=0.9772\Phi(2) = 0.9772. What is the p-value?

What is a type I error?

Flashcards for review

Flip a card and say whether you knew the answer. The ones you did not know come back at the end of the deck. Why it pays to come back to them in a few days is explained in the guide Spaced repetition.

Flashcards

  1. What is the null hypothesis H0H_0?

    The claim the test starts from - usually “no effect” or a stated value, such as p=0.5p = 0.5 for someone who is guessing.
  2. What is the p-value?

    The probability, worked out assuming H0H_0 is true, of a result at least as extreme as the one observed.
  3. When do we reject H0H_0?

    When p≤αp \le \alpha, where the significance level α is chosen before the test - often 0.050.05.
  4. What does p>αp > \alpha mean?

    There are no grounds to reject H0H_0. It does not prove that H0H_0 is true.
  5. Is the p-value the probability that H0H_0 is true?

    No. It is worked out assuming H0H_0 is true, so it says how surprising the data would be under H0H_0.
  6. What is the critical region?

    The values of the test statistic for which we reject H0H_0 - for 2020 cups and α=0.05\alpha = 0.05, X≥15X \ge 15.
  7. What are type I and type II errors?

    Type I: rejecting H0H_0 when it is true - its probability is at most α. Type II: not rejecting H0H_0 when it is false.
  8. What is the power of a test?

    The probability of rejecting H0H_0 when it is false, 1−β1 - \beta.
  9. How do you work out zz for a mean?

    z=xˉ−μ0σ/nz = \frac{\bar{x} - \mu_0}{\sigma / \sqrt{n}} - the standard error σ/n\sigma/\sqrt{n} is in the denominator.
  10. How do you get the p-value of a two-sided z-test?

    Double the area of one tail: p=2⋅(1−Φ(z))p = 2 \cdot (1 - \Phi(z)) for a positive zz.

Sources

We checked the facts on this page against these sources. All of them may be reused freely: they carry an open licence or are not covered by copyright.

  1. David M. Lane - Online Statistics Education, Logic of Hypothesis Testing: Introduction (the probability of a result at least this good if someone is only guessing in a taste test; Fisher's story of a lady tasting tea) · public domain
  2. David M. Lane - Online Statistics Education, Significance Testing (the significance level α, 0.05 and 0.01; statistically significant results) · public domain
  3. David M. Lane - Online Statistics Education, Type I and II Errors (rejecting a true null hypothesis with probability α; not rejecting a false one; power) · public domain
  4. David M. Lane - Online Statistics Education, One- and Two-Tailed Tests (one- or two-tailed is decided before looking at the data; for a symmetric distribution the two-tailed probability is double the one-tailed one) · public domain
  5. David M. Lane - Online Statistics Education, Interpreting Non-Significant Results (do not accept the null hypothesis when you do not reject it) · public domain
  6. David M. Lane - Online Statistics Education, Misconceptions (the p-value is not the probability that the null hypothesis is true; a small effect can give a low p-value in a large sample) · public domain
  7. David M. Lane - Online Statistics Education, Testing a Single Mean (z with the standard error σ/√N; t when σ is estimated from the sample) · public domain
  8. Kyle Siegrist - Probability, Mathematical Statistics, and Stochastic Processes, 9.1 Introduction to Hypothesis Testing (null and alternative hypotheses, critical region, type I and II errors, power) · CC BY 2.0
  9. Danielle Navarro - Learning Statistics with R, 11 Hypothesis Testing (a guessing null hypothesis θ = 0.5 with a binomial test statistic; critical region; reject when p ≤ α; the type I error rate is no larger than α; power; effect size) · CC BY-SA 4.0
  10. Danielle Navarro - Learning Statistics with R, 13.1 The one-sample z-test (z = (x̄ − μ₀)/(σ/√N), the standard error; critical values 1.645, 1.96, 2.326 and 2.576) · CC BY-SA 4.0
  11. Greenland et al. - Statistical tests, P values, confidence intervals, and power: a guide to misinterpretations, European Journal of Epidemiology, 2016 (the p-value assumes the null hypothesis; α is fixed in advance; p is not the probability of a hypothesis; tiny effects can be significant) · CC BY 4.0
  12. NIST/SEMATECH e-Handbook of Statistical Methods - 7.1.3 What are statistical tests? (the test statistic, one- and two-sided tests; 0.1, 0.05 and 0.01 as common significance levels) · public domain
  13. OpenIntro (Diez, Çetinkaya-Rundel, Barr) - OpenIntro Statistics, chapter Foundations for inference (hypothesis testing for a proportion comes after point estimates and confidence intervals) · CC BY-SA 3.0
  14. Wikipedia - p-value (the probability of a result at least as extreme as the one observed, assuming the null hypothesis is true) · CC BY-SA 4.0
  15. Wikipedia - Lady tasting tea (R. A. Fisher's tea-tasting experiment in The Design of Experiments, 1935) · CC BY-SA 4.0
  16. Wikipedia - Binomial test (the number of successes follows a binomial distribution under the null hypothesis) · CC BY-SA 4.0
  17. Wikipedia - AP Statistics (units on inference for proportions and for means) · CC BY-SA 4.0

More explainers