EuraStudy
Notes/Statistics/Contingency tables
Notes · StatisticsUK · A-Levels

Contingency tables

This topic tests whether two categorical variables in a two-way table are associated, using the chi-squared test. It covers computing expected frequencies under the assumption of independence, forming the chi-squared statistic, finding the degrees of freedom, applying Yates' continuity correction to a 2x2 table, and concluding in context under the small-expected-frequency conditions.

5 sections·~12 min reading time·3 competencies·Level Standard 2 · Advanced 3

T·141414 / 18
Exam profile
AO1 · Compute expected frequencies and the chi-squared statistic for a contingency tableAO2 · Use degrees of freedom and critical values correctlyAO3 · Test for association in a real two-way table and interpret the result
Operators:testcalculatefinddetermineconcludecomment

basic level

The chi-squared test for association is principally full A-Level (Paper 3) content within the statistical-enquiry strand.

higher level

The full A-Level expects expected frequencies, the chi-squared statistic, degrees of freedom, Yates' correction and a contextual conclusion.

Depth

Reading depth: In depth

Text

Text size: Standard

Contents · 5 sections▾
  1. Contingency tables
    • 01Contingency tables and the test for association◐
    • 02Expected frequencies under independence◐
    • 03The chi-squared statistic and degrees of freedom●
    • 04Yates' correction and small expected frequencies●
    • 05Carrying out and concluding the test●
§ 01

Contingency tables and the test for association#

●●○StandardLPPearson Edexcel 9ST0, Topic 14 (Paper 3)

Observed contingency table

Brand preference by age (observed)Table with 5 columns and 3 rows, Data: Brand A · Brand B · Brand C · Total; Under 30 · 30 · 40 · 30 · 100; 30 and over · 20 · 30 · 50 · 100; Total · 50 · 70 · 80 · 200BRAND ABRAND BBRAND CTOTALUNDER 3030403010030 AND OVER203050100TOTAL507080200
Fig. 1Observed frequencies of brand preference by age group, with row and column totals.

Key points

A contingency table cross-classifies a sample by two categorical variables, recording the observed frequency in each cell together with the row and column totals. The chi-squared test for association asks whether the two variables are related: the null hypothesis H0H_0H0​ states that the variables are INDEPENDENT (no association), and the alternative H1H_1H1​ states that they are associated.
The logic compares the frequencies actually observed with those expected if the variables were independent. If the two sets of frequencies are close, the data are consistent with independence; if they differ substantially, that is evidence of association. The whole test rests on quantifying 'substantially' through the chi-squared statistic and comparing it with a critical value.
The table below records brand preference for two age groups. The observed frequencies, with their row and column totals, are the raw material of the test; the row totals (100 and 100) and column totals (50, 70, 80) sum to the grand total 200. These marginal totals are used, in the next section, to compute the frequencies expected under independence.
The variables here are both categorical (age group and brand), which is what makes chi-squared the appropriate test — it works with counts in categories, not with means. Recognising when data call for a chi-squared test of association, rather than a test of means, is the first decision, and it is signalled by a two-way table of frequencies.
H0:the two variables are independent;H1:the two variables are associatedH_0: \text{the two variables are independent}; \qquad H_1: \text{the two variables are associated}H0​:the two variables are independent;H1​:the two variables are associated

Hypotheses for the test of association

Independence is the null; the test looks for evidence of association.

Worked example

Framing the test

A survey cross-classifies 200 people by age group and preferred brand. State the hypotheses and identify the marginal totals needed.

  1. 01Hypotheses

    H0H_0H0​: age group and brand preference are independent; H1H_1H1​: they are associated.

  2. 02Row totals

    Each age group totals 100.

  3. 03Column totals

    Brands A, B, C total 50, 70, 80, summing to the grand total 200.

Result: H0H_0H0​: independence; H1H_1H1​: association; the marginal totals are 100, 100 (rows) and 50, 70, 80 (columns).

Exam focus

  • State the hypotheses as independence versus association for a two-way table.
  • Recognise when a chi-squared test of association is the appropriate procedure.

Typical mistakes

  • Stating hypotheses about means rather than about association between the categorical variables.
  • Omitting or miscalculating the row and column totals needed for the expected frequencies.

Active revision

State the null and alternative hypotheses for testing whether smoking status and exercise level are associated in a two-way table.

Active recall

Recall the key points — then reveal.

