Salick Academy

The Chi-Squared Test

No calculator

Every test so far has concerned a mean. The chi-squared test concerns counts: it asks whether the frequencies you observed differ from what a hypothesis predicts by more than chance would explain.

The idea of a chi-squared test

Compare observed frequencies OO with the expected frequencies EE that H0H_0 predicts. If they are close, H0H_0 survives; if they diverge, it does not.

Two standard uses:

  • Goodness of fit — do the data follow a stated distribution? H0H_0: they do.
  • Independence (a contingency table) — are two categorical variables associated? H0H_0: they are independent.

Expected frequencies

For goodness of fit, EE comes from the hypothesised distribution. If a fair die is rolled 60 times, each face is expected 606=10\frac{60}{6} = 10 times.

For a contingency table:

E=row total×column totalgrand totalE = \frac{\text{row total} \times \text{column total}}{\text{grand total}}

Pass Fail Total
Method A 40 20 60
Method B 30 30 60
Total 70 50 120

E(A, Pass)=60×70120=35E(A, Fail)=60×50120=25E(\text{A, Pass}) = \frac{60 \times 70}{120} = 35 \qquad E(\text{A, Fail}) = \frac{60 \times 50}{120} = 25

and by the same calculation E(B, Pass)=35E(\text{B, Pass}) = 35, E(B, Fail)=25E(\text{B, Fail}) = 25.

The test statistic

χ2=(OE)2E\chi^2 = \sum \frac{(O-E)^2}{E}

For the table above:

(4035)235+(2025)225+(3035)235+(3025)225\frac{(40-35)^2}{35} + \frac{(20-25)^2}{25} + \frac{(30-35)^2}{35} + \frac{(30-25)^2}{25} =0.714+1+0.714+1=3.43= 0.714 + 1 + 0.714 + 1 = 3.43

Each term measures a squared discrepancy relative to what was expected: being 5 out of 25 matters more than being 5 out of 35.

Degrees of freedom

Goodness of fit:

ν=(number of categories)1(parameters estimated from the data)\nu = (\text{number of categories}) - 1 - (\text{parameters estimated from the data})

Six die faces with nothing estimated gives ν=5\nu = 5.

Contingency table:

ν=(r1)(c1)\nu = (r-1)(c-1)

A 2×22 \times 2 table gives ν=1\nu = 1; a 3×43 \times 4 table gives ν=2×3=6\nu = 2 \times 3 = 6.

Some critical values at the 5% level:

ν\nu 1 2 3 5 6
χ0.052\chi^2_{0.05} 3.841 5.991 7.815 11.070 12.592

Contingency tables

Test at the 5% level whether pass rate is associated with teaching method, for the table above.

1. Hypotheses. H0H_0: method and outcome are independent. H1H_1: they are associated.

2. Expected frequencies. 35,25,35,2535, 25, 35, 25 as computed.

3. Statistic. χ2=3.43\chi^2 = 3.43.

4. Degrees of freedom and critical value. ν=(21)(21)=1\nu = (2-1)(2-1) = 1, so χ0.052=3.841\chi^2_{0.05} = 3.841.

5. Compare and conclude. 3.43<3.8413.43 < 3.841, so do not reject H0H_0: at the 5% level there is insufficient evidence of an association between teaching method and pass rate.

Conditions and interpretation

All expected frequencies must be at least 5. Small expected values make the (OE)2E\frac{(O-E)^2}{E} term unstable, and the chi-squared approximation breaks down.

If some are too small, combine adjacent categories until every expected value reaches 5 — and recalculate the degrees of freedom for the reduced number of categories.

Other requirements: the data must be frequencies from a random sample, and the observations independent — each item counted in exactly one cell.