The chi-square test, explained with examples
The chi-square test checks whether observed counts in categories differ from what we would expect by chance. It is the main tool in AP Statistics for categorical data.
On this page
When to use a chi-square test
Use a chi-square (χ²) test when your data are counts in categories, not measurements. Examples include how many people chose each flavour, how many plants had each colour, or how many students in each year group prefer each subject. If your data are numbers you can average, such as heights or times, you need a t-test or z-test instead.
The three types
- Goodness of fit: one categorical variable, one sample. Does the distribution match a claimed distribution? For example, is a dice fair?
- Test for homogeneity: one categorical variable, several samples or groups. Is the distribution the same across groups? For example, do three schools have the same distribution of favourite sport?
- Test for independence: two categorical variables, one sample. Is there an association between them? For example, in one survey, is handedness related to eye colour?
Homogeneity and independence use the same calculations; the difference is in how the data were collected and how you word the hypotheses.
The test statistic
χ² = Σ (Observed − Expected)² / Expected
Each category contributes a non-negative amount. If observed counts are close to expected, χ² is small. Large differences make χ² large, which is evidence against the null hypothesis. The chi-square distribution is skewed right, and its shape depends on the degrees of freedom.
Degrees of freedom and expected counts
- Goodness of fit: df = number of categories − 1. Expected count = n × claimed proportion.
- Two-way table: df = (rows − 1)(columns − 1). Expected count = (row total × column total) / grand total.
Conditions
- Random: data come from a random sample or randomised experiment.
- 10% condition: when sampling without replacement, n is at most 10% of the population.
- Large counts: all expected counts are at least 5. Check expected counts, not observed ones.
Worked examples
Example 1: goodness of fit
A dice is rolled 120 times. Observed counts for 1 to 6 are 15, 25, 18, 22, 14, 26. Test at α = 0.05 whether the dice is fair.
- H0: the dice is fair, each face has probability 1/6. Ha: at least one probability differs from 1/6.
- Expected count for each face: 120/6 = 20. All are at least 5.
- χ² = (25 + 25 + 4 + 4 + 36 + 36)/20 = 130/20 = 6.5, with df = 5.
- P-value ≈ 0.26. Since 0.26 > 0.05, fail to reject H0. There is not convincing evidence that the dice is unfair.
Example 2: expected counts in a two-way table
In a survey of 200 students, 120 are in Year 12 and 80 in Year 13. 90 students prefer maths and 110 prefer science. Find the expected count for Year 12 students who prefer maths.
- Expected = (row total × column total)/grand total = 120 × 90/200 = 54.
Example 3: test for independence
A random sample of 100 adults is classified by exercise (yes/no) and sleep quality (good/poor). Observed: exercise and good 35, exercise and poor 15, no exercise and good 25, no exercise and poor 25. Test for an association at α = 0.05.
- H0: exercise and sleep quality are independent. Ha: they are associated.
- Row totals 50 and 50; column totals 60 good and 40 poor. Expected counts: 30, 20, 30, 20, all at least 5.
- χ² = 25/30 + 25/20 + 25/30 + 25/20 = 0.833 + 1.25 + 0.833 + 1.25 ≈ 4.17, df = 1.
- P-value ≈ 0.041 < 0.05, so reject H0. There is convincing evidence of an association between exercise and sleep quality among adults. This was an observational study, so it does not show that exercise causes better sleep.
Using a graphing calculator
On a TI-84, a goodness-of-fit test uses χ² GOF-Test: put observed counts in one list and expected counts in another, and enter the degrees of freedom. For a two-way table, enter the observed counts as a matrix and use χ²-Test; the calculator stores the expected counts in a second matrix, which you can view to check the large counts condition. On the exam, still write the hypotheses, conditions, test statistic, df and P-value, because the calculator output alone does not earn full credit.
Writing the conclusion
A full conclusion links the P-value to α, makes a decision, and states it in context: “Because the P-value of 0.041 is less than α = 0.05, we reject H0. There is convincing evidence that …”. Never say you have proved Ha, and never say you accept H0. If you fail to reject, say there is not convincing evidence for the alternative.
Follow-up analysis
After a significant result, AP questions may ask which category contributed most. Look for the largest term (O − E)²/E in the sum, then describe the direction: was the observed count higher or lower than expected? In Example 1, faces 5 and 6 contributed most, with 5 appearing less often and 6 more often than expected.
Common mistakes
- Using percentages or proportions instead of counts in the formula.
- Checking observed counts instead of expected counts for the large counts condition.
- Wrong degrees of freedom, especially for two-way tables.
- Stating that one variable causes the other from an observational study.
- Writing hypotheses that mix up the three test types.
Practice questions
Try each one before opening the answer.
Q1. A goodness-of-fit test has 4 categories. What are the degrees of freedom?
Show answer
Q2. A two-way table has 3 rows and 4 columns. What are the degrees of freedom?
Show answer
Q3. Observed 30, expected 25. What does this cell contribute to χ²?
Show answer
Q4. Which test: a random sample of voters is classified by age group and preferred candidate?
Show answer
Q5. Which test: random samples from three cities are asked their preferred transport?
Show answer
Frequently asked questions
Is the chi-square test on the AP Statistics exam?
Yes. It is Unit 8, inference for categorical data: chi-square, worth about 2 to 5% of the exam, and it often appears in a free-response question.
Can a chi-square test be one-sided?
The test is always right-tailed, because only large values of χ² give evidence against H0. But the hypotheses are not “greater than” or “less than”; they are about whether distributions match.
Is the chi-square test in A level Maths?
No, it is not in A level Maths. It appears in A level Further Maths statistics and in A level Biology.
Key takeaways
- Use chi-square for counts in categories.
- χ² = Σ(O − E)²/E.
- Goodness of fit: df = k − 1. Two-way table: df = (r − 1)(c − 1).
- All expected counts must be at least 5.
- Conclude in context; association is not causation.