Contingency tables and the chi-squared test

Contingency tables and the chi-squared test

Spec SE1–SE4 · AQA A-Level Further Maths: Revision notes

Studying this course? Keep your progress in one place.

Key facts

  • H0H_0: no association (independent). H1H_1: there is an association. State both in context.
  • Expected frequency E=row total×column totalgrand totalE=\dfrac{\text{row total}\times\text{column total}}{\text{grand total}}.
  • X2=∑(O−E)2EX^2=\sum\dfrac{(O-E)^2}{E} with ν=(n−1)(m−1)\nu=(n-1)(m-1); reject H0H_0 if X2X^2 exceeds the upper-tail critical value.
  • Every expected frequency must exceed 55: combine adjacent categories if not.
  • The largest contributions (O−E)2E\frac{(O-E)^2}{E} show where the association lies.

Contingency tables and hypotheses

Whether two categorical variables are associated; H0H_0 always says they are independent.

A contingency table shows observed frequencies for two categorical variables, with nn rows and mm columns. The chi-squared test checks whether the variables are associated.

  • H0H_0: there is no association between the variables (they are independent).
  • H1H_1: there is an association.

Always state the hypotheses in the context of the question.

051015202530A: yesA: noB: yesB: noGroup and responseFrequency
A contingency table drawn as bars: observed frequencies (illustrative values)
  • H0H_0no association (independent)
  • H1H_1there is an association

A survey records whether 100 students walk, cycle or take the bus to school, split by year group. What is the correct null hypothesis?

Expected frequencies

Multiply the row total by the column total and divide by the grand total.

If H0H_0 is true, the expected frequency in each cell is

E=row total×column totalgrand total.E=\frac{\text{row total}\times\text{column total}}{\text{grand total}}.

Check that the expected frequencies have the same row and column totals as the observed table.

051015202530A: yesA: noB: yesB: noCellFrequency
  • Observed
  • Expected
Observed against expected frequencies (illustrative values): each expected value is 50 × 50 ÷ 100 = 25
  • Expected frequencyrow×columngrand total\dfrac{\text{row}\times\text{column}}{\text{grand total}}

Worked example

150 employees: 40 walk to work and 70 live in town. Find the expected number who walk and live in town.

A table has row totals 30 and 70, column totals 40 and 60, and grand total 100. What is the expected frequency for the cell in row 1, column 2?

The test statistic and degrees of freedom

Compute X2=∑(O−E)2EX^2=\sum\frac{(O-E)^2}{E} and compare it with the upper-tail critical value for ν=(n−1)(m−1)\nu=(n-1)(m-1).

The test statistic is X2=∑(Oi−Ei)2EiX^2=\sum\dfrac{(O_i-E_i)^2}{E_i}, approximately chi-squared when H0H_0 is true.

For an n×mn\times m table the degrees of freedom are ν=(n−1)(m−1)\nu=(n-1)(m-1).

Large X2X^2 means the observed frequencies are far from those expected under H0H_0. If X2X^2 exceeds the critical value, reject H0H_0.

The test is one-tailed: a very small X2X^2 just means the data fit independence closely.

24681012140.050.10.150.20.250.3X²densitycritical value 7.815χ² density, ν = 3
Chi-squared distribution for ν = 3: reject H₀ if X² falls in the shaded 5% tail beyond 7.815
  • Test statisticX2=∑(O−E)2EX^2=\sum\dfrac{(O-E)^2}{E}
  • Degrees of freedomν=(n−1)(m−1)\nu=(n-1)(m-1)

ν = 1

Critical value at 5%:
3.841
Critical value at 1%:
6.635

ν = 2

Critical value at 5%:
5.991
Critical value at 1%:
9.210

ν = 3

Critical value at 5%:
7.815
Critical value at 1%:
11.345

ν = 4

Critical value at 5%:
9.488
Critical value at 1%:
13.277

A contingency table has 3 rows and 4 columns. At the 5% level, what is the critical value?

Small expected frequencies

The approximation needs every expected frequency above 55; otherwise combine adjacent categories and recalculate.

The chi-squared approximation is only reliable when all expected frequencies are greater than 5.

If any Ei≤5E_i\le5, combine categories: merge adjacent rows or columns so that every expected frequency exceeds 55. Then recalculate EE, X2X^2 and use the reduced degrees of freedom for the new table.

For example, expected frequencies of 4.24.2, 3.63.6 and 4.24.2 in a "not at all" column mean it should be combined with its neighbour.

  1. 1

    Calculate every E

    row total × column total ÷ grand total

  2. 2

    Spot any E ≤ 5

    the approximation is unreliable

  3. 3

    Combine adjacent categories

    merge neighbouring rows or columns

  4. 4

    Recalculate

    new E, new X² and new ν from the smaller table

Dealing with small expected frequencies

A 3×43\times4 table has one column combined with its neighbour. What is the new number of degrees of freedom?

Sources of association

Look at each contribution (O−E)2E\frac{(O-E)^2}{E}: the largest ones show where observed and expected differ most.

If H0H_0 is rejected, find which cells cause it by looking at each contribution (O−E)2E\frac{(O-E)^2}{E}.

The cells with the largest contributions are the main sources of association. Compare OO with EE for those cells and describe the pattern in context, saying "more than expected" or "fewer than expected" and quoting OO and EE.

For example, at clinic Z, 20 dissatisfied patients were observed against 11.6711.67 expected, a contribution of (20−11.67)211.67=5.95\frac{(20-11.67)^2}{11.67}=5.95.

05101520ObservedExpectedCellFrequency
Clinic Z, dissatisfied patients: 20 observed against 11.67 expected, a contribution of 5.95
  • Contribution of a cell(O−E)2E\dfrac{(O-E)^2}{E}
  • Largest contributionsmain sources of association

After rejecting H0H_0, how do you decide which cells show the association?

Try an exam question

A 3×43\times4 contingency table classifies students by year group (3 groups) and by method of travel to school (4 methods). A chi-squared test of association is carried out at the 5% level. State the null hypothesis, the degrees of freedom, and the critical value.

[4 marks]

That's the notes covered.

Carry on to the next subtopic.

Try a question

Assuming no association, find the expected number of employees who drive and live in town.

1 mark, marked against the mark scheme

Revision notes