Chi-square test
The chi-square test compares observed counts with the counts expected under a null hypothesis: χ² = Σ (o − e)² ÷ e.
Part 1 · Hook
Why this matters
Release 40 pill bugs into a chamber with a moist side and a dry side, and 29 end up on the moist side. A preference, or just luck? Flip 40 coins and you rarely get exactly 20 heads. The chi-square test measures how far your counts are from what "no preference" predicts and tells you whether that gap is too big for chance.
Part 2 · Before you start
What this builds on
Part 3 · Prerequisite check
Quick check before you start
1. An experiment's null hypothesis says…
- the independent variable has no effect; differences are due to chance
- the independent variable causes the predicted effect
- the experiment has no control group
Show the answer
The null is the "no effect" statement that the test tries to reject.
- Correct: the independent variable has no effect; differences are due to chance:
- the independent variable causes the predicted effect:
- the experiment has no control group:
2. Data lead you to fail to reject a null hypothesis. What does that mean?
- The data did not show an effect
- The data proved there is no effect
- The alternative hypothesis is true
Show the answer
Failing to reject means the evidence is not strong enough; it never proves the null.
- Correct: The data did not show an effect:
- The data proved there is no effect:
- The alternative hypothesis is true:
Part 4 · See it
See it first
Part 5 · Step by step
How it works, step by step
- The null hypothesis predicts how the total should split among categories (no preference: 20 and 20).That prediction gives an expected count, e, for each category.
- Observed counts, o, differ from expected; squaring the differences and dividing by e scales each gap to the size of the category.Adding the terms gives χ² = Σ (o − e)² ÷ e: 4.05 + 4.05 = 8.1.
- More categories give more chances for chance gaps to add up.You look up the critical value for df = categories − 1 (here 1) at p = 0.05: 3.84.
- χ² (8.1) is greater than the critical value (3.84).A gap this large would happen less than 5% of the time if the null were true (p < 0.05), so you reject the null hypothesis.
- If χ² had been below the critical value……you would fail to reject the null: the counts would fit "no preference" well enough to be chance.
Part 6 · Key ideas
Key ideas
- Worked example. o = 29 moist, 11 dry; e = 20, 20. χ² = (29 − 20)² ÷ 20 + (11 − 20)² ÷ 20 = 4.05 + 4.05 = 8.1. df = 1; critical value (p = 0.05) = 3.84. 8.1 > 3.84: reject the null.
- Formula sheet: χ² = Σ (o − e)² ÷ e, with df = number of categories − 1. Use the p = 0.05 column unless told otherwise.
- Bigger χ² means a worse fit to the null. χ² greater than the critical value means p is less than 0.05: reject. Otherwise, fail to reject.
- Always use counts, never percentages or means: chi-square depends on how many individuals were counted.
Part 7 · Misconception
A common mistake
The wrong idea: A large chi-square value means the data support the null hypothesis.
What actually happens: A large χ² means observed counts are far from what the null predicts. Above the critical value, you reject the null; a small χ² is what fits the null.
Part 8 · Check yourself
Check yourself
Exam-style questions. Anything you miss goes into your review queue.
Data table
Pill bugs in a two-sided choice chamber
A student placed 40 pill bugs in the center of a chamber with a moist side and a dry side, identical in light and temperature. After 10 minutes she counted the animals on each side.
Critical values of χ²: at p = 0.05, df 1 = 3.84, df 2 = 5.99, df 3 = 7.82, df 4 = 9.49; at p = 0.01, df 1 = 6.63, df 2 = 9.21, df 3 = 11.34, df 4 = 13.28.
| Side | Observed (pill bugs) |
|---|---|
| Moist | 29 |
| Dry | 11 |
| Total | 40 |
1. What is the null hypothesis for this experiment?
- Pill bugs show no preference, so they will be split equally between the moist and dry sides.
- Pill bugs prefer the moist side, so more than half of them will be found on that side of the chamber.
- Pill bugs prefer the dry side, because dry conditions keep their bodies at a steady temperature.
- The number of pill bugs on the moist side depends on how many are on the dry side of the chamber.
Show the answer
The null hypothesis says the independent variable (moisture) has no effect, so the 40 animals should split 20 : 20, with any departure due to chance.
- Correct: Pill bugs show no preference, so they will be split equally between the moist and dry sides.: Correct: no preference, equal split.
- Pill bugs prefer the moist side, so more than half of them will be found on that side of the chamber.: This is a directional alternative hypothesis.
- Pill bugs prefer the dry side, because dry conditions keep their bodies at a steady temperature.: This is an alternative with a proposed reason.
- The number of pill bugs on the moist side depends on how many are on the dry side of the chamber.: With a fixed total this is true whatever the animals do, so it tests nothing.
2. Calculate the chi-square value. Give your answer to one decimal place.
Type a number.
Show the answer
Expected: 20 moist, 20 dry. Moist: (29 − 20)² ÷ 20 = 81 ÷ 20 = 4.05. Dry: (11 − 20)² ÷ 20 = 4.05. χ² = 4.05 + 4.05 = 8.1.
- Answer: 8.1
3. Which conclusion follows from the chi-square test at p = 0.05?
- χ² = 8.1 is greater than 3.84 (df = 1), so reject the null hypothesis: the split is unlikely to be chance.
- χ² = 8.1 is greater than 3.84 (df = 1), so fail to reject the null hypothesis: the bugs show no preference.
- χ² = 8.1 is less than 9.49 (df = 4), so fail to reject the null hypothesis, because the 40 bugs are the categories.
- χ² = 8.1 is greater than 0.05, so reject the null hypothesis, because any χ² above 0.05 is significant.
Show the answer
Two categories give df = 2 − 1 = 1; the critical value at p = 0.05 is 3.84. A χ² larger than the critical value means the deviation is too big to blame on chance (p < 0.05), so reject the null.
- Correct: χ² = 8.1 is greater than 3.84 (df = 1), so reject the null hypothesis: the split is unlikely to be chance.: Correct.
- χ² = 8.1 is greater than 3.84 (df = 1), so fail to reject the null hypothesis: the bugs show no preference.: A χ² above the critical value leads to rejecting the null, not failing to reject.
- χ² = 8.1 is less than 9.49 (df = 4), so fail to reject the null hypothesis, because the 40 bugs are the categories.: Degrees of freedom count categories (2), not animals, so df = 1.
- χ² = 8.1 is greater than 0.05, so reject the null hypothesis, because any χ² above 0.05 is significant.: χ² is compared with the critical value, not with the significance level itself.
Data table
A four-way choice chamber
A second class built a chamber with four equal sections: dark and moist, dark and dry, light and moist, light and dry. They released 60 pill bugs at the center and counted them after 10 minutes.
Critical values of χ²: at p = 0.05, df 1 = 3.84, df 2 = 5.99, df 3 = 7.82, df 4 = 9.49; at p = 0.01, df 1 = 6.63, df 2 = 9.21, df 3 = 11.34, df 4 = 13.28.
| Section | Observed (pill bugs) |
|---|---|
| Dark, moist | 24 |
| Dark, dry | 14 |
| Light, moist | 13 |
| Light, dry | 9 |
| Total | 60 |
4. How many degrees of freedom does this test have?
Type a number.
Show the answer
Four categories (sections) − 1 = 3 degrees of freedom.
- Answer: 3
5. Calculate the chi-square value for the null hypothesis that the pill bugs spread equally among the four sections. Give your answer to two decimal places.
Type a number.
Show the answer
Expected = 60 ÷ 4 = 15 per section. (24 − 15)² ÷ 15 = 5.40; (14 − 15)² ÷ 15 = 0.07; (13 − 15)² ÷ 15 = 0.27; (9 − 15)² ÷ 15 = 2.40. χ² = 122 ÷ 15 = 8.13.
- Answer: 8.13
6. Which statement about the test is correct?
- The null hypothesis is rejected at p = 0.05 (8.13 > 7.82) but not at p = 0.01 (8.13 < 11.34).
- The null hypothesis is rejected at both p = 0.05 and p = 0.01, because 8.13 is larger than 3.84.
- The null hypothesis is not rejected at either level, because 8.13 is less than 9.49, the value for 4 sections.
- The null hypothesis is rejected at p = 0.01 but not at p = 0.05, because the stricter level is easier to pass.
Show the answer
With df = 3, χ² = 8.13 exceeds 7.82 (p = 0.05) but not 11.34 (p = 0.01). So 0.01 < p < 0.05: significant at the usual 0.05 level, but not at the stricter 0.01 level.
- Correct: The null hypothesis is rejected at p = 0.05 (8.13 > 7.82) but not at p = 0.01 (8.13 < 11.34).: Correct.
- The null hypothesis is rejected at both p = 0.05 and p = 0.01, because 8.13 is larger than 3.84.: 3.84 is the df = 1 value; this test has df = 3.
- The null hypothesis is not rejected at either level, because 8.13 is less than 9.49, the value for 4 sections.: Four sections give df = 3, not 4.
- The null hypothesis is rejected at p = 0.01 but not at p = 0.05, because the stricter level is easier to pass.: A stricter level needs a larger χ², so it is harder to reach, not easier.
7. Which section contributed most to the chi-square value, and what does that suggest?
- Dark and moist (5.40 of 8.13): far more bugs gathered there than chance predicts.
- Light and dry (2.40 of 8.13): far fewer bugs went there than in any other section of the chamber.
- Dark and dry (0.07 of 8.13): its count was closest to expected, so it drives the result.
- Each section contributed equally, because the expected value was 15 in each of the sections.
Show the answer
Dark-moist's term, (24 − 15)² ÷ 15 = 5.40, is two thirds of the total; it is where observed and expected differ most.
- Correct: Dark and moist (5.40 of 8.13): far more bugs gathered there than chance predicts.: Correct.
- Light and dry (2.40 of 8.13): far fewer bugs went there than in any other section of the chamber.: Light-dry contributes 2.40, the second largest share; it is not the main driver.
- Dark and dry (0.07 of 8.13): its count was closest to expected, so it drives the result.: A term near zero means a count close to expected; it adds almost nothing.
- Each section contributed equally, because the expected value was 15 in each of the sections.: Equal expected values do not give equal contributions; observed counts differ.
Part 9 · Summary
Summary
The chi-square test compares observed counts with the counts expected under a null hypothesis: χ² = Σ (o − e)² ÷ e. Degrees of freedom are categories − 1. If χ² is greater than the critical value at p = 0.05, the deviation is unlikely to be chance and the null is rejected; otherwise you fail to reject it. Use counts, not percentages, and never "prove" or "accept" a hypothesis.
Part 10 · Up next
What comes next
Part 11 · Connections