Sources: Pearson Edexcel Level 3 Advanced GCE in Statistics (9ST0) Specification (Pearson Edexcel)

§ 02

Expected frequencies under independence#

●●○StandardLPPearson Edexcel 9ST0, Topic 14 (Paper 3)

Observed versus expected frequencies

Observed vs expectedColumn chart: frequency by cell, Data: Observed · <30 A: 30; Observed · <30 B: 40; Observed · <30 C: 30; Observed · 30+ A: 20; Observed · 30+ B: 30; Observed · 30+ C: 50; Expected · <30 A: 25; Expected · <30 B: 35; Expected · <30 C: 40; Expected · 30+ A: 25; Expected · 30+ B: 35; Expected · 30+ C: 4001020304050<30 A<30 B<30 C30+ A30+ B30+ C302540353040202530355040frequencycellObservedExpected
Fig. 2Observed and expected frequencies for each cell; the biggest departures from independence are at Brand C.

Key points

Under independence, the expected frequency in a cell is E=row total×column totalgrand totalE = \dfrac{\text{row total} \times \text{column total}}{\text{grand total}}E=grand totalrow total×column total​. This follows from the multiplication rule for independent events: if age group and brand were independent, the probability of a cell would be the product of its marginal probabilities, and multiplying by the grand total converts that probability into an expected count.
For the brand-preference table, the expected count for 'under 30, Brand A' is 100×50200=25\dfrac{100 \times 50}{200} = 25200100×50​=25, and applying the formula to every cell gives expected frequencies 25, 35, 40 in each row. The row and column totals of the expected table match those of the observed table by construction, a useful arithmetic check.
The comparison of observed and expected frequencies is the heart of the test, and the chart below sets them side by side for all six cells. Where the bars differ markedly — 'under 30, Brand C' expected 40 but observed only 30, and '30 and over, Brand C' expected 40 but observed 50 — the data depart from independence, and the chi-squared statistic will accumulate those departures.
Expected frequencies need not be whole numbers, and they should be kept to a reasonable accuracy (they are counts under a model, not observed counts). Every expected frequency should also be checked against the condition that they are not too small, discussed later, because the chi-squared approximation relies on it.
E=row total×column totalgrand totalE = \frac{\text{row total} \times \text{column total}}{\text{grand total}}E=grand totalrow total×column total​

Expected frequency under independence

From the multiplication rule for independent events, scaled to the grand total.

Worked example

Computing expected frequencies

For the brand-preference table (row totals 100, 100; column totals 50, 70, 80; grand total 200), find the expected frequencies for the 'under 30' row.

  1. 01Brand A

    100×50200=25\dfrac{100 \times 50}{200} = 25200100×50​=25.

  2. 02Brand B

    100×70200=35\dfrac{100 \times 70}{200} = 35200100×70​=35.

  3. 03Brand C

    100×80200=40\dfrac{100 \times 80}{200} = 40200100×80​=40.

    E<30, C=100×80200=40E_{\text{<30, C}} = \frac{100 \times 80}{200} = 40E<30, C​=200100×80​=40
  4. 04Check

    25+35+40=10025 + 35 + 40 = 10025+35+40=100, matching the row total.

Result: The expected 'under 30' frequencies are 25, 35 and 40, summing to the row total 100.

Exam focus

  • Compute expected frequencies with the row-times-column-over-grand-total formula.
  • Check that the expected row and column totals reproduce the observed totals.

Typical mistakes

  • Rounding expected frequencies to whole numbers when the formula gives fractional counts.
  • Using the wrong marginal totals for a cell (mixing up row and column).

Active revision

For the brand-preference table, compute all six expected frequencies and verify their totals.

Active recall

Recall the key points — then reveal.

Sources: Pearson Edexcel Level 3 Advanced GCE in Statistics (9ST0) Specification (Pearson Edexcel)

§ 03

The chi-squared statistic and degrees of freedom#

●●●AdvancedLPPearson Edexcel 9ST0, Topic 14 (Paper 3)

Key points

