STEM-TutorLearn • Practice • ExcelBook Free DemoFree demo

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
  1. When to use a chi-square test
  2. The three types
  3. The test statistic
  4. Degrees of freedom and expected counts
  5. Conditions
  6. Worked examples
  7. Using a graphing calculator
  8. Writing the conclusion
  9. Follow-up analysis
  10. Common mistakes
  11. Practice questions
  12. Frequently asked questions
  13. Key takeaways
  14. Related guides

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

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

Conditions

  1. Random: data come from a random sample or randomised experiment.
  2. 10% condition: when sampling without replacement, n is at most 10% of the population.
  3. 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.

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.

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.

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

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
3.

Q2. A two-way table has 3 rows and 4 columns. What are the degrees of freedom?

Show answer
(3 − 1)(4 − 1) = 6.

Q3. Observed 30, expected 25. What does this cell contribute to χ²?

Show answer
25/25 = 1.

Q4. Which test: a random sample of voters is classified by age group and preferred candidate?

Show answer
Test for independence: one sample, two variables.

Q5. Which test: random samples from three cities are asked their preferred transport?

Show answer
Test for homogeneity: several samples, one variable.

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