James Ashton MathsFREE MATHEMATICS. OPEN TO EVERYONE.
HomeIB DiplomaA levelAbout

χ² tests: independence & goodness of fit

Hypothesis testing with the χ² statistic. The test for independence asks whether two categorical variables are linked; the goodness of fit test asks whether data matches a claimed distribution. You write the hypotheses, the GDC finds χ² and the p-value, and you write the conclusion in context.

SL 4.11Paper 1Paper 2GDC allowed≈ 60 min to work through
Before you start: probability and expected numbers (Probability).

1What you need to know

Tick these off as you go. By the end of the page you should be able to do all of them without notes.

  • Write null and alternative hypotheses, H0 and H1, in wordsSL 4.11
  • Find expected frequencies for a contingency tableSL 4.11
  • Find the degrees of freedom for a test for independence and for a goodness of fit testSL 4.11
  • Use the GDC to find the χ² statistic and the p-valueSL 4.11
  • Reach a conclusion by comparing the p-value with the significance level, or χ² with the critical valueSL 4.11
  • Write the conclusion in contextSL 4.11

2Notes & worked examples

Each idea is followed by a worked example. Try the question yourself first, then reveal the solution one step at a time.

The big idea

A χ² test measures how far the observed frequencies are from the frequencies you would expect if the null hypothesis were true. Small differences could be chance; big differences give a large χ² and a small p-value, which is evidence against H0. The p-value is the probability of getting data this extreme if H0 were true: if it is smaller than the significance level, reject H0.

2.1 The structure of every test

  1. Hypotheses. H0: the "nothing interesting" statement (the variables are independent; the data fits the distribution). H1: the opposite.
  2. Degrees of freedom ν.
  3. GDC: χ² statistic and p-value.
  4. Decision: if p-value < significance level (or χ² > critical value), reject H0; otherwise do not reject H0.
  5. Conclusion in context.

2.2 The χ² test for independence

Expected frequencies and degrees of freedom Not in booklet: learn it
expected=row total×column totalgrand totalν=(rows−1)(columns−1)

Use the table of observed values only, not the totals, to count rows and columns.

Worked example 1Paper 2
150 students were asked their favourite sport.
FootballTennisSwimmingTotal
Year 1130251570
Year 1220352580
Total506040150
Test at the 5% level whether favourite sport is independent of year group.
H0: favourite sport is independent of year group. H1: favourite sport is not independent of year group.
Expected frequency for Year 11, Football: 70×50150=23.3
Questions often ask you to show one expected value: this is the calculation.
ν=(2−1)(3−1)=2
GDC χ² 2-way test: χ2=5.52, p-value =0.0631
Enter the observed values (without totals) as a matrix.
0.0631>0.05, so do not reject H0. There is not enough evidence that favourite sport depends on year group.
Say "do not reject", not "accept", and put the conclusion in context.

Alternatively, compare χ² with a critical value given in the question (here 5.991 for ν=2 at 5%): 5.52<5.991, so do not reject H0.

2.3 The χ² goodness of fit test

Here H0 says the data follows a stated distribution (uniform, or given percentages). Expected frequencies come from that distribution. At AI SL, ν=n−1, where n is the number of categories.

Worked example 2Paper 2
A die is rolled 120 times: 1 → 16, 2 → 24, 3 → 18, 4 → 25, 5 → 17, 6 → 20. Test at the 5% level whether the die is fair.
H0: the die is fair (each score has probability 16). H1: the die is not fair.
Expected frequency of each score: 120×16=20. ν=6−1=5
GDC χ² GOF: χ2=3.5, p-value =0.623
0.623>0.05: do not reject H0. There is no evidence that the die is biased.
Worked example 3Paper 2
A claim says blood types O, A, B, AB occur in the ratio 45%, 40%, 11%, 4%. In a sample of 200 people the counts are 80, 86, 26, 8. Test the claim at the 5% level.
H0: the blood types follow the claimed percentages. H1: they do not.
Expected: 200×0.45=90, 80, 22, 8. ν=3
χ2=2.29, p-value =0.515>0.05: do not reject H0. The data is consistent with the claim.
Worked example 4 (faded)Paper 1
A contingency table has 3 rows and 4 columns. Find ν.
ν=(3−1)(4−1)= 6  ← you work this out
On your TI-Nspire Calculator tricks →

Independence: make a matrix of the observed values (templates key → matrix, choose rows and columns), store it as obs. Then menu → Statistics → Stat Tests → χ² 2-way Test and enter obs. The output gives χ², the p-value and df; the expected values are stored in stat.ExpMatrix. Goodness of fit: put observed values in one list and expected values in another, then menu → Statistics → Stat Tests → χ² GOF, with the degrees of freedom.

3Explore it

The curve is the χ² distribution for your degrees of freedom. Move the test statistic: the shaded tail is the p-value. Compare it with the significance level, and see where the critical value lies.

4Common mistakes & exam tips

Common mistakes

  • Writing the hypotheses the wrong way round: H0 is always "independent" or "fits the distribution".
  • Counting the totals row and column when finding the degrees of freedom.
  • Saying "accept H0". Say "do not reject H0" or "there is insufficient evidence to reject H0".
  • Rejecting H0 when the p-value is larger than the significance level.
  • Giving a conclusion with no context.

Exam tips

  • The expected frequency formula is not in the booklet as words, but "row total × column total ÷ grand total" is quick to remember.
  • Use either the p-value or the critical value, as the question asks; you never need both.
  • A full conclusion has three parts: the comparison, the decision about H0, and what it means in context.
  • Expected frequencies in IB questions are always above 5.

5Practice

Fluency questions build the basics. Problem-solving questions make you think about which method to use.

FluencyP1
Write H0 and H1 for a test of whether eye colour is independent of gender.
H0: eye colour is independent of gender. H1: eye colour is not independent of gender.
FluencyP2
Row total 60, column total 45, grand total 200. Find the expected frequency.
60×45200=13.5
FluencyP3
Find ν for a goodness of fit test with 5 categories.
4
FluencyP4
At the 5% level, the p-value is 0.031. State the decision.
0.031<0.05: reject H0.
Problem solvingP5
A χ² test for independence on a 3 × 2 table gives χ2=13.8. The critical value at 5% is 5.991. State the conclusion.
13.8>5.991: reject H0; the variables are not independent.
Problem solvingP6
Cars passing a junction are counted by colour: 48, 35, 27, 40. Test at the 10% level whether the four colours are equally common.
Expected 37.5 each, ν=3; χ2=6.21, p =0.102>0.10: do not reject H0.

6Exam-style questions

Original questions in the style of the IB Maths AI SL exam, with full markschemes. Your GDC is allowed throughout: use it, but write down what you entered and what it gave you. Give yourself about 1 minute per mark.

Question 1Paper 2[8 marks]

170 people were asked whether they prefer streaming or cinema, by age group.

StreamingCinema
Under 254515
25 to 503525
Over 502030
A χ² test for independence is carried out at the 5% significance level.

  • (a)Write down the null and alternative hypotheses.[1]
  • (b)Show that the expected frequency for "Under 25, Streaming" is 35.3, to 3 s.f.[2]
  • (c)Write down the number of degrees of freedom.[1]
  • (d)Find the χ² statistic and the p-value.[2]
  • (e)State the conclusion of the test, giving a reason.[2]
(a)
H0: preference is independent of age group; H1: it is not independentA1
(b)
60×100170M1
35.29…=35.3AG A1
(c)
2A1
(d)
χ2=13.8A1
p-value =0.00101A1
(e)
0.00101<0.05R1
reject H0: preference depends on age groupA1
Question 2Paper 1[6 marks]

The number of cars of each colour passing a junction is recorded: white 48, black 35, grey 27, red 40. A goodness of fit test is used to test whether the four colours are equally common, at the 10% level.

  • (a)Write down the null hypothesis.[1]
  • (b)Write down the expected frequency for each colour.[1]
  • (c)Find the p-value.[2]
  • (d)State the conclusion of the test.[2]
(a)
the four colours are equally commonA1
(b)
37.5A1
(c)
χ2=6.21(A1)
0.102A1
(d)
0.102>0.10R1
do not reject H0: no evidence that the colours are not equally commonA1
Question 3Paper 1[6 marks]

A survey of 120 people recorded their favourite type of film (comedy, action, drama) and whether they were under 30. A χ² test for independence at the 1% level gave χ2=7.65. The critical value is 9.210.

  • (a)Write down the number of degrees of freedom.[1]
  • (b)State the conclusion of the test, giving a reason.[2]
  • (c)The test is repeated at the 5% level, with critical value 5.991. State the new conclusion.[2]
  • (d)Explain why the two conclusions differ.[1]
(a)
(2−1)(3−1)=2A1
(b)
7.65<9.210R1
do not reject H0: no evidence that film type depends on ageA1
(c)
7.65>5.991R1
reject H0: film type depends on ageA1
(d)
a 5% test needs less evidence to reject H0 than a 1% testR1

7Check yourself

Six quick questions, marked instantly. Aim for 6/6 before moving on. Fractions like 3/2 are accepted.

8Past-paper practice

Once you're scoring well above, try these real IB Maths AI SL questions. Your school or teacher will have the papers.

PaperQuestionFocusDifficulty
May 2025 · TZ2 · Paper 1Q4Pet food vs animal: χ² independence at two significance levels★★★
May 2026 · TZ2 · Paper 2Q2Scratchcards: fair game, then χ² goodness of fit★★★
May 2026 · TZ1 · Paper 1Q10Spinner fairness: χ² goodness of fit, p-value★★☆
May 2025 · TZ1 · Paper 1Q2Car colour vs age group: expected value, χ², conclusion★☆☆
Spotted a mistake on this page?Tell me and I'll fix it. The button opens an email with this page already named, or write to jamesashtonmaths@gmail.com.
Report a mistake