The chi-squared statistic accumulates the standardised squared differences between observed and expected frequencies, χ2=∑(O−E)2E\chi^2 = \sum \dfrac{(O - E)^2}{E}χ2=∑E(O−E)2​, summed over every cell. Each term is large when a cell's observed count is far from what independence predicts, and dividing by EEE scales the departure relative to the size expected there. A total near zero supports independence; a large total is evidence of association.
The statistic is compared with the chi-squared distribution, whose shape depends on the degrees of freedom. For an r×cr \times cr×c table the degrees of freedom are (r−1)(c−1)(r - 1)(c - 1)(r−1)(c−1), because once the marginal totals are fixed only that many cells are free to vary. The brand table is 2×32 \times 32×3, giving (2−1)(3−1)=2(2 - 1)(3 - 1) = 2(2−1)(3−1)=2 degrees of freedom.
For the brand data, summing the six terms gives χ2=1.0+0.714+2.5+1.0+0.714+2.5=8.43\chi^2 = 1.0 + 0.714 + 2.5 + 1.0 + 0.714 + 2.5 = 8.43χ2=1.0+0.714+2.5+1.0+0.714+2.5=8.43 (3 s.f.). This is compared with the critical value from the chi-squared distribution with 2 degrees of freedom at the 5% level, which is 5.991; the test statistic exceeds it, as pursued in the conclusion.
The test is always upper-tailed: only large values of χ2\chi^2χ2 indicate association, since a value near zero means the observed and expected frequencies agree. The degrees of freedom, not the number of cells, index the distribution, and getting (r−1)(c−1)(r - 1)(c - 1)(r−1)(c−1) right — rather than rcrcrc or r+cr + cr+c — is a frequent source of error.
χ2=∑(O−E)2E,df=(r−1)(c−1)\chi^2 = \sum \frac{(O - E)^2}{E}, \qquad \text{df} = (r - 1)(c - 1)χ2=∑E(O−E)2​,df=(r−1)(c−1)

Chi-squared statistic and degrees of freedom

Summed over all cells; the test is upper-tailed and indexed by (r−1)(c−1)(r-1)(c-1)(r−1)(c−1).

Worked example

Computing the chi-squared statistic

For the brand table, observed 30, 40, 30, 20, 30, 50 against expected 25, 35, 40, 25, 35, 40, compute χ2\chi^2χ2 and the degrees of freedom.

  1. 01Cell contributions

    (30−25)225=1.0\dfrac{(30-25)^2}{25} = 1.025(30−25)2​=1.0, (40−35)235=0.714\dfrac{(40-35)^2}{35} = 0.71435(40−35)2​=0.714, (30−40)240=2.5\dfrac{(30-40)^2}{40} = 2.540(30−40)2​=2.5 for the first row.

  2. 02Second row

    (20−25)225=1.0\dfrac{(20-25)^2}{25} = 1.025(20−25)2​=1.0, (30−35)235=0.714\dfrac{(30-35)^2}{35} = 0.71435(30−35)2​=0.714, (50−40)240=2.5\dfrac{(50-40)^2}{40} = 2.540(50−40)2​=2.5.

  3. 03Sum

    χ2=1.0+0.714+2.5+1.0+0.714+2.5=8.43\chi^2 = 1.0 + 0.714 + 2.5 + 1.0 + 0.714 + 2.5 = 8.43χ2=1.0+0.714+2.5+1.0+0.714+2.5=8.43 (3 s.f.).

    χ2=8.43\chi^2 = 8.43χ2=8.43
  4. 04Degrees of freedom

    (2−1)(3−1)=2(2 - 1)(3 - 1) = 2(2−1)(3−1)=2.

Result: χ2=8.43\chi^2 = 8.43χ2=8.43 with 2 degrees of freedom.

Exam focus

  • Compute χ2=∑(O−E)2E\chi^2 = \sum \frac{(O - E)^2}{E}χ2=∑E(O−E)2​ cell by cell.
  • Find the degrees of freedom as (r−1)(c−1)(r - 1)(c - 1)(r−1)(c−1) for the table.

Typical mistakes

  • Forgetting to divide each squared difference by its own EEE.
  • Using rcrcrc or r+cr + cr+c for the degrees of freedom instead of (r−1)(c−1)(r - 1)(c - 1)(r−1)(c−1).

Active revision

A 3x4 contingency table gives ∑(O−E)2E=15.2\sum \frac{(O - E)^2}{E} = 15.2∑E(O−E)2​=15.2. State the degrees of freedom and describe how to conclude.

Active recall

Recall the key points — then reveal.

Sources: Pearson Edexcel Level 3 Advanced GCE in Statistics (9ST0) Specification (Pearson Edexcel)

§ 04

Yates' correction and small expected frequencies#

●●●AdvancedLPPearson Edexcel 9ST0, Topic 14 (Paper 3)

Key points

