Math 115
Previously, we compared two groups with a binary outcome (2×2 table).
But what if we have:
We need a new approach!
Generalization 1: More groups
Generalization 2: Non-binary response
With either generalization, we can’t use a single difference in proportions!
Same concept as before, different statistic:
New statistic: Chi-square, \(X^2\), measures deviation from independence.
Research question: Is political party associated with opinions on military spending?
This creates a 3×3 contingency table.
| Party | Too Little | About Right | Too Much | Total |
|---|---|---|---|---|
| Dem | 17 | 14 | 12 | 43 |
| Ind | 20 | 28 | 24 | 72 |
| Rep | 24 | 8 | 2 | 34 |
| Total | 61 | 50 | 38 | 149 |
Beyond simple \(2\times 2\) tables, we can’t compute just one difference in proportions.
We need to compare all observed counts to what we’d expect under \(H_0\).
If \(H_0\) is true (no association), each party should have the same distribution of opinions.
Expected count for any cell:
\[\text{Expected} = \frac{\text{row total} \times \text{column total}}{\text{grand total}}\]
This distributes the overall opinion proportions equally across all parties.
Example: Democrats who say “Too Little”
\[\text{Expected} = \frac{43 \times 61}{149} = 17.6\]
| Party | Too Little | About Right | Too Much |
|---|---|---|---|
| Dem | 17 (17.6) | 14 (14.4) | 12 (11) |
| Ind | 20 (29.5) | 28 (24.2) | 24 (18.4) |
| Rep | 24 (13.9) | 8 (11.4) | 2 (8.7) |
Observed (Expected) — How different are they?
Measures total deviation of observed from expected:
\[X^2 = \sum_{\text{all cells}} \frac{(\text{Observed} - \text{Expected})^2}{\text{Expected}}\]
Why this formula?
For each cell, compute \(\frac{(O - E)^2}{E}\):
| Party | Too Little | About Right | Too Much |
|---|---|---|---|
| Dem | \(\frac{(17 - 17.6)^2}{17.6} = 0.02\) | \(\frac{(14 - 14.4)^2}{14.4} = 0.01\) | \(\frac{(12 - 11)^2}{11} = 0.10\) |
| Ind | \(\frac{(20 - 29.5)^2}{29.5} = 3.05\) | \(\frac{(28 - 24.2)^2}{24.2} = 0.61\) | \(\frac{(24 - 18.4)^2}{18.4} = 1.73\) |
| Rep | \(\frac{(24 - 13.9)^2}{13.9} = 7.30\) | \(\frac{(8 - 11.4)^2}{11.4} = 1.02\) | \(\frac{(2 - 8.7)^2}{8.7} = 5.13\) |
\[X^2 = 0.02 + 0.01 + 0.10 + 3.05 + 0.61 + 1.73 + 7.30 + 1.02 + 5.13 = 18.97\]
But how large is “large enough” to reject \(H_0\)?
We need a reference distribution → chi-square distribution
For contingency tables:
\[df = (\text{rows} - 1) \times (\text{columns} - 1)\]
For our 3×3 table:
\[df = (3-1) \times (3-1) = 2 \times 2 = 4\]
Intuition: After fixing row and column totals, only \(df\) cells can vary freely.
When conditions are met, we can use the chi-square distribution as our reference:
Computing the p-value:
Independence:
Expected Counts (under \(H_0\)):
Check expected counts, not observed counts!
Chi-squared distribution with \(df=4\)
P-value < 0.001
Results:
Decision: Reject \(H_0\)
Conclusion: There is a statistically significant association between political party and opinions on military spending. The parties differ in their views.
Note: The chi-square test tells us there IS an association, but not the direction or which groups differ.
Same parties, same opinion categories, but asking about space exploration spending.
| Party | Too Little | About Right | Too Much | Total |
|---|---|---|---|---|
| Dem | 8 | 22 | 13 | 43 |
| Ind | 13 | 37 | 22 | 72 |
| Rep | 9 | 17 | 8 | 34 |
\(X^2 = 1.33\), df = 4, P-value = 0.857
| Issue | \(X^2\) | P-value | Conclusion |
|---|---|---|---|
| Military | 18.97 | < 0.001 | Strong association |
| Space | 1.33 | 0.857 | No evidence of association |
Same groups, different topics, very different conclusions!
Chi-square test extends two-proportion test to larger tables:
| Component | Formula/Value |
|---|---|
| Expected count | \(\frac{\text{row total} \times \text{column total}}{\text{grand total}}\) |
| Chi-square statistic | \(X^2 = \sum \frac{(O - E)^2}{E}\) |
| Degrees of freedom | \(df = (r-1) \times (c-1)\) |
| P-value | Right tail of chi-square distribution |
Conditions: Independence + Expected counts ≥ 5 in each cell
| Two Proportions | Chi-Square Test | |
|---|---|---|
| Table size | 2×2 only | Any r×c |
| Test statistic | Z | \(X^2\) |
| Null distribution | Normal | Chi-square |
| What we test | \(p_1 - p_2 = 0\) | Independence |
| Direction | Can be one-sided | Always two-sided |
Chi-square generalizes the two-proportion test to larger tables!
(For 2×2 tables, both methods give equivalent results)