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.
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.
Observed vs Expected Frequencies
Two Types of \(\chi^2\) Test
Example: Is a die fair?
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.
Degrees of Freedom
where \(k\) = number of categories.
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
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
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 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| \(O\) | 14 | 6 | 12 | 11 | 8 | 9 |
| \(E\) | 10 | 10 | 10 | 10 | 10 | 10 |
Example 1: Calculation
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
Common Mistakes
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?