The chi-squared distribution is a continuous approximation to the discrete distribution of the statistic, and for a 2×22 \times 22×2 table (with just 1 degree of freedom) the approximation is noticeably too generous. Yates' continuity correction adjusts for this by reducing each absolute difference by a half before squaring: χ2=∑(∣O−E∣−0.5)2E\chi^2 = \sum \dfrac{(|O - E| - 0.5)^2}{E}χ2=∑E(∣O−E∣−0.5)2​. It makes the test slightly more conservative and is applied ONLY to 2×22 \times 22×2 tables.
A second condition guards the approximation from the opposite direction. The chi-squared test requires every EXPECTED frequency to be at least 5; where an expected frequency falls below 5, adjacent categories should be combined until the condition is met. Small expected frequencies inflate the (O−E)2E\dfrac{(O - E)^2}{E}E(O−E)2​ terms unreliably, so ignoring the condition can produce a spuriously significant result.
Combining classes reduces the number of rows or columns and therefore the degrees of freedom, which must be recomputed after merging. The decision of which categories to combine should be sensible in context — grouping naturally similar categories — rather than chosen to manufacture a particular outcome.
These two safeguards, Yates' correction for the 2×22 \times 22×2 case and the expected-frequency condition for every table, are routinely examined. A complete answer checks the expected frequencies, applies Yates only where the table is 2×22 \times 22×2, and states any merging of categories together with the revised degrees of freedom.
χ2=∑(∣O−E∣−0.5)2E(2×2 tables only);require every E≥5\chi^2 = \sum \frac{(|O - E| - 0.5)^2}{E} \quad (2 \times 2 \text{ tables only}); \qquad \text{require every } E \geq 5χ2=∑E(∣O−E∣−0.5)2​(2×2 tables only);require every E≥5

Yates' correction and the expected-frequency condition

Apply Yates only to 2×22 \times 22×2 tables; merge categories to keep every expected frequency at least 5.

Worked example

Yates' correction on a 2x2 table

A 2x2 table has cells with ∣O−E∣=3|O - E| = 3∣O−E∣=3 in every cell and expected frequencies 15, 15, 10, 10. Compute the Yates-corrected χ2\chi^2χ2.

  1. 01Corrected numerator

    Each term uses (∣O−E∣−0.5)2=(3−0.5)2=2.52=6.25(|O - E| - 0.5)^2 = (3 - 0.5)^2 = 2.5^2 = 6.25(∣O−E∣−0.5)2=(3−0.5)2=2.52=6.25.

  2. 02Cell contributions

    6.2515+6.2515+6.2510+6.2510=0.4167+0.4167+0.625+0.625\dfrac{6.25}{15} + \dfrac{6.25}{15} + \dfrac{6.25}{10} + \dfrac{6.25}{10} = 0.4167 + 0.4167 + 0.625 + 0.625156.25​+156.25​+106.25​+106.25​=0.4167+0.4167+0.625+0.625.

  3. 03Sum

    χ2=2.083\chi^2 = 2.083χ2=2.083 (3 d.p.) with 1 degree of freedom.

    χ2=2(0.4167)+2(0.625)=2.083\chi^2 = 2(0.4167) + 2(0.625) = 2.083χ2=2(0.4167)+2(0.625)=2.083
  4. 04Compare

    The 5% critical value for 1 df is 3.841; since 2.083<3.8412.083 < 3.8412.083<3.841, do not reject H0H_0H0​.

Result: The Yates-corrected χ2=2.083<3.841\chi^2 = 2.083 < 3.841χ2=2.083<3.841, so do not reject independence at the 5% level.

Exam focus

  • Apply Yates' continuity correction to a 2×22 \times 22×2 table only.
  • Combine categories with expected frequencies below 5 and recompute the degrees of freedom.

Typical mistakes

  • Applying Yates' correction to a table larger than 2×22 \times 22×2.
  • Failing to merge classes with expected frequencies under 5, or forgetting to update the degrees of freedom after merging.

Active revision

A 2x2 table has observed 18, 12, 7, 13 and expected 15, 15, 10, 10. Apply Yates' correction to find χ2\chi^2χ2.

Active recall

Recall the key points — then reveal.

Sources: Pearson Edexcel Level 3 Advanced GCE in Statistics (9ST0) Specification (Pearson Edexcel)

§ 05

Carrying out and concluding the test#

●●●AdvancedLPPearson Edexcel 9ST0, Topic 14 (Paper 3)

Chi-squared distribution with the critical region

Function graph, chi-squared, 2 df = 0.5*exp(-x/2)Graph of chi-squared, 2 df, y-intercept at y = 0.5, decreasing, on the interval x from 0 to 12246810120.10.20.30.40.55.991 (5%)chi-squared, 2dfdensitychi-squared value
Fig. 3Chi-squared distribution (2 df): reject H0 beyond the critical value 5.991; the test statistic 8.43 lies in this tail.

Key points

The full test assembles the pieces: state the hypotheses, compute the expected frequencies and check they are all at least 5, form the chi-squared statistic, find the degrees of freedom, and compare with the upper-tail critical value. For the brand data, χ2=8.43\chi^2 = 8.43χ2=8.43 with 2 degrees of freedom exceeds the 5% critical value 5.991, so H0H_0H0​ is rejected.
The chi-squared distribution below (2 degrees of freedom) shows the decision geometrically: the rejection region is the upper tail beyond 5.991, and the test statistic 8.43 lies inside it. The distribution is right-skewed and lives on the positive axis, as it must, being a sum of squared quantities.
The conclusion is stated in context: there is sufficient evidence at the 5% level of an association between age group and brand preference. It is good practice to point to WHERE the association lies by inspecting the largest cell contributions — here the Brand C cells, where the older group over-chose and the younger under-chose relative to independence.
A crucial caveat closes the analysis: a significant chi-squared test establishes association, NOT causation, and it does not say how strong the association is. As with correlation, a confounding variable could drive both, and the practical importance of the association must be judged separately from its statistical significance — the honest, contextual interpretation the enquiry cycle demands.
Reject H0  ⟺  χ2>χcrit2(df,α);8.43>5.991⇒association\text{Reject } H_0 \iff \chi^2 > \chi^2_{\text{crit}}(\text{df}, \alpha); \qquad 8.43 > 5.991 \Rightarrow \text{association}Reject H0​⟺χ2>χcrit2​(df,α);8.43>5.991⇒association

The decision rule

Upper-tailed: reject independence when the statistic exceeds the critical value.

Worked example

Completing the association test

For the brand data, χ2=8.43\chi^2 = 8.43χ2=8.43 with 2 degrees of freedom. Using the 5% critical value 5.991, conclude the test.

  1. 01Compare

    8.43>5.9918.43 > 5.9918.43>5.991, so the statistic lies in the rejection region.

  2. 02Decision

    Reject H0H_0H0​ at the 5% level.

    8.43>5.991⇒reject H08.43 > 5.991 \Rightarrow \text{reject } H_08.43>5.991⇒reject H0​
  3. 03Conclude in context

    There is sufficient evidence of an association between age group and brand preference; the Brand C cells contribute most.

  4. 04Caveat

    This shows association, not causation, and says nothing about its strength.

Result: Since 8.43>5.9918.43 > 5.9918.43>5.991, reject H0H_0H0​: there is evidence of association between age and brand preference (but not causation).

Exam focus

  • Assemble the full test and compare χ2\chi^2χ2 with the upper-tail critical value.
  • Conclude in context and identify which cells drive the association.

Typical mistakes

  • Using a two-tailed critical value; the chi-squared test is upper-tailed.
  • Claiming the significant result proves causation rather than association.

Active revision

Given χ2=8.43\chi^2 = 8.43χ2=8.43 with 2 degrees of freedom and a 5% critical value of 5.991, complete the test with a contextual conclusion.

Active recall

Recall the key points — then reveal.

Sources: GCE AS and A level subject content (Statistics) (Department for Education / Ofqual)

Contents

Section -- / 05

    • 01Contingency tables and the test for association◐
    • 02Expected frequencies under independence◐
    • 03The chi-squared statistic and degrees of freedom●
    • 04Yates' correction and small expected frequencies●
    • 05Carrying out and concluding the test●

0/5 Read

From notes into training

Contingency tables

Reinforce this topic with matching tasks from the question bank.

~12
min
3
Competencies
Practise

References & sources

Sources

Pearson Edexcel

  • Pearson Edexcel Level 3 Advanced GCE in Statistics (9ST0) Specification

Department for Education / Ofqual

  • GCE AS and A level subject content (Statistics)

Previous topic

Hypothesis testing, confidence intervals and power

Next topic

Goodness of fit

EuraStudy·Notes T·14·MMXXVI

Carry on to the next topic — your learning path is kept.