impera Open Impera

A levels Further Mathematics · Further statistics

Chi-squared tests

1Observed and expected frequencies

A chi-squared ($\chi^2$) test compares observed frequencies $O$ with the expected frequencies $E$ predicted by a model.

The test statistic is

$$X^2 = \sum \frac{(O - E)^2}{E}$$

If the model fits well, $O$ and $E$ are close and $X^2$ is small. A large $X^2$ is evidence against the model.

Under $H_0$, $X^2$ approximately follows a $\chi^2$ distribution with $\nu$ degrees of freedom.

The 5% critical region is X² > 11.07 for 5 degrees of freedom. The die's value of 4.5 is well inside the acceptance region.

Check yourself

What does a large value of X² suggest?

  • The model fits the observed data perfectly

  • The sample is too small to use the test

  • The observed data does not fit the model well

  • The degrees of freedom have been miscounted

Show the answer

The observed data does not fit the model well

Big gaps between O and E make X² large.

2Goodness of fit

Worked example

Is the die fair?

  1. A die is rolled 120 times: 15, 25, 18, 22, 16, 24 for faces 1 to 6.
  2. $H_0$: the die is fair. Expected: 20 for each face.
  3. $X^2 = \frac{25 + 25 + 4 + 4 + 16 + 16}{20} = \frac{90}{20} = 4.5$.
  4. Degrees of freedom: $6 - 1 = 5$. Critical value at 5%: 11.070.
  5. $4.5 < 11.070$, so do not reject $H_0$: no evidence that the die is biased.

The test is always one-tailed (upper tail), because only large values of $X^2$ count against the model.

Check yourself

Why is a chi-squared test always one-tailed?

  • Because there are two tails

  • Because X² can be negative

  • Only large values of X² show a poor fit

  • Because the critical value is zero

Show the answer

Only large values of X² show a poor fit

Small X² means good agreement.

3Degrees of freedom

The degrees of freedom are

$$\nu = \text{number of cells} - \text{number of constraints}$$

  • The total always gives one constraint.
  • Each parameter estimated from the data gives another.
Worked example

Fitting a Poisson model

  1. Data on goals per match is grouped into 6 classes. The mean is estimated from the data to fit a Poisson distribution.
  2. $\nu = 6 - 1 - 1 = 4$.

Combining cells: each expected frequency should be at least 5. If not, merge neighbouring cells, then count the cells after merging.

Check yourself

Why must cells be combined when E < 5?

  • The chi-squared approximation is unreliable with small expected frequencies

  • Because each observed frequency must equal its expected one

  • To increase the number of degrees of freedom in the test

  • To make the value of X² bigger so H₀ is rejected more easily

Show the answer

The chi-squared approximation is unreliable with small expected frequencies

Then recount the cells.

4Contingency tables

A contingency table tests whether two factors are independent.

Expected frequency for each cell:

$$E = \frac{\text{row total} \times \text{column total}}{\text{grand total}}$$

Degrees of freedom: $\nu = (r - 1)(c - 1)$ for $r$ rows and $c$ columns.

Worked example

A 2 × 3 table

  1. Observed: group A: 30, 20, 10 (total 60); group B: 20, 30, 30 (total 80). Column totals 50, 50, 40; grand total 140.
  2. Expected for A: 21.43, 21.43, 17.14; for B: 28.57, 28.57, 22.86.
  3. $X^2 = 11.38$, with $\nu = (2 - 1)(3 - 1) = 2$. Critical value at 5%: 5.991.
  4. $11.38 > 5.991$: reject $H_0$. There is evidence of an association between group and choice.
Check yourself

What are the degrees of freedom for a 3 × 4 contingency table?

  • 12

  • 7

  • 6

  • 11

Show the answer

6

(3 − 1)(4 − 1).

5Interpreting and Yates' correction

After rejecting independence, look at which cells contribute most to $X^2$ to describe the association.

Worked example

Interpreting

  1. In the 2 × 3 table, the largest contributions came from group A's first choice (more than expected) and group B's third choice (more than expected).
  2. So group A tends to prefer the first option, and group B the third.

For a 2 × 2 table ($\nu = 1$), some courses use Yates' continuity correction:

$$X^2 = \sum \frac{(|O - E| - 0.5)^2}{E}$$

It reduces $X^2$ slightly to correct for using a continuous distribution with discrete counts.

Check yourself

When is Yates' correction used?

  • For all goodness of fit tests

  • Only when E > 100

  • Never

  • For 2 × 2 contingency tables

Show the answer

For 2 × 2 contingency tables

The case with one degree of freedom.

6Hypotheses and conclusions

For a contingency table:

  • $H_0$: the two factors are independent (no association);
  • $H_1$: the factors are not independent (there is an association).

For goodness of fit:

  • $H_0$: the model fits the data;
  • $H_1$: the model does not fit the data.

Conclusions should be in context and non-definite: "there is evidence of an association between age group and preferred news source".

Association is not causation: a chi-squared test cannot show that one factor causes the other.

Check yourself

What is H₀ in a contingency table test?

  • The two factors are associated

  • O = E in every cell

  • X² is large

  • The two factors are independent

Show the answer

The two factors are independent

No association.

Now test yourself

This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.

Practise in Impera