Chi-Square Test

Testing whether observed counts match expected ones (goodness of fit) or whether two categorical variables are independent.

Chi-square distribution — right-tail p-value
χ²=6.0p≈0.199df=405101520
df=4
χ²=6.0
p-value ≈ 0.1992 → fail to reject H₀
Definition

The chi-square test (χ2\chi^2) tests whether categorical data matches an expected distribution.

The test statistic is:

χ2=∑i=1k(Oi−Ei)2Ei\chi^2 = \sum_{i=1}^{k} \frac{(O_i - E_i)^2}{E_i}

where OiO_i are observed counts and EiE_i are expected counts under H0H_0.

Under H0H_0, this follows a χ2\chi^2 distribution with k−1k - 1 degrees of freedom (for goodness of fit) or (r−1)(c−1)(r-1)(c-1) for a contingency table with rr rows and cc columns.

Key properties
  • The χ2\chi^2 statistic is always non-negative, and exactly 0 only when observed counts match expected counts perfectly
  • Larger deviations from expected counts contribute quadratically, so a few large discrepancies can dominate many small ones
  • The approximation to the χ2\chi^2 distribution improves as sample size grows — it's asymptotic, not exact
  • A significant result only establishes association (for independence tests), never causation
Is a die fair?

Roll a die 60 times. Under H0H_0 (fair die), expect 10 of each face. Observed: 8, 14, 11, 9, 7, 11.

χ2=(8−10)210+(14−10)210+…=0.4+1.6+0.1+0.1+0.9+0.1=3.2\chi^2 = \frac{(8-10)^2}{10} + \frac{(14-10)^2}{10} + \ldots = 0.4+1.6+0.1+0.1+0.9+0.1 = 3.2

With 5 df, the critical value at α=0.05\alpha=0.05 is 11.07. Since 3.2<11.073.2 < 11.07, fail to reject — no evidence the die is unfair.

Try it

A genetics experiment expects a 9:3:3:1 ratio in a cross (Mendelian genetics). Observed counts: 315, 108, 101, 32 (total 556). Expected: 556×(9/16,3/16,3/16,1/16)556 \times (9/16, 3/16, 3/16, 1/16). Compute χ2\chi^2 and use the fact that the critical value with 3 df at α=0.05\alpha=0.05 is 7.81.

Solution

Expected: 312.75, 104.25, 104.25, 34.75.

χ2=(315−312.75)2/312.75+(108−104.25)2/104.25+(101−104.25)2/104.25+(32−34.75)2/34.75\chi^2 = (315-312.75)^2/312.75 + (108-104.25)^2/104.25 + (101-104.25)^2/104.25 + (32-34.75)^2/34.75 ≈0.016+0.135+0.101+0.218=0.47\approx 0.016 + 0.135 + 0.101 + 0.218 = 0.47

Since 0.47<7.810.47 < 7.81, we fail to reject — the data fits Mendel's expected 9:3:3:1 ratio.

Related concepts