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 of cups correctly. If she were only guessing, how often would she do at least this well?
A guesser is right at each cup with probability , like a coin toss, so the number of right answers follows the binomial distribution . The probability of or more right is - about in . Of the computer guessers in the animation below, did at least as well. This probability is the p-value of Maya’s result.
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 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 right.
Does that prove she has a good palate? Not yet. Someone who is only guessing gets each cup right with probability and could get lucky. So we ask: if Maya were only guessing, how surprising would 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 (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 cups, then the scores of people who only guess, all taking the same test (simulated on a computer).
the taster: 15 of 20 right
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 - then we would reject a true , a type I error. If she really can taste the difference, she may still score below - 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 and the number of right answers . The bars show how likely each score is for someone who is guessing, and the filled bars add up to the p-value . Choose α to see the critical region and the decision. Then test a few hundred guessers and compare the share of them with or more right answers with the p-value.
- p-value = P(X ≥ k)
- 0.021
- critical region
- X ≥ 15
- decision
- reject H₀
guessers tested: 0
What to notice:
- with , gives , but already gives - more than ,
- the same share of right answers is stronger evidence in a longer test: of cups gives , of gives , and of gives ,
- a smaller α makes the critical region smaller: with and it is , so right answers would no longer be enough,
- with only cups there is no critical region at : even of has ,
- the more guessers you test, the closer the share of them with or more right answers comes to the p-value.
The definition
Hypotheses. A hypothesis test weighs two statements against each other. The null hypothesis is the claim the test starts from - usually “no effect” or a stated value, such as or g. The alternative hypothesis is what we suspect instead, such as , g or ml.
Test statistic. A number worked out from the sample, such as the number of right answers . We need to know how it behaves when is true. If each of independent trials is a success with probability , the number of successes follows the binomial distribution:
The p-value. The probability, worked out assuming is true, of a test statistic at least as extreme as the one observed - extreme in the direction of . For and successes, it is
Significance level and decision. Before looking at the data we choose the significance level . A common choice is ; and are also used. Then:
- if , we reject in favour of - the result is statistically significant,
- if , there are no grounds to reject . That does not prove is true: the data are simply not strong enough evidence against it.
Critical region. The values of the test statistic for which we reject . In the tasting test with and it is , because but . Rejecting is the same as the test statistic landing in the critical region.
Two kinds of error.
- A type I error is rejecting when it is true. Its probability is at most ; in the tasting test it is .
- A type II error is not rejecting when it is false. Its probability is written , and is the power of the test - in the animation, for a taster who is right times out of .
One-sided and two-sided tests. With or the test is one-sided: only results far out in one direction count as extreme. With it is two-sided: results far out on either side count. For a statistic with a symmetric distribution, such as 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 , the mean of a sample of values is compared with through
The denominator is the standard error of the mean: means of samples vary less than single values. When is true and the values are normally distributed, has the standard normal distribution , so its p-value comes from the table of . When is unknown and estimated from the sample, a t-test is used instead.
So at a one-sided test rejects when (or , for ), and a two-sided test when or . At the thresholds are and .
Example 1: a dog and two boxes
A dog is being trained to find a treat by smell. In each of trials the treat is hidden at random in one of two boxes, and the dog picks the right box 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 ; we suspect it does better.
Step 2. Name the test statistic
The test statistic is the number of right picks . If is true, it follows the binomial distribution.
Step 3. Write the p-value as a sum
The results at least as extreme as right picks are and .
Step 4. Work out the two probabilities
Each sequence of picks has probability . Exactly right can happen in ways, and right in one way.
Step 5. Add them up
We add the two probabilities.
Step 6. Compare with the significance level
We compare the p-value with .
Answer
, so we reject . 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 g of flour, and the masses have standard deviation g. An inspector weighs bags and finds a mean of 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 g, so the test is one-sided.
Step 2. Work out the standard error
We divide the standard deviation by the square root of the sample size.
Step 3. Work out z
We count how many standard errors the sample mean is from g.
Step 4. Find the p-value
Extreme here means a small mean, so we need the area to the left of . The table gives .
Step 5. Compare with both levels
We compare the p-value with and with .
Answer
. At the 5% level we reject : the machine fills too little on average. At the 1% level there are no grounds to reject - the decision depends on α, which is why α is chosen before the test.
Your turn
Juice bottles are labelled ml, and the filling machine has standard deviation ml. A sample of bottles has mean ml. Test at the 5% level whether the mean differs from ml, in either direction.
Hintshow
The test is two-sided: . Work out the standard error and , then for a positive . From the table: .
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.
Step 2. Work out the standard error
We divide the standard deviation by the square root of the sample size.
Step 3. Work out z
We count how many standard errors the sample mean is from ml.
Step 4. Find the area of one tail
We take the area to the right of from the table.
Step 5. Double it
In a two-sided test a result just as far below ml counts too, so both tails count.
Step 6. Compare with the significance level
We compare the p-value with .
Answer
, so there are no grounds to reject . The sample does not show that the mean differs from ml - but it does not prove that the mean is exactly ml either.
Common mistakes
- “The p-value is the probability that H₀ is true.” No: the p-value is worked out assuming is true. It says how surprising the data would be under , not how likely is. A p-value of does not mean a 2.1% chance that Maya is guessing.
- “p > α proves H₀.” Not rejecting is not the same as proving. With of right () Maya might still have a real but weaker skill - a test of cups is too short to show it.
- Forgetting “at least as extreme”. The p-value is a whole tail, not one result. With of right, looks smaller than , but the p-value 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 , makes a false alarm more likely.
- “Significant” means “important”. A significant result would be unlikely under , 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 , and the significance level is . What do we decide?
What does mean?
A coin is tossed times and lands heads every time. With and , what is the p-value?
In a two-sided z-test, . The table gives . 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
Question
Answer
What is the null hypothesis ?
The claim the test starts from - usually “no effect” or a stated value, such as for someone who is guessing.What is the p-value?
The probability, worked out assuming is true, of a result at least as extreme as the one observed.When do we reject ?
When , where the significance level α is chosen before the test - often .What does mean?
There are no grounds to reject . It does not prove that is true.Is the p-value the probability that is true?
No. It is worked out assuming is true, so it says how surprising the data would be under .What is the critical region?
The values of the test statistic for which we reject - for cups and , .What are type I and type II errors?
Type I: rejecting when it is true - its probability is at most α. Type II: not rejecting when it is false.What is the power of a test?
The probability of rejecting when it is false, .How do you work out for a mean?
- the standard error is in the denominator.How do you get the p-value of a two-sided z-test?
Double the area of one tail: for a positive .
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.
- 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
- David M. Lane - Online Statistics Education, Significance Testing (the significance level α, 0.05 and 0.01; statistically significant results) · public domain
- 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
- 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
- David M. Lane - Online Statistics Education, Interpreting Non-Significant Results (do not accept the null hypothesis when you do not reject it) · public domain
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- Wikipedia - Lady tasting tea (R. A. Fisher's tea-tasting experiment in The Design of Experiments, 1935) · CC BY-SA 4.0
- Wikipedia - Binomial test (the number of successes follows a binomial distribution under the null hypothesis) · CC BY-SA 4.0
- Wikipedia - AP Statistics (units on inference for proportions and for means) · CC BY-SA 4.0