Chi-Square Test
Homogeneity & Independence
Learn to carry out the \(\chi^2\) test to determine whether categorical distributions differ across populations or whether two variables are associated.
What Is a \(\chi^2\) Test?
A chi-square test compares observed counts in a two-way table to the counts we would expect if there were no relationship between the variables (or no difference between populations). The bigger the gap between observed and expected, the stronger the evidence against the null hypothesis.
Two Flavors of the Same Test
The Two-Way Table
Computing Expected Counts
Under the null hypothesis (no association / same distribution), each cell's expected count is:
This formula distributes the grand total proportionally so that each cell reflects the overall row and column proportions. If reality matches this prediction, the variables are independent (or the distributions are homogeneous).
The \(\chi^2\) Statistic
Degrees of Freedom
Once you know the marginals, you can freely choose values for \((r-1)(c-1)\) cells: the rest are determined. For a \(3 \times 2\) table: \(\text{df} = (3-1)(2-1) = 2\).
Stating the Hypotheses
\(H_a\): The distributions differ for at least one population.
\(H_a\): The two variables are not independent (there is an association).
Homogeneity vs. Independence
| Homogeneity | Independence | |
|---|---|---|
| Sampling | Separate sample from each population | One sample, two variables recorded |
| Question | Same distribution across groups? | Are the variables related? |
| Fixed margins | Column (or row) totals are fixed by design | Only the grand total is fixed |
| Formula | Identical: \(\chi^2 = \sum \frac{(O-E)^2}{E}\) | |
| df | Identical: \((r-1)(c-1)\) | |
Checking Conditions
How to Carry Out the Test
Example: Music & Studying
A researcher randomly selects 200 college students and records their preferred study environment (silence, lo-fi music, pop music) and GPA category (below 3.0, 3.0 or above). Is there an association?
| Silence | Lo-fi | Pop | Total | |
|---|---|---|---|---|
| \(< 3.0\) | 30 | 20 | 40 | 90 |
| \(\geq 3.0\) | 50 | 35 | 25 | 110 |
| Total | 80 | 55 | 65 | 200 |
Computing Expected Counts
Using \(E = \frac{R_i \times C_j}{n}\) for each cell:
| Silence | Lo-fi | Pop | |
|---|---|---|---|
| \(< 3.0\) | \(\frac{90 \times 80}{200} = \) 36 | \(\frac{90 \times 55}{200} = \) 24.75 | \(\frac{90 \times 65}{200} = \) 29.25 |
| \(\geq 3.0\) | \(\frac{110 \times 80}{200} = \) 44 | \(\frac{110 \times 55}{200} = \) 30.25 | \(\frac{110 \times 65}{200} = \) 35.75 |
Computing \(\chi^2\)
Sum the contributions from each cell:
\(\text{df} = (2-1)(3-1) = 2\). Using a \(\chi^2\) table or calculator: \(p\text{-value} \approx 0.0049\).
Follow-Up: Which Cells Drove the Result?
After rejecting \(H_0\), compare each cell's component \(\frac{(O-E)^2}{E}\) to identify where the largest deviations occurred:
Common Mistakes
Question 1 of 5
A \(3 \times 4\) two-way table is used for a chi-square test. What are the degrees of freedom?
Question 2 of 5
In a chi-square test, one cell has \(O = 12\) and \(E = 8\). What is this cell's contribution to the test statistic?
Question 3 of 5
Which condition for a \(\chi^2\) test requires that all expected counts be at least 5?
Question 4 of 5
A researcher takes one random sample of 500 adults and classifies each by political party and opinion on a policy. This is a test of:
Question 5 of 5
In a \(2 \times 3\) table, the row totals are 60 and 90 and the grand total is 150. One column total is 50. What is the expected count for the cell in row 1, that column?