Cambridge International AS & A Level · Topic 4.3
A-Level Further Maths 9231 / Topic 4.3 / AS & A Level

Are the two linked?

A contingency table counts people or objects by two features at once. If the features are independent, the totals alone predict every cell. The chi-squared test measures how far the real counts stray from those predictions, and the cells that stray most tell you what the association looks like.

The key idea

H0: the two classifications are independent; H1: they are not independent (there is an association). Expected frequency \(E = \dfrac{\text{row total} \times \text{column total}}{\text{grand total}}\). Combine adjacent rows or columns until every \(E \ge 5\), then \(X^{2} = \sum \dfrac{(O - E)^{2}}{E}\) is compared with \(\chi^{2}_{\nu}\) where \(\nu = (r - 1)(c - 1)\) for the table you actually use. Reject H0 if \(X^{2}\) exceeds the critical value.

Gym Running Swimming Total Under 30 30 and over Total 30 18 12 60 14 22 24 60 44 40 36 120 E = 60 × 44 ÷ 120 = 22 row total × column total ÷ grand total
Fig. 1: 120 adults classified by age group and favourite exercise. If the two are independent, the expected number of under-30s who prefer the gym is 60 x 44 / 120 = 22; 30 were observed
Section 01

Independence or association?

In the goodness of fit lesson the expected frequencies came from a named distribution. In a contingency table they come from the table itself. If age group and favourite exercise are independent, then the proportion of all adults who prefer the gym, \(\frac{44}{120}\), should apply to the 60 under-30s as well, giving \(60 \times \frac{44}{120} = 22\). That is the rule \(E = \dfrac{\text{row total} \times \text{column total}}{\text{grand total}}\), used in every cell.

ObservedGymRunningSwimmingTotal
Under 3030181260
30 and over14222460
Total444036120
Worked example Every expected frequency
Find the expected frequencies for the exercise table above, assuming H0 is true.
  1. Under 30, gym: \(\dfrac{60 \times 44}{120} = 22\). Under 30, running: \(\dfrac{60 \times 40}{120} = 20\). Under 30, swimming: \(\dfrac{60 \times 36}{120} = 18\).
  2. The row totals are equal (60 and 60), so the 30 and over row has the same expected frequencies: 22, 20, 18.
  3. Check: each expected row adds to 60 and each expected column adds to its observed total (44, 40, 36).
Answer: 22, 20, 18 in each row
Worked example One cell and the degrees of freedom
125 students are classified by distance from school (3 rows) and number of late arrivals in a term (4 columns: 0, 1-2, 3-5, 6 or more). The row total for 'over 5 km' is 35 and the column total for '6 or more' is 9. Find the expected frequency for that cell and the number of degrees of freedom for the full table.
  1. \(E = \dfrac{35 \times 9}{125} = \dfrac{315}{125} = 2.52\).
  2. \(\nu = (3 - 1)(4 - 1) = 2 \times 3 = 6\), if no rows or columns are combined.
  3. But \(2.52 < 5\), so this table cannot be used as it stands: section 3 shows what to do.
Answer: \(E = 2.52\); \(\nu = 6\) for the uncombined table
Examiner trap

Do not round expected frequencies to whole numbers. They are averages, not counts: 2.52 and 14.4 are correct values. Rounding them changes every contribution and can change the conclusion.

Section 02

Contributions, then a decision.

Lay out \(\dfrac{(O - E)^{2}}{E}\) for every cell in a table of contributions. Their sum is the test statistic \(X^{2}\). Compare it with the critical value of \(\chi^{2}_{\nu}\) from the tables. Then look back at the biggest contributions: they show WHERE the association lies, and comparing \(O\) with \(E\) in those cells shows its direction.

\[ X^{2} = \sum \frac{(O - E)^{2}}{E}, \qquad \nu = (r - 1)(c - 1) \]
\(\frac{(O - E)^{2}}{E}\)GymRunningSwimming
Under 302.9090.2002.000
30 and over2.9090.2002.000
Worked example The full test on the exercise table
Test, at the 5% significance level, whether age group and favourite exercise are independent. Comment on the contributions.
  1. H0: age group and favourite exercise are independent. H1: they are not independent. All \(E \ge 5\) (22, 20, 18), so no combining is needed.
  2. \[ \begin{aligned} \frac{(30 - 22)^{2}}{22} &= 2.909, \quad \frac{(18 - 20)^{2}}{20} = 0.200, \quad \frac{(12 - 18)^{2}}{18} = 2.000 \\ X^{2} &= 2 \times (2.909 + 0.200 + 2.000) = 10.22 \end{aligned} \]
  3. \(\nu = (2 - 1)(3 - 1) = 2\). The 5% critical value of \(\chi^{2}_{2}\) is 5.991.
  4. \(10.22 > 5.991\), so reject H0. There is sufficient evidence at the 5% level that age group and favourite exercise are associated.
  5. The gym and swimming cells contribute most. More under-30s chose the gym than expected (30 against 22) and fewer chose swimming (12 against 18); the over-30s show the reverse. Running (0.200 per cell) plays almost no part.
Answer: \(X^{2} = 10.2 > 5.991\): evidence of association, driven by gym (younger) and swimming (older)
Worked example A 2 x 2 table, no Yates' correction
Of 40 students who revised with flashcards, 34 passed a test and 6 failed. Of 60 who did not, 38 passed and 22 failed. Test at the 5% level whether passing is independent of using flashcards.
  1. H0: passing and using flashcards are independent. H1: they are not independent. Totals: pass 72, fail 28, grand total 100.
  2. \(E\): flashcards \(\frac{40 \times 72}{100} = 28.8\) and \(11.2\); no flashcards \(43.2\) and \(16.8\). All are at least 5.
  3. In a 2 x 2 table every \(|O - E|\) is the same, here \(5.2\), so \[ X^{2} = 5.2^{2} \left( \frac{1}{28.8} + \frac{1}{11.2} + \frac{1}{43.2} + \frac{1}{16.8} \right) = 5.589 \]
  4. \(\nu = (2 - 1)(2 - 1) = 1\); the 5% critical value is 3.841. \(5.589 > 3.841\), so reject H0.
  5. There is sufficient evidence at the 5% level of an association. The largest contribution (2.414) is flashcard users who failed: 6 observed against 11.2 expected, so flashcard users failed less often than independence predicts.
Answer: \(X^{2} = 5.59 > 3.841\): evidence that passing is associated with using flashcards
Your turn
In the flashcard test, would the conclusion change at the 1% level?
Examiner trap

Rejecting H0 shows an association, not a cause: the test cannot say that flashcards MADE students pass. Equally, not rejecting H0 never proves independence; write 'there is insufficient evidence of an association'.

Stage 1 · Learn

Check your understanding

Four quick checks. Each correct answer earns XP and records this skill on your profile.

Quick check+10 XP

In a contingency table with grand total 120, a cell has row total 40 and column total 30. If the classifications are independent, the expected frequency for the cell is

Quick check+10 XP

A contingency table has 3 rows and 4 columns and every expected frequency is at least 5. How many degrees of freedom does the test have?

Quick check+10 XP

A researcher records whether each of 200 people owns a pet and their age group. Which is the correct null hypothesis for a test of independence?

Quick check+10 XP

A 2 x 2 table has observed frequencies 20, 10 (first row) and 10, 20 (second row). Find \(X^{2}\).

Section 03

Combine until every E is at least 5.

The test statistic only follows a \(\chi^{2}\) distribution approximately, and the approximation is poor when expected frequencies are small. So before calculating \(X^{2}\), check every \(E\). If any is below 5, merge that row or column with a neighbouring one that makes sense (adjacent categories of an ordered scale), recompute the expected frequencies, and count the degrees of freedom from the NEW table.

Observed01-23-56+Total
Under 2 km24146145
2-5 km18168345
Over 5 km81012535
Total5040269125
Worked example Combine, then test
The table shows the late arrivals of 125 students against distance from school. Test at the 5% level whether lateness is independent of distance.
  1. H0: number of late arrivals and distance are independent. H1: they are not independent.
  2. The '6+' expected frequencies are \(\frac{45 \times 9}{125} = 3.24\), 3.24 and 2.52, all below 5. Combine '6+' with the adjacent '3-5' column to make '3 or more' (totals 45, 45, 35; column total 35).
  3. Combined observed: under 2 km 24, 14, 7; 2-5 km 18, 16, 11; over 5 km 8, 10, 17. Expected: 18, 14.4, 12.6 in the first two rows and 14, 11.2, 9.8 in the third. All at least 5.
  4. \[ \begin{aligned} X^{2} &= 2.000 + 0.011 + 2.489 \\ &\quad + 0.000 + 0.178 + 0.203 \\ &\quad + 2.571 + 0.129 + 5.290 = 12.87 \end{aligned} \]
  5. \(\nu = (3 - 1)(3 - 1) = 4\), not 6. The 5% critical value of \(\chi^{2}_{4}\) is 9.488. \(12.87 > 9.488\), so reject H0: there is sufficient evidence at the 5% level that lateness is associated with distance.
Answer: \(X^{2} = 12.9 > 9.488\) with \(\nu = 4\): evidence of an association
Worked example Reading the contributions
Use the contributions in the previous example to describe the association.
  1. The largest contribution, 5.290, is 'over 5 km, 3 or more': 17 observed against 9.8 expected.
  2. Next come 'over 5 km, 0' (2.571: 8 against 14) and 'under 2 km, 3 or more' (2.489: 7 against 12.6).
  3. The 2-5 km row contributes very little, so those students behave much as independence predicts.
Answer: Students living over 5 km away are late 3 or more times more often than expected, and those under 2 km less often
Examiner trap

Combine on EXPECTED frequencies, not observed ones: the '6+' column has observed 5 in one row, but its expected frequency 2.52 is what matters. And after combining, \(\nu\) comes from the new table: \((3 - 1)(3 - 1) = 4\), not the original 6.

Stage 2 · Exam

Exam-style questions

Unlocks once the four checks above are done. Worth more XP, written to AS & A Level Further Mathematics Paper 1 to 4 standard.

Finish the four checks above to unlock the exam questions
Exam style+20 XP

In a test of independence on a 2 x 2 table, \(X^{2} = 3.2\). What is the conclusion at the 5% significance level?

Exam style+20 XP

A 3 x 4 contingency table is tested for independence at the 5% level. The expected frequencies in the last column are 3.1, 4.2 and 2.7, so the last two columns are combined. Which critical value should be used?

Exam style+20 XP

In a test of independence between diet (vegetarian or not) and sleep quality (good, fair, poor), H0 is rejected. The largest contribution is from 'vegetarian, good', where \(O = 30\) and \(E = 21\). Which comment is correct?

Exam style+20 XP

Why must expected frequencies be at least 5 before a chi-squared test of independence is carried out?

Skill unlocked

Association tested, and explained.

This skill is now recorded on your profile. Keep the chain going.

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
Hypotheses and expected frequencies, a 2 x 2 test at 1%, a 2 x 3 test, combining rows in a 4 x 3 table, a conclusion at 1% with comments, and combining columns down to a 2 x 2 table.