01 / 20

Chi-Squared
Tests

Master the \(\chi^2\) goodness-of-fit and test for independence: when to use them, how to compute them, and how to interpret the results.

IB Math AI HL

What Is a \(\chi^2\) Test?

A chi-squared test is a non-parametric hypothesis test that compares observed frequencies in categorical data with expected frequencies predicted by a model or by independence.

Categorical
Data sorted into categories, not measured on a continuous scale.
Non-parametric
No assumption about the underlying population distribution shape.

Observed vs Expected Frequencies

A B C D Observed Expected

Two Types of \(\chi^2\) Test

Goodness-of-Fit
Does a single variable's distribution match a proposed model?
Example: Is a die fair?
Test for Independence
Are two categorical variables independent of each other?
Example: Is hair colour related to eye colour?

The \(\chi^2\) Statistic

Each term \(\frac{(O - E)^2}{E}\) measures how far one category's count deviates from expectation, relative to the expected count. Squaring ensures all deviations are positive; dividing by \(E\) gives proportional weight.

Large \(\chi^2\)
Big gap between observed and expected: evidence against \(H_0\).
Small \(\chi^2\)
Observed data close to expected: no evidence to reject \(H_0\).

Degrees of Freedom

Goodness-of-Fit
\(\nu = k - 1\)
where \(k\) = number of categories.
Independence
\(\nu = (r - 1)(c - 1)\)
where \(r\) = rows, \(c\) = columns.

GoF vs Independence

Goodness-of-Fit Independence
Variables One categorical variable Two categorical variables
\(H_0\) Data follows proposed distribution Variables are independent
Expected \(E\) \(E_i = n \cdot p_i\) \(E = \frac{\text{row total} \times \text{col total}}{n}\)
d.f. \(k - 1\) \((r-1)(c-1)\)
Data layout One-way frequency table Two-way contingency table

The \(\chi^2\) Distribution

\(\chi^2\) value Probability Density 0 5 10 15 20 ν = 2 ν = 4 ν = 8

The \(\chi^2\) distribution is right-skewed and only takes non-negative values. As \(\nu\) increases, the curve shifts right and becomes more symmetric.

How to Apply the Test

1
State hypotheses. Write \(H_0\) (no effect/fit) and \(H_1\) (effect/no fit).
2
Calculate expected values. Use \(E = np\) (GoF) or \(E = \frac{\text{row} \times \text{col}}{n}\) (independence).
3
Check conditions. All expected values must satisfy \(E_i \geq 5\).
4
Compute \(\chi^2_{\text{calc}}\). Sum \(\frac{(O - E)^2}{E}\) across all cells.
5
Find \(p\)-value or critical value. Compare with \(\chi^2\) table at your significance level.
6
Conclude. If \(p \leq \alpha\) (or \(\chi^2_{\text{calc}} \geq \chi^2_{\text{crit}}\)), reject \(H_0\).

Example 1: Fair Die?

A die is rolled 60 times. The results are shown below. Test at the 5% significance level whether the die is fair.

Face 123456
\(O\) 14 6 12 11 8 9
\(E\) 10 10 10 10 10 10

Example 1: Calculation

1
Degrees of freedom: \(\nu = k - 1 = 6 - 1 = 5\).
2
Critical value: \(\chi^2_{0.05,\,5} = 11.07\).
3
Decision: \(4.2 < 11.07\), so we do not reject \(H_0\).

Example 2: Independence

A survey asks 200 students whether they prefer Science or Arts, categorised by gender. Test at \(\alpha = 0.05\) whether preference is independent of gender.

Science Arts Total
Male 50 30 80
Female 40 80 120
Total 90 110 200

Example 2: Expected Values

Science (E) Arts (E)
Male \(\frac{80 \times 90}{200} = 36\) \(\frac{80 \times 110}{200} = 44\)
Female \(\frac{120 \times 90}{200} = 54\) \(\frac{120 \times 110}{200} = 66\)

Interpreting Results

Do not reject \(H_0\)
There is insufficient evidence at the \(\alpha\) level to conclude there is a difference / association.
Reject \(H_0\)
There is significant evidence at the \(\alpha\) level that the data do not fit the model / are not independent.

Common Mistakes

✕ Using raw data, not frequencies
\(\chi^2\) tests require count data (frequencies), not percentages or means.
✕ Expected value too small
The test is invalid if any \(E_i < 5\). Combine categories to fix this.
✕ Wrong degrees of freedom
GoF uses \(k - 1\), independence uses \((r-1)(c-1)\). Mixing them up changes the critical value.

Question 1 of 5

A goodness-of-fit test has 4 categories. What are the degrees of freedom?

Question 2 of 5

In a \(\chi^2\) test for independence on a \(3 \times 4\) contingency table, what are the degrees of freedom?

Question 3 of 5

If \(\chi^2_{\text{calc}} = 9.8\) and \(\chi^2_{\text{crit}} = 7.81\) at \(\alpha = 0.05\), what is the correct conclusion?

Question 4 of 5

In a contingency table, the row total is 60, the column total is 40, and the grand total is 200. What is the expected frequency for that cell?

Question 5 of 5

Which condition must be met before performing any \(\chi^2\) test?