What the goodness-of-fit test does
The chi-square goodness-of-fit test checks whether observed counts in several categories match an expected distribution. Is a die fair? Do customers arrive equally on each weekday? Do genetic crosses follow Mendel’s 9:3:3:1 ratio? Does a sample match the age profile of the census? In each case you compare what you counted with what a hypothesis predicts.
The formula
χ² = Σ (O − E)² ÷ E
- O: observed count in each category;
- E: expected count = N × expected proportion.
Under the null hypothesis that the data follow the expected distribution, χ² follows a chi-square distribution with k − 1 − m degrees of freedom, where k is the number of categories and m the number of parameters estimated from the data (0 when the expected proportions are fixed in advance).
Example
A die is rolled 60 times and shows 5, 8, 9, 8, 10 and 20 for faces one to six. If the die is fair, each face is expected 10 times:
- χ² = (25 + 4 + 1 + 4 + 0 + 100) ÷ 10 = 13.4, with 5 degrees of freedom;
- p ≈ 0.020: significant at α = 0.05; the critical χ² is 11.07;
- Cohen’s w ≈ 0.47, a large effect, driven mostly by the twenty sixes.
Custom proportions
Choose “custom proportions” and enter the expected share of each category, in percent. The shares are rescaled if they do not add up exactly to 100. For a 9:3:3:1 genetic ratio, enter 56.25, 18.75, 18.75 and 6.25.
Conditions of use
- Observations are independent, and each falls into exactly one category.
- Use counts, not percentages or means.
- Expected counts should be at least 5 in every category (some authors accept a few between 1 and 5 if most are above 5). Otherwise, merge neighboring categories or use an exact multinomial test.
Effect size and interpretation
With large samples, tiny deviations become significant. Cohen’s w = √(χ² ÷ N) helps judge practical importance: about 0.1 is small, 0.3 medium and 0.5 large. To see which categories drive the result, look at the standardized residuals (O − E) ÷ √E; values beyond about ±2 stand out.
Related tests
- Testing whether two categorical variables are associated in a contingency table is the chi-square test of independence, which uses (rows − 1) × (columns − 1) degrees of freedom.
- For two categories, the goodness-of-fit test is equivalent to a two-sided test of one proportion.