# Chi-squared tests

> Further Mathematics · CIE A-Level 9231
> Source: https://www.owlsprep.com/study/cie-9231-u4-chi-squared-tests/

This module covers chi-squared hypothesis tests for goodness of fit and contingency table independence, including Yates' correction, degrees of freedom rules, and exam-standard worked examples.

**Prerequisites:** [Fundamentals of hypothesis testing](https://www.owlsprep.com/study/cie-9231-u4-hypothesis-testing-basics/); [Discrete probability distributions](https://www.owlsprep.com/study/cie-9231-u3-discrete-probability-distributions/)

## Learning objectives

- Calculate expected frequencies for goodness of fit and contingency table tests
- Correctly determine degrees of freedom across all chi-squared test scenarios
- Apply Yates' continuity correction for 2x2 contingency tables as required by CIE
- Formulate valid null and alternative hypotheses for independence and distribution fit tests
- Interpret chi-squared test results to draw statistically valid conclusions

## Chi-squared Goodness of Fit Test Basics

**Chi-squared test statistic** — Sum of squared differences between observed and expected frequencies, normalised by the expected frequency for each category.

*Notation:* \chi^2 = \sum \frac{(O_i - E_i)^2}{E_i}

For a goodness of fit test, the null hypothesis states that the sample data follows a specified theoretical distribution. The alternative hypothesis states the data does not follow that distribution. Expected frequencies are calculated directly from the theoretical distribution, scaled to the total sample size.

**Worked example:** A fair 6-sided die is rolled 120 times, with observed scores: 25, 18, 22, 17, 21, 17. Calculate the chi-squared test statistic to test if the die is fair.

1. Total sample size = 120. For a fair die, expected frequency for each of 6 outcomes = 120 / 6 = 20.
2. Compute each (O_i - E_i)^2 / E_i term:
3. $$\frac{(25-20)^2}{20} + \frac{(18-20)^2}{20} + \frac{(22-20)^2}{20} + \frac{(17-20)^2}{20} + \frac{(21-20)^2}{20} + \frac{(17-20)^2}{20}$$
4. Sum the terms: 1.25 + 0.2 + 0.2 + 0.45 + 0.05 + 0.45 = 2.6

**Check your understanding**

1. What is the expected frequency for a category if total sample size is 200 and theoretical probability of the category is 0.15?

   *Why:* E_i = n * p_i = 200 * 0.15 = 30

> **Exam tip:** CIE examiners will deduct marks if you do not explicitly state that all expected frequencies are >=5 before proceeding with the test.

## Degrees of Freedom Calculation

Degrees of freedom for a chi-squared test are calculated as the number of independent pieces of information used to compute the test statistic. For goodness of fit tests, you subtract 1 for the total sample size constraint, plus 1 for every population parameter estimated from the sample data.

$$\nu = k - m - 1$$

- k = number of categories after merging any groups with E_i < 5
- m = number of parameters estimated from sample data to define the theoretical distribution

**Worked example:** You fit a normal distribution to 8 categories of grouped data, estimating mean and variance from the sample. All expected frequencies are >=5. Find the degrees of freedom.

1. Number of categories k = 8
2. Number of estimated parameters m = 2 (mean and variance)
3. $$\nu = 8 - 2 - 1 = 5$$

**Check your understanding**

1. You test if data follows a Poisson distribution, estimating lambda from the sample, with 4 categories. What is the df?

   *Why:* 4 - 1 -1 = 2

> **Exam tip:** Never subtract extra degrees of freedom for parameters that are given in the question, only for values you calculate from the sample.

## Chi-squared Test for Independence

This test assesses if two categorical variables are independent of each other, using a contingency table. The null hypothesis states the two variables are independent, the alternative states they are associated. Expected frequency for each cell is calculated as (row total * column total) / grand total.

$$E_{ij} = \frac{R_i \times C_j}{N}$$

**Worked example:** A 3x2 contingency table has row totals 40, 60, 50, column totals 70, 80, grand total 150. Calculate the expected frequency for the cell in row 2, column 1.

1. Row 2 total R_2 = 60, Column 1 total C_1 =70
2. $$E_{21} = \frac{60 \times 70}{150} = 28$$

Degrees of freedom for an r x c contingency table is (r-1)(c-1), where r is number of rows and c number of columns, no extra subtractions required.

**Exam command terms**

- **Test for association** — Identical to test for independence, use chi-squared contingency table method

- **Test if the results are homogeneous** — Same calculation as test for independence, identical degrees of freedom

> **Exam tip:** You can verify your expected frequencies are correct by checking that all row and column totals match the observed contingency table totals.

## Yates' Continuity Correction

The chi-squared distribution is continuous, but the test statistic calculated from 2x2 contingency tables is discrete. Yates' correction adjusts the test statistic to reduce this approximation error, and is mandatory for all 2x2 tables in the CIE 9231 syllabus.

$$\chi^2_{\text{Yates}} = \sum \frac{(|O_i - E_i| - 0.5)^2}{E_i}$$

**Worked example:** For a 2x2 table, the difference between observed and expected for each cell is 1.2. Calculate the Yates corrected test statistic.

1. Subtract 0.5 from absolute difference: |1.2| - 0.5 = 0.7
2. Square the value: 0.7^2 = 0.49
3. Sum over 4 cells, each with E_i = 25: 4 * (0.49 / 25) = 0.0784

> **warning**
>
> Never apply Yates' correction to contingency tables larger than 2x2, or to goodness of fit tests. CIE will deduct marks for unnecessary use of Yates' correction.

## Common pitfalls

- **Wrong:** Failing to combine expected frequencies less than 5
  - Why it fails: Breaks the chi-squared distribution approximation assumption, leading to inflated test statistics and incorrect conclusions
  - Correct: Merge adjacent categories until all E_i >=5, then reduce degrees of freedom by the number of merged groups minus 1
- **Wrong:** Applying Yates' correction to 3x2 or larger contingency tables
  - Why it fails: Yates' correction is only designed for 2x2 tables, and produces overly conservative test results for larger tables
  - Correct: Only use Yates' correction explicitly when the contingency table is 2 rows by 2 columns
- **Wrong:** Forgetting to subtract degrees of freedom for parameters estimated from sample data
  - Why it fails: Overestimates degrees of freedom, leading you to pick an overly lenient critical value and incorrectly reject the null hypothesis
  - Correct: Explicitly count all parameters you calculated from the observed data to define the theoretical distribution, subtract 1 per parameter from df
- **Wrong:** Using observed totals instead of (row total * column total)/grand total to calculate contingency table expected frequencies
  - Why it fails: Produces invalid expected values that do not reflect the independence assumption
  - Correct: Verify all expected row and column totals exactly match the observed table totals before calculating the test statistic
- **Wrong:** Stating the null hypothesis as 'the two variables are correlated'
  - Why it fails: Chi-squared tests for independence do not measure linear correlation, they test for any association between categorical variables
  - Correct: Explicitly write H0 as 'the two variables are independent' and H1 as 'the two variables are not independent'

## Cheatsheet

| Test Type | Degrees of Freedom Formula | Required Adjustments |
| --- | --- | --- |
| Goodness of fit, no parameters estimated | k - 1 | Merge categories if E_i < 5 |
| Goodness of fit, m parameters estimated | k - m - 1 | Merge categories if E_i < 5 |
| r x c Contingency table (r>2 or c>2) | (r-1)(c-1) | Merge rows/columns if E_i <5 |
| 2 x 2 Contingency table | 1 | Apply Yates' continuity correction |

## What's next

Mastering chi-squared tests gives you a core tool for analysing categorical data that appears in almost every CIE 9231 exam paper. Next, you will build on this hypothesis testing foundation to learn non-parametric tests that can be used when your data does not meet the assumptions of standard parametric tests like t-tests. You will also explore hypothesis testing for correlation coefficients, which lets you assess the statistical significance of linear relationships between continuous variables. These topics are frequently paired with chi-squared questions in extended problem sets, so solidifying your understanding now will boost your performance in the final exam.

- [Non-parametric Hypothesis Tests](https://www.owlsprep.com/study/cie-9231-u4-non-parametric-tests/)

---

From [OwlsPrep](https://www.owlsprep.com) — free study guides for A-Level, IB, AP and IGCSE, written against the official syllabus. Canonical page: https://www.owlsprep.com/study/cie-9231-u4-chi-squared-tests/
