a. The Chi-Square Statistic
Math 115
We’ve been building inference for categorical data in stages:
| Topic | What we tested | Statistic | Example |
|---|---|---|---|
| 6 | One categorical variable | \hat{p} | Payday loans |
| 10 | Two groups × a binary outcome (2×2) | \hat{p}_1 - \hat{p}_2 | CPR survival |
| 14 (today) | Two categorical variables (any r×c) | X^2 | Party × spending |
Today continues the thread from topics 6 and 10. Once a variable has more than two categories, the table grows past 2×2 and a single difference in proportions can’t summarize it — so we score the whole table with one number, X^2.
Is opinion on military spending associated with political party? General Social Survey, 2016 — random sample of 149 U.S. adults.
“No relationship” between two categorical variables is called independence:
Party (3 rows) × opinion (3 columns) — a 3×3 table, bigger than topic 10’s 2×2 in both directions.
| Party | Too Little | About Right | Too Much | Row total |
|---|---|---|---|---|
| Dem | 17 | 14 | 12 | 43 |
| Ind | 20 | 28 | 24 | 72 |
| Rep | 24 | 8 | 2 | 34 |
| Col total | 61 | 50 | 38 | 149 |
Looking row by row, Republicans look noticeably more likely to say “Too Little” and noticeably less likely to say “Too Much” than Democrats or Independents — in this sample. Real association, or sampling noise?
To answer that, we need to compare these counts to what we’d expect if party and opinion were truly independent.
Each cell has an expected count — the value we’d see if H_0 (independence) held:
| Party | Too Little | About Right | Too Much | Row total |
|---|---|---|---|---|
| Dem | 17 | 14 | 12 | 43 |
| Ind | 20 | 28 | 24 | 72 |
| Rep | 24 | 8 | 2 | 34 |
| Col total | 61 | 50 | 38 | 149 |
Focus on one cell — Democrats who said “Too Little” (observed 17). If H_0 held, what count would we expect here?
Overall, \dfrac{61}{149} \approx 41\% said “Too Little.” Under H_0, that same share appears in every row.
So expect that share of the 43 Democrats: E_{\text{Dem, TL}} = \underbrace{43}_{\text{Democrats}} \times \underbrace{\tfrac{61}{149}}_{H_0\text{ proportion}} \approx 17.6.
Expected 17.6 vs observed 17 — almost exactly what independence predicts.
We just built the Democrat cell as row total \times H_0 proportion:
E_{\text{Dem, TL}} = \underbrace{43}_{\text{row total}} \times \underbrace{\tfrac{61}{149}}_{H_0\text{ proportion}} \approx 17.6
Every cell works the same way — just swap in that cell’s own row total and column:
\text{Expected} = (\text{row total}) \times \underbrace{\frac{\text{column total}}{\text{grand total}}}_{H_0\text{ proportion}} = \frac{(\text{row total}) \times (\text{column total})}{\text{grand total}}
Republicans saying “Too Little” — if H_0 (independence) held, what count would we expect? Read the totals you need off the table, then use \text{Expected} = \dfrac{\text{row} \times \text{column}}{\text{grand total}}.
| Party | Too Little | About Right | Too Much | Row total |
|---|---|---|---|---|
| Dem | 17 | 14 | 12 | 43 |
| Ind | 20 | 28 | 24 | 72 |
| Rep | 24 | 8 | 2 | 34 |
| Col total | 61 | 50 | 38 | 149 |
E_{\text{Rep, TL}} = \dfrac{34 \times 61}{149} = \dfrac{2074}{149} \approx 13.92. Observed was 24 — far more than H_0 predicts. This cell is where the association starts to show.
Observed (Expected) for every cell:
| Party | Too Little | About Right | Too Much |
|---|---|---|---|
| Dem | 17 (17.6) | 14 (14.43) | 12 (10.97) |
| Ind | 20 (29.48) | 28 (24.16) | 24 (18.36) |
| Rep | 24 (13.92) | 8 (11.41) | 2 (8.67) |
Democrats: observed ≈ expected across all three — 17 vs 17.6, 14 vs 14.4, 12 vs 11.
Independents: fewer “Too Little” than expected, more “Too Much” — they lean toward “Too Much.”
Republicans: far more “Too Little” than expected, far fewer “Too Much” — they lean toward “Too Little.”
Independents and Republicans pull in opposite directions. We need one number that combines all nine gaps.
Score each cell, then sum across the whole table:
X^2 = \sum_{\text{all cells}} \frac{(\text{Observed} - \text{Expected})^2}{\text{Expected}}
Two design choices in the formula:
Bigger X^2 = more total deviation from independence = stronger evidence against H_0.
For each cell, compute \dfrac{(O - E)^2}{E}:
| Party | Too Little | About Right | Too Much |
|---|---|---|---|
| Dem | \frac{(17 - 17.6)^2}{17.6} \approx 0.02 | \frac{(14 - 14.43)^2}{14.43} \approx 0.01 | \frac{(12 - 10.97)^2}{10.97} \approx 0.1 |
| Ind | \frac{(20 - 29.48)^2}{29.48} \approx 3.05 | \frac{(28 - 24.16)^2}{24.16} \approx 0.61 | \frac{(24 - 18.36)^2}{18.36} \approx 1.73 |
| Rep | \frac{(24 - 13.92)^2}{13.92} \approx 7.3 | \frac{(8 - 11.41)^2}{11.41} \approx 1.02 | \frac{(2 - 8.67)^2}{8.67} \approx 5.13 |
X^2 \approx 0.02 + 0.01 + 0.1 + 3.05 + 0.61 + 1.73 + 7.3 + 1.02 + 5.13 \approx 18.97
The full sum is X^2 \approx 18.97. Each cell’s contribution sits in the table above. Which two cells push X^2 up the most — and what’s the story those cells tell?
Identify the two largest cell contributions. Republicans, “Too Little” (\approx 7.3) and Republicans, “Too Much” (\approx 5.13). Together they account for about 12.4 out of 18.97 — roughly two-thirds of the total.
What do those two cells say about where the association is? Republicans were more likely than expected to say “Too Little” (24 observed vs 13.9 expected) and less likely than expected to say “Too Much” (2 observed vs 8.7 expected). X^2 summarizes how different the table is from “no association”; the cell-by-cell contributions tell us where the difference is.
Next time (14b): the chi-square distribution, conditions, the p-value, and the decision.