Chi-Squared Tests
Chi-Squared Tests
Chi-squared (χ²) tests are hypothesis tests for categorical data. They compare observed frequencies with expected frequencies to determine whether there is a statistically significant difference. The two main types are the goodness-of-fit test and the test for independence/association.
The Chi-Squared Statistic
χ² = Σ (O − E)²/E
where:
- O = observed frequency in each category
- E = expected frequency in each category
- The sum is over all categories
A large χ² value suggests the observed data does not fit the expected pattern.
Goodness-of-Fit Test
Tests whether observed data follows a specified distribution (uniform, binomial, Poisson, normal, etc.).
Hypotheses:
- H₀: The data follows the specified distribution
- H₁: The data does not follow the specified distribution
Method:
1. Calculate expected frequencies from the proposed distribution
2. Combine categories where E < 5 (merge adjacent cells until all E ≥ 5)
3. Compute χ² = Σ(O − E)²/E
4. Determine degrees of freedom: ν = (number of cells after merging) − 1 − (number of estimated parameters)
5. Compare with χ²_ν critical value at the chosen significance level
6. Reject H₀ if χ² > critical value
Degrees of freedom adjustments:
| Situation | Parameters estimated | ν reduction |
|---|---|---|
| Distribution fully specified | 0 | ν = k − 1 |
| Mean estimated from data | 1 | ν = k − 2 |
| Mean and variance estimated | 2 | ν = k − 3 |
| Probability p estimated | 1 | ν = k − 2 |
Worked Example: Goodness of Fit
A die is rolled 120 times. Results:
| Face | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| O | 25 | 17 | 15 | 23 | 24 | 16 |
H₀: The die is fair (uniform distribution). H₁: The die is not fair.
Expected frequency for each face: E = 120/6 = 20 (all ≥ 5, no merging needed).
χ² = (25−20)²/20 + (17−20)²/20 + (15−20)²/20 + (23−20)²/20 + (24−20)²/20 + (16−20)²/20
= 25/20 + 9/20 + 25/20 + 9/20 + 16/20 + 16/20 = 100/20 = 5.0
ν = 6 − 1 = 5. At 5% significance, χ²₅ = 11.07.
Since 5.0 < 11.07, do not reject H₀. Insufficient evidence that the die is unfair.
Test for Independence (Contingency Tables)
Tests whether two categorical variables are independent (unrelated) or associated.
Hypotheses:
- H₀: The two variables are independent
- H₁: The two variables are not independent (there is an association)
Expected frequency for each cell:
E = (row total × column total) / grand total
Degrees of freedom: ν = (r − 1)(c − 1)
where r = number of rows, c = number of columns.
Worked Example: Contingency Table
Survey of 200 students:
| Prefer Maths | Prefer Science | Prefer English | Row total | |
|---|---|---|---|---|
| Male | 40 | 30 | 20 | 90 |
| Female | 25 | 45 | 40 | 110 |
| Col total | 65 | 75 | 60 | 200 |
H₀: Subject preference is independent of gender.
Expected frequencies (E = row total × col total / 200):
| Maths | Science | English | |
|---|---|---|---|
| Male | 90×65/200 = 29.25 | 90×75/200 = 33.75 | 90×60/200 = 27 |
| Female | 110×65/200 = 35.75 | 110×75/200 = 41.25 | 110×60/200 = 33 |
χ² = (40−29.25)²/29.25 + (30−33.75)²/33.75 + (20−27)²/27 + (25−35.75)²/35.75 + (45−41.25)²/41.25 + (40−33)²/33
= 3.949 + 0.417 + 1.815 + 3.231 + 0.341 + 1.485 = 11.24
ν = (2−1)(3−1) = 2. At 5% significance, χ²₂ = 5.991.
Since 11.24 > 5.991, reject H₀. There is significant evidence of an association between gender and subject preference.
Yates' Correction
For 2×2 contingency tables (ν = 1), apply Yates' continuity correction:
χ² = Σ (|O − E| − 0.5)²/E
This reduces the χ² value slightly, giving a more conservative test. Only use for 2×2 tables.
Conditions and Limitations
- All expected frequencies should be at least 5. If not, combine adjacent categories
- Data must be frequencies (counts), not proportions or percentages
- Observations must be independent (each item in one category only)
- The test is one-tailed — we only reject for large χ² (right tail)
- A significant result tells you there IS an association, but not the nature or direction — examine the individual (O−E)²/E contributions to see where the biggest differences are
Reading Chi-Squared Tables
The χ² distribution has one parameter: degrees of freedom ν. Critical values increase with ν.
Common critical values (5% significance):
| ν | 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 |
|---|---|---|---|---|---|---|---|---|
| χ² | 3.841 | 5.991 | 7.815 | 9.488 | 11.07 | 12.59 | 15.51 | 18.31 |
Exam Tips
- Never skip combining cells with E < 5 — state that you are combining and show the new merged cells
- Always state H₀ and H₁ in context ("The die is fair", not just "the data fits")
- Show the calculation of each (O−E)²/E term, not just the total
- Remember: goodness of fit uses ν = k − 1 − (parameters estimated); contingency uses ν = (r−1)(c−1)
- The test is always compared to the upper tail of the χ² distribution
- In the conclusion, say "sufficient/insufficient evidence to reject H₀" — never "accept H₀"
- For contingency tables, the E formula is always (row total × column total) / grand total