01 / 21
O E \(\chi^2\)

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.

AP Statistics

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

Homogeneity
Are the distributions of one categorical variable the same across two or more populations? Data come from separate random samples, one from each population.
Independence
Are two categorical variables independent within a single population? Data come from one random sample, cross-classified by both variables.

The Two-Way Table

Category Group 1 Group 2 Row Total A \(O_{11}\) \(O_{12}\) \(R_1\) B \(O_{21}\) \(O_{22}\) \(R_2\) C \(O_{31}\) \(O_{32}\) \(R_3\) Col Total \(C_1\) \(C_2\) \(n\)

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

\(O - E\)
Difference between what we observed and what we expected.
\((O-E)^2\)
Squaring makes all deviations positive and penalises large gaps more.
\(\div\; E\)
Dividing by \(E\) standardises: a difference of 5 matters more when \(E = 10\) than when \(E = 100\).

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\).

\(\chi^2\) density 0 5 10 15 df = 1 df = 3 df = 6

Stating the Hypotheses

Homogeneity
\(H_0\): The distribution of the categorical variable is the same for all populations.
\(H_a\): The distributions differ for at least one population.
Independence
\(H_0\): The two variables are independent in the 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

1
Random: Data must come from a random sample (independence test) or independent random samples (homogeneity test).
2
10% Rule: Each sample should be < 10% of its population (ensures independence of observations).
3
Large Counts: All expected counts must satisfy \(E \geq 5\). Check every cell, not just the totals.

How to Carry Out the Test

1
State hypotheses: Write \(H_0\) and \(H_a\) appropriate to the context (homogeneity or independence).
2
Check conditions: Random, 10%, and Large Counts (\(E \geq 5\) in every cell).
3
Calculate expected counts: \(E = \frac{R_i \times C_j}{n}\) for each cell.
4
Compute \(\chi^2\): Sum \(\frac{(O-E)^2}{E}\) across all cells.
5
Find the p-value: Use a \(\chi^2\) distribution with \(\text{df} = (r-1)(c-1)\).
6
Conclude: Compare p-value to \(\alpha\). If \(p < \alpha\), reject \(H_0\) and state what this means in context.

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:

Pop / \(< 3.0\)
Component = 3.95: many more low-GPA students preferred pop than expected.
Pop / \(\geq 3.0\)
Component = 3.23: far fewer high-GPA students preferred pop than expected.
Other cells
Components \(< 1.0\): silence and lo-fi categories were close to expected counts.

Common Mistakes

✕ Using Observed for Condition
The Large Counts condition requires expected counts \(\geq 5\), not observed counts.
✕ Wrong df Formula
It is \((r-1)(c-1)\), not \((\text{cells} - 1)\) or \((n - 1)\). Don't count the totals row/column.
✕ Claiming Causation
The \(\chi^2\) test shows association, not causation. Unless data come from a randomised experiment, avoid causal language.

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?