Statistics Quest

Chi-square test of independence (and homogeneity)

Tests whether two categorical variables are associated in an r × c contingency table by comparing observed counts with those expected under independence.

Eij=Ri CjN,X2=∑i,j(Oij−Eij)2Eij,df=(r−1)(c−1)E_{ij} = \frac{R_i\,C_j}{N},\qquad X^2 = \sum_{i,j}\frac{(O_{ij} - E_{ij})^2}{E_{ij}},\qquad df = (r-1)(c-1)
Oij,EijO_{ij}, E_{ij}
Observed and expected counts in row i, column j.
Ri,CjR_i, C_j
Row i total and column j total.
NN
Grand total.
r,cr, c
Numbers of rows and columns.
Oij−EijEij(1−Ri/N)(1−Cj/N)\frac{O_{ij} - E_{ij}}{\sqrt{E_{ij}(1 - R_i/N)(1 - C_j/N)}}
Adjusted standardised residual: roughly N(0, 1) under H₀; values beyond about ±2 show which cells drive the association.
Ri/N,Cj/NR_i/N, C_j/N
Row and column proportions.

When to use

Two categorical variables measured on the same units (independence), or one categorical outcome compared across several groups (homogeneity) — the arithmetic is identical. For 2×2 tables with small expected counts use Fisher's exact test.

Assumptions

  • Independent units, each in exactly one cell; counts, not percentages.
  • Expected counts mostly ≥ 5 (the engine reports how many are below 5).
  • Yates' continuity correction is optional (2×2 only) and off by default.

How to interpret

  • A small p-value is evidence of association; it says nothing about direction or cause.
  • Describe the association with conditional percentages (row or column percentages) and adjusted residuals.
  • Effect size: Cramér's V=X2/(N(min⁡(r,c)−1))V = \sqrt{X^2/(N(\min(r,c)-1))} (0 = no association, 1 = perfect).

Common mistakes

  • Using row percentages or means instead of counts.
  • Counting the same person in several cells (e.g. multiple-response questions).
  • Interpreting a significant result in a huge sample as a strong association — check V.

Example

Preferred plan (A, B, C) by region: North 20, 30, 25; South 30, 20, 25 (N = 150). All Eij=25E_{ij} = 25. X2=4.0X^2 = 4.0 on 2 df, p=0.135p = 0.135, V=0.163V = 0.163. Adjusted residuals are ±1.73 for plans A and B: no convincing evidence that preferences differ by region.