IB Maths AI SLTopic 4 — Hypothesis TestingPaper 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
Contingency table: a 2-way table of observed frequencies for two categorical variables.
H₀: variable X is independent of variable Y. H₁: variable X is not independent of variable Y.
Degrees of freedom: for an m × n table, ν = (m − 1)(n − 1).
Expected frequency: Eij = row total × column totaloverall total.
Test statistic: χcalc2 = Σ(Oi − Ei)2Ei. GDC computes it from the matrix.
Reject H₀ if χcalc2 > critical value OR p < α.
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.
Three-step flow. Take the observed table, compute expected frequencies using row × col ÷ total, then sum (O−E)2/E to get χ2. Compare with the critical value (or compare p with α) to decide.
The expected-frequency formulaEij = row total × column totaloverall total
degrees of freedom: ν = (m − 1)(n − 1)
🧭 Recipe — full χ2 test for independence
State H₀ and H₁: “variable X is independent of variable Y” vs “not independent”.
Find degrees of freedom: ν = (rows−1)(cols−1).
Enter the observed matrix on the GDC and run the 2-way χ2 test — it returns χ2calc, the p-value, and the expected matrix.
Compare: χ2calc vs critical value, OR p vs α.
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 variablesX = handedness, Y = favourite sportWrite hypotheses in contextH₀: handedness is independent of favourite sportH₁: handedness is NOT independent of favourite sportH₀: independent · H₁: not independentname 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 = 8v = 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) / overallE = (60 × 50) / 200 = 3000 / 200 = 15E = 15if 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 A
Shop B
Shop C
Male
35
40
25
Female
45
30
25
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.
HypothesesH₀: gender independent of coffee shop preferenceH₁: gender NOT independent of coffee shop preferencev = (2−1)(3−1) = 2Compare p with αp = 0.262, α = 0.050.262 > 0.05 → accept H₀insufficient evidence that gender and shop preference are associatedaccepting 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:
Red
Blue
Black
Male
20
40
40
Female
50
25
25
A χ2 test is performed at 5%. The critical value is 5.991. The GDC gives χ2calc ≈ 19.78. State the conclusion.
HypothesesH₀: gender independent of car colour preferenceH₁: NOT independentv = (2−1)(3−1) = 2Compare χ² stat with critical value19.78 > 5.991→ reject H₀sufficient evidence that gender and car colour preference are associatedbig χ² (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).
A
B
C
Total
X
25
?
15
60
Y
20
25
15
60
Total
45
—
30
120
Use the row X total = 6025 + ? + 15 = 60? = 60 − 25 − 15 = 20Check using column B totalcolumn B = 20 + 25 = 45overall: 45 + 45 + 30 = 120 ✓missing value = 20a 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
GDC does the test: enter the observed table as a matrix, then “2-way” or “chi-squared test”. Read off χ2, p, expected matrix.
Always name the variables in H₀ / H₁ — “gender” and “car colour”, not “X” and “Y“.
Big χ2 = strong evidence against independence; tiny χ2 = data looks consistent with independence.
Two paths, one answer: compare χ2 with critical value OR p with α. The exam will tell you which.
Round χ2 to 3 sf; don’t round the p-value too aggressively (often quote to 3-4 sf).
⚠ Common mistakes
Reversing the inequality: reject H₀ when χ2 is BIG (or p is SMALL). Easy mark loser.
Wrong degrees of freedom: use (rows−1)(cols−1), not rows×cols.
Saying H₀ is true: accept H₀ means “not enough evidence to reject”, not “proven independent”.
Putting only one direction in H₁: chi-squared is always “not independent” — never “>” or “<“.
Mixing observed and expected in the GDC: enter the OBSERVED matrix; the calculator returns the expected matrix.
Next up: Goodness of Fit Test. Same test statistic χ2 = Σ(O−E)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.