Chi-squared Test (AI SL)
The \(\chi^2\) test checks whether two categorical variables are associated (the test for independence, using a contingency table) or whether a set of observed frequencies matches a claimed distribution (the goodness-of-fit test). Both compare observed counts to the counts you'd expect if there were no association, then let the GDC turn that comparison into a \(p\)-value. It's part of the broader Hypothesis Testing topic.
32 questions on this sub-topic.
Degrees of freedom and expected frequency
Covered under IB syllabus reference SL4.11: the \(\chi^2\) test for independence with contingency tables and degrees of freedom, the \(\chi^2\) goodness-of-fit test, significance levels and \(p\)-values.
Degrees of freedom
\(\nu = (\text{rows}-1)(\text{columns}-1)\)
This is for the test for independence on a contingency table. A goodness-of-fit test instead uses \(\nu = (\text{number of categories}) - 1\).
Expected frequency
\(E = \dfrac{\text{row total} \times \text{column total}}{\text{grand total}}\)
Expected frequency \(>5\) in every cell - this is not in the formula booklet, it's a syllabus requirement for the \(\chi^2\) approximation to be valid.
Need the full syllabus wording, formula table, and GDC key sequences? See Hypothesis Testing.
Worked examples
In a contingency table, a row total is 40, a column total is 30, and the grand total is 120.
Find the expected frequency for that cell.
Worked solution
Under independence, each cell's expected count is
\(E=\dfrac{\text{row total}\times\text{column total}}{\text{grand total}}=\dfrac{40\times 30}{120}=\dfrac{1200}{120}\) M1
\(=10.\) A1
200 cinema-goers are classified by age group (under 30 / 30-60 / over 60) and preferred film genre (action / comedy / drama). Observed frequencies:
| Action | Comedy | Drama | |
|---|---|---|---|
| Under 30 | 40 | 30 | 10 |
| 30-60 | 25 | 35 | 20 |
| Over 60 | 10 | 15 | 15 |
(a) State \(H_0\) and \(H_1\).
(b) Find the degrees of freedom.
(c) Using the GDC, find the \(\chi^2\) statistic and \(p\)-value.
(d) State the conclusion at the 5% level.
Worked solution
(a) \(H_0\): age group and film genre are independent; \(H_1\): they are not independent. A1
(b) df. \((3-1)(3-1) = 4\). A1
(c) GDC. M1
Row totals 80, 80, 40; column totals 75, 80, 45; grand total 200. Expected: \(E_{11}=30,\ E_{12}=32,\ E_{13}=18,\ E_{21}=30,\ E_{22}=32,\ E_{23}=18,\ E_{31}=15,\ E_{32}=16,\ E_{33}=9.\) \(\chi^2 \approx 14.08,\quad p \approx 0.0288\). A1
(d) \(p \approx 0.0288 < 0.05\): reject \(H_0\). R1
There is significant evidence that age group and film preference are associated. A1
Common mistakes
- Treating "reject \(H_0\)" as proof that \(H_1\) is true. A hypothesis test only measures the strength of evidence at a chosen significance level - it never proves anything with certainty, in either direction.
- Forgetting the expected-frequency-at-least-5 rule. If any cell's expected frequency is 5 or below, the \(\chi^2\) approximation becomes unreliable - categories should be combined first.
- Using the wrong degrees-of-freedom formula. \(\nu = (\text{rows}-1)(\text{columns}-1)\) is for the test for independence on a contingency table; a goodness-of-fit test uses \(\nu = (\text{categories}) - 1\) instead. Mixing the two up gives the wrong critical value and the wrong \(p\)-value.
Ready to practise properly?
32 chi-squared questions, marked instantly like the real exam.
Quick answers
How do you find the degrees of freedom for a chi-squared test of independence?
For a contingency table, \(\nu = (\text{rows}-1)(\text{columns}-1)\). For a goodness-of-fit test it is instead the number of categories minus 1.
How do you calculate an expected frequency in a contingency table?
\(E = \dfrac{\text{row total} \times \text{column total}}{\text{grand total}}\), calculated for each cell under the assumption that the two variables are independent.