Statistics Quest

Chi-square goodness-of-fit test

Tests whether the counts in k categories are consistent with a stated set of proportions.

X2=∑i=1k(Oi−Ei)2Ei,Ei=Npi,df=k−1−mX^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i},\qquad E_i = N p_i,\qquad df = k - 1 - m
OiO_i
Observed count in category i.
EiE_i
Expected count under H₀.
pip_i
Proportion for category i stated by H₀.
NN
Total count.
mm
Number of parameters estimated from the data (e.g. 1 for a fitted Poisson mean; 0 when all p_i are given).

When to use

One categorical variable and a hypothesised distribution: is a die fair, do calls spread evenly over weekdays, do counts follow a fitted Poisson model? The p-value is the upper tail of χdf2\chi^2_{df}.

Assumptions

  • Independent observations, each counted in exactly one category.
  • Counts, not percentages or means.
  • Expected counts large enough: all Ei≥5E_i \ge 5 is the classic rule (Cochran's: no more than 20% below 5, none below 1). Merge sparse categories or simulate otherwise.

How to interpret

A small p-value says the observed distribution differs from the hypothesised one; look at the contributions (O−E)2/E(O-E)^2/E or residuals (O−E)/E(O-E)/\sqrt E to see where. A large p-value means the data are consistent with the model, not that the model is right.

Common mistakes

  • Running the test on percentages (the statistic depends on the counts).
  • Forgetting to subtract estimated parameters from the df.
  • Checking observed counts instead of expected counts against the "≥ 5" rule.

Example

60 rolls of a die: 8, 12, 9, 15, 10, 6. Each Ei=10E_i = 10. Contributions 0.4, 0.4, 0.1, 2.5, 0, 1.6, so X2=5.0X^2 = 5.0 on 5 df, p=0.42p = 0.42: no evidence that the die is unfair (60 rolls also have little power to detect a modest bias).