IB Maths AI SL Topic 4 — Hypothesis Testing Paper 2 χ2 contingency table ~8 min read

Chi-squared Test for Independence

A χ2 test for independence checks whether two categorical variables (e.g. gender and car colour) are related. You compare the observed frequencies in a contingency table against the frequencies you’d expect if the variables were independent. A big mismatch ⇒ reject H₀ ⇒ the variables are associated. The GDC does the heavy lifting; you handle the setup and conclusion.

📘 What you need to know

The contingency table & expected values

If two variables are independent, the cell counts should follow the ratio “row share × column share × total”. Any cell far from its expected value is evidence against independence. The χ2 statistic adds up all those deviations.

From contingency table to decision in three stepsObserved (data) A B C M 35 40 25 F 45 30 25 200 customers, row totals 100 each row × col / totalExpected (if indep.) A B C M 40 35 25 F 40 35 25 e.g. 100 × 80 / 200 = 40 Σ(O−E)²/E χcalc² & degrees of freedom χcalc² ≈ 2.68 ν = (2−1)(3−1) = 2 p ≈ 0.262Decision rule if χ² > critical value reject H₀ → associated if χ² < critical value accept H₀ → independent small χ² (close to 0) → observed matches expected → variables look independent
Three-step flow. Take the observed table, compute expected frequencies using row × col ÷ total, then sum (OE)2/E to get χ2. Compare with the critical value (or compare p with α) to decide.
The expected-frequency formula Eij  =  row total × column totaloverall total
 
degrees of freedom:  ν = (m − 1)(n − 1)

🧭 Recipe — full χ2 test for independence

  1. State H₀ and H₁: “variable X is independent of variable Y” vs “not independent”.
  2. Find degrees of freedom: ν = (rows−1)(cols−1).
  3. Enter the observed matrix on the GDC and run the 2-way χ2 test — it returns χ2calc, the p-value, and the expected matrix.
  4. Compare: χ2calc vs critical value, OR p vs α.
  5. Conclude in context: “sufficient/insufficient evidence to suggest X is not independent of Y“.
Two routes, one answer: comparing χ2 with the critical value, OR comparing p with α, always give the same decision. Use whichever the question hands you.

Worked examples

WE 1

State the hypotheses

A researcher wants to test whether handedness (left/right) is related to favourite sport (football, tennis, basketball) among a group of students.

Write the null and alternative hypotheses.

Identify the two variables X = handedness, Y = favourite sport Write hypotheses in context H₀: handedness is independent of favourite sport H₁: handedness is NOT independent of favourite sport H₀: independent · H₁: not independent name both variables in plain words — don’t write “X is independent of Y”. Examiners want the actual context.
WE 2

Degrees of freedom

A contingency table has 5 rows and 3 columns. Find the number of degrees of freedom for a χ2 test of independence.

Apply v = (m − 1)(n − 1) v = (5 − 1)(3 − 1) = 4 × 2 = 8 v = 8 “degrees of freedom” tells you how many cells are independent — once 8 cells are fixed, the totals force the rest.
WE 3

Expected frequency from totals

In a contingency table the overall total is 200. One row has a total of 60 and one column has a total of 50. Find the expected frequency for the cell at the intersection of that row and column.

Apply E = (row total × col total) / overall E = (60 × 50) / 200 = 3000 / 200 = 15 E = 15 if variables were truly independent, this cell would have exactly 15 in it. Differences from 15 are what build the χ² statistic.
WE 4

Full test using the p-value — accept H₀

A survey of 200 customers records their gender and preferred coffee shop (A, B, C):

 Shop AShop BShop C
Male354025
Female453025

A χ2 test of independence is performed at the 5% significance level. The GDC gives χ2calc ≈ 2.68 and p ≈ 0.262. State the conclusion.

Hypotheses H₀: gender independent of coffee shop preference H₁: gender NOT independent of coffee shop preference v = (2−1)(3−1) = 2 Compare p with α p = 0.262, α = 0.05 0.262 > 0.05 → accept H₀ insufficient evidence that gender and shop preference are associated accepting H₀ means the data is CONSISTENT with independence — it doesn’t prove they’re independent, just that we don’t have enough evidence to reject.
WE 5

Full test using the critical value — reject H₀

The same survey now records gender and preferred car colour:

 RedBlueBlack
Male204040
Female502525

A χ2 test is performed at 5%. The critical value is 5.991. The GDC gives χ2calc ≈ 19.78. State the conclusion.

Hypotheses H₀: gender independent of car colour preference H₁: NOT independent v = (2−1)(3−1) = 2 Compare χ² stat with critical value 19.78 > 5.991 → reject H₀ sufficient evidence that gender and car colour preference are associated big χ² (well above 5.991) means observed counts are far from “independent” expectations. The association is strong here.
WE 6

Find a missing observed value

A partial contingency table is shown. Find the missing value in the cell (X, B).

 ABCTotal
X25?1560
Y20251560
Total4530120

Use the row X total = 60 25 + ? + 15 = 60 ? = 60 − 25 − 15 = 20 Check using column B total column B = 20 + 25 = 45 overall: 45 + 45 + 30 = 120 ✓ missing value = 20 a contingency table is fully determined by its totals and (m−1)(n−1) interior cells — that’s where the “degrees of freedom” formula comes from.

💡 Top tips

⚠ Common mistakes

Next up: Goodness of Fit Test. Same test statistic χ2 = Σ(OE)2/E, but now the question is whether data fits a specific distribution — uniform, binomial, or normal. You’ll compute the expected frequencies yourself using the given distribution, then run the same comparison.

Need help with AI SL Hypothesis Testing?

Get 1-on-1 help from an IB examiner who knows exactly what Paper 1 & 2 are looking for.

Book Free Session →