Skip to main content
Daily Math Minute

Unit 8: Inference for Categorical Data: Chi-Square

Chi-Square Goodness of Fit

Testing whether a categorical variable follows a hypothesized distribution.

Advanced25 min lesson3 min readUpdated August 12, 2026Author not yet attributed

Testing Whether a Categorical Variable Matches a Claimed Distribution

A die is rolled 120 times: face 1 comes up 15 times, face 2 comes up 14, face 3 comes up 25, face 4 comes up 28, face 5 comes up 16, face 6 comes up 22. Before reading on: if the die really were fair, about how many times would you expect each face to appear in 120 rolls — and how far do the actual counts drift from that?

Definition — Chi-Square Goodness-of-Fit Test

A chi-square goodness-of-fit test compares observed counts across categories of one variable to the counts expected under a hypothesized distribution, H₀. The test statistic is χ² = Σ(observed − expected)²/expected, with df = (number of categories) − 1. Every expected count must be at least 5 for the test to be valid.
χ2=(OE)2E\chi^2 = \sum \frac{(O - E)^2}{E}

Worked Example — Conducting a Goodness-of-Fit Test

H₀: the die is fair (each face has probability 1/6). Ha: the die is not fair. Expected count per face: 120 × (1/6) = 20 (all ≥ 5, condition satisfied). χ² = (15−20)²/20 + (14−20)²/20 + (25−20)²/20 + (28−20)²/20 + (16−20)²/20 + (22−20)²/20 = 1.25 + 1.8 + 1.25 + 3.2 + 0.8 + 0.2 = 8.5. df = 6−1 = 5. The critical value for df=5, α=0.05 is 11.070.

Since χ² = 8.5 < 11.070, fail to reject H₀: there is not convincing evidence that this die is unfair. The observed counts do drift from 20 in each direction, but not by more than ordinary chance variation would produce if the die really were fair.

Tip

The chi-square statistic can never be negative — squaring the difference between observed and expected counts means every category contributes a non-negative amount, however small the discrepancy.

Common Mistakes

  • Computing expected counts as equal shares of the observed total without reference to the actual hypothesized proportions in H₀.

    Expected counts come from H₀'s claimed proportions (here, 1/6 per face) applied to the sample size — for a goodness-of-fit test with unequal hypothesized proportions, the expected counts would differ across categories accordingly.

Key Takeaways

  • A goodness-of-fit test compares one categorical variable's observed distribution to a specific hypothesized distribution.
  • χ² = Σ(O−E)²/E, with df = categories − 1, and every expected count must be at least 5.
  • A large χ² relative to its critical value signals the observed counts drift more than chance alone would explain.

Summary

The next lesson extends the same chi-square logic to test for an association between two categorical variables — directly revisiting the two-way table from Unit 2.