Chi-square goodness-of-fit test
The chi-square goodness-of-fit test compares how often each category occurred in your data with how often you’d expect it to under some hypothesis. It’s the one-variable member of the chi-square family.
When to use it
- Do customers choose equally among four product designs?
- Does a sample’s ethnic mix match census proportions?
- Do offspring follow the 3:1 ratio predicted by Mendelian genetics?
- Is a die fair?
Hypotheses and formula
- H₀: the population proportions equal the expected proportions.
- H₁: at least one proportion differs.
χ² = Σ (Observed − Expected)² / Expected, with df = categories − 1
Each expected count is N × that category’s expected proportion.
Assumptions
- Counts of individual cases, not percentages or means.
- Each case falls in exactly one category, and cases are independent.
- Expected counts of at least 5 in every category. If not, combine sparse categories (if that makes sense) or use an exact multinomial test.
Worked example: are hair colours equally common?
In a 1974 survey of 592 statistics students at the University of Delaware (R’s HairEyeColor), hair colour was: 108 black, 286 brown, 71 red and 127 blond. Are the four colours equally common? Under equal proportions we’d expect 592 / 4 = 148 of each.
GOF_CELL: {"level": "Black", "observed": 108, "expected": 148.0, "proportion": 0.25}
GOF_CELL: {"level": "Blond", "observed": 127, "expected": 148.0, "proportion": 0.25}
GOF_CELL: {"level": "Brown", "observed": 286, "expected": 148.0, "proportion": 0.25}
GOF_CELL: {"level": "Red", "observed": 71, "expected": 148.0, "proportion": 0.25}
Chi-square statistic: 182.5270
P-value: 2.51e-39
Degrees of freedom: 3
Cohen's w: 0.5553
N: 592
Missing values excluded: 0> chisq.test(margin.table(HairEyeColor, 1)) Chi-squared test for given probabilities data: margin.table(HairEyeColor, 1) X-squared = 182.53, df = 3, p-value < 2.2e-16
The same χ² and df. R stops printing p below 2.2 × 10⁻¹⁶. Report it as p < .001. Analytika’s test suite checks the statistic and Cohen’s w against R.
Interpretation
- χ²(3) = 182.53, p < .001: hair colours are clearly not equally common.
- Cohen’s w = .56: a large departure (0.1 small, 0.3 medium, 0.5 large).
- Where the misfit lies: brown hair (286 observed vs 148 expected) is far more common than equal shares would predict, and red (71) far less.
The test says the distribution isn’t uniform, but not which categories differ. Compare each category’s observed and expected counts, or use standardised residuals, as in the test of independence.
APA write-up
A chi-square goodness-of-fit test showed that hair colours were not equally distributed, χ²(3, N = 592) = 182.53, p < .001, w = .56. Brown hair (n = 286) was more common, and red hair (n = 71) less common, than the 148 expected under equal proportions.
Testing against other proportions
Equal proportions are just one option. To test whether a sample matches a population (say 60% / 30% / 10%), enter those proportions as the expected values. Choose them from theory or external data before looking at your counts, otherwise the test is meaningless.
Common mistakes
- Using percentages instead of counts.
- Choosing expected proportions after seeing the data.
- Ignoring small expected counts in rare categories.
- Treating a non-significant result as proof of a match. It only means no evidence of a mismatch.
How to run it
- SPSS: Analyze → Nonparametric Tests → Legacy Dialogs → Chi-square.
- R:
chisq.test(counts, p = c(0.6, 0.3, 0.1)) - Python:
scipy.stats.chisquare(observed, f_exp=expected) - Analytika: ask whether a column’s categories are equally common, or give the proportions to test against. Our free chi-square calculator also runs this test.
More in Categorical data
Try it with the free tools
Run this on your own data
Upload a dataset and ask your question in plain English. Analytika checks the assumptions, picks the test, runs it, and writes the results up in APA format.