Chi-Square Goodness-of-Fit
A chi-square goodness-of-fit test checks whether observed counts in several categories of one variable match the counts you'd expect under a claimed distribution, using the statistic sum of (observed - expected)2 / expected.
You can't just eyeball whether a bag of candy matches its advertised color mix. Real bags vary by chance even when the company's claim is true, so you need a way to measure how far observed counts drift from expected counts, and whether that drift is bigger than random sampling would explain. The chi-square goodness-of-fit test gives you one number that captures the total mismatch across every category at once.
Start with one categorical variable and a claimed distribution, like a company's stated 1/3 red, 1/3 blue, 1/3 green. Multiply the claimed proportions by your sample size to get expected counts for each category. Then for every category, subtract expected from observed, square that difference, and divide by the expected count. Squaring keeps every term positive so deviations don't cancel out, and dividing by expected scales each gap relative to how many you expected there, so a miss of 10 matters more when you expected 20 than when you expected 200. Add up these terms across all categories to get the chi-square statistic. A small value means observed counts stayed close to the claim; a large value means they drifted far enough that you'd question the claim.
This test sits next to the chi-square test for independence, and the two get confused constantly because they use the same formula and the same chi-square distribution for the p-value. The difference is what question each one answers. Goodness-of-fit takes one variable and asks whether its distribution matches a specific claimed set of proportions. Independence takes two variables, arranged in a two-way table, and asks whether knowing one tells you anything about the other. Same arithmetic, different setup and different hypotheses.
Key terms
- Observed count
- The actual number of data values that fall into a given category.
- Expected count
- The number you'd predict in a category if the claimed distribution were exactly true, found by proportion times sample size.
- Chi-square statistic
- The sum across categories of (observed minus expected) squared, divided by expected, measuring total mismatch.
- Goodness-of-fit test
- A chi-square test comparing one categorical variable's observed distribution to a single claimed distribution.
- Test for independence
- A chi-square test checking whether two categorical variables are related, using counts from a two-way table.
Watch it explained
Check yourself
End of topic.