14. Inference for Contingency Tables

b. Chi-Square Inference
Math 115

Yurk

Recap: Observed vs Expected

14a — GSS 2016, party × military-spending opinion, a 3×3 table of 149 U.S. adults. Each cell: observed count on top, expected count (if \(H_0\) / independence held) below.

Party Too Little About Right Too Much Total
Dem 17
(17.6)
14
(14.4)
12
(11)
43
Ind 20
(29.5)
28
(24.2)
24
(18.4)
72
Rep 24
(13.9)
8
(11.4)
2
(8.7)
34
Total 61 50 38 149
  • \(H_0\): party and military-spending opinion are independent · \(H_A\): they are associated.

From Statistic to Decision

Recall the logic (14a). \(X^2 = \sum_{\text{all cells}} \frac{(O - E)^2}{E}\) adds up how far each observed count falls from its expected count, across the whole table:

  • Larger \(X^2\) = bigger mismatch → stronger evidence against \(H_0\).
  • Smaller \(X^2\) = table close to what \(H_0\) predicts.

For the military table, \(X^2 \approx 18.97\).

Today’s question: is \(18.97\) “big enough” to reject \(H_0\)? We need a reference distribution — the \(X^2\) values we’d expect if \(H_0\) were true.

The Chi-Square Distribution

When conditions are met (next slide), \(X^2\) under \(H_0\) follows a chi-square distribution with degrees of freedom set by the table size.

  • Always non-negative — \(X^2\) is a sum of squared standardized gaps.
  • Right-skewed with a single shape parameter, \(df\).
  • As \(df\) grows, the curve slides right (typical values get larger) and grows less skewed.
  • Bigger \(X^2\) → farther into the right tail → stronger evidence against \(H_0\).

Degrees of Freedom for r×c Tables

For an \(r \times c\) contingency table:

\[df = (r - 1) \times (c - 1)\]

Intuition. Once the row and column totals are fixed, only \((r-1)(c-1)\) cells can vary freely — the rest are pinned down by the totals.

Try it: what’s \(df\) for the 3×3 military table (3 parties × 3 opinion levels)?

\(df = (3 - 1) \times (3 - 1) = 2 \times 2 = 4\). So we compare \(X^2 = 18.97\) to a chi-square distribution with \(df = 4\).

Conditions for the Chi-Square Test

Two conditions before we trust the chi-square distribution as the reference:

Condition Rule
Independence Each individual independent of the others — a random sample or random assignment, otherwise justified from study context.
Sample size At least 5 expected counts in every cell. Check \(E\) (expected), not the observed counts.

Military table. Independence holds — GSS draws a random sample of U.S. adults ✓. The sample-size condition needs the expected counts; rather than compute all nine, we’ll find just the smallest one next.

Checking Sample Size: a Shortcut

Every cell needs expected ≥ 5. Since \(\text{Expected} = \dfrac{\text{row} \times \text{col}}{\text{grand}}\), the smallest expected count sits where the row and column totals are both smallest — check one cell, not nine.

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

Smallest row total: Rep = 34 (orange).

Smallest column total: Too Much = 38 (blue).

Rep × Too Much — observed count here is just 2.

Expected: \(E_{\min} = \dfrac{34 \times 38}{149} \approx 8.67 \ge 5\) ✓ — every cell clears.

The P-Value for Military

  • P-value = area to the right of \(X^2 = 18.97\) under the chi-square curve with \(df = 4\).
  • The alternative is two-sided in spirit — departures from \(H_0\) count in any cell, in any direction — but squaring sends every gap to a positive contribution, so all of that evidence lands in the right tail. Use the right tail only — no doubling.
  • Using Jamovi: p-value \(\approx 8\times 10^{-4}\) — far below 0.05.

Conclusion for Military Spending

Results: \(X^2 = 18.97\), \(df = 4\), p-value \(\approx 8\times 10^{-4}\) — well below 0.05 → reject \(H_0\).

In context: Among U.S. adults, opinion on military spending is associated with political party. Republicans were much more “Too Little” and much less “Too Much” than expected (more supportive of military spending); Independents leaned the opposite way more mildly (less supportive).

Scope of inference.

  • Generalization: random sample of U.S. adults → generalizes to U.S. adults (2016).
  • Causation: observational (variables measured, not assigned) → no causal claim, just a population-level association.

Heads up: the chi-square test answers “is there any association?” — not which groups differ or which direction. The cell contributions only suggest where the mismatch is largest; formally pinning down which groups differ waits for the pairwise follow-up tests in topic 16.

Space Exploration — Setup

Same 149 GSS respondents, same parties — does opinion on space exploration depend on party? New 3×3 table:

Party Too Little About Right Too Much Total
Dem 8 22 13 43
Ind 13 37 22 72
Rep 9 17 8 34
Total 30 76 43 149

Computed for you: \(X^2 \approx 1.33\), \(df = 4\).

  1. State \(H_0\) and \(H_A\), then use the shortcut to find the smallest expected count and check both conditions. \(H_0\): party and space-spending opinion are independent. \(H_A\): they are associated. Independence: GSS random sample of U.S. adults ✓. Sample size (shortcut): smallest row total is Rep (34), smallest column total is Too Little (30), so \(E_{\text{min}} = \frac{34 \times 30}{149} \approx 6.85 \geq 5\) ✓. Both conditions met.

Space Exploration — P-Value & Conclusion

Recall: \(X^2 \approx 1.33\), \(df = 4\). The shaded region to the right of \(X^2\) is the p-value.

  1. The total area under the curve is 1. Using the figure, is the p-value less than the \(\alpha = 0.05\) significance level? Conclude (include scope). \(X^2 \approx 1.33\) sits in the bulk of the \(df = 4\) curve, so the shaded area is a large share of the total area of 1 — nowhere near as small as 0.05. So the p-value > 0.05 (in fact \(\approx 0.86\)). Fail to reject \(H_0\). No evidence that party is associated with opinion on space spending. Scope: GSS random sample → conclusion generalizes to U.S. adults (2016); observational, so no causation.

Same Sample, Different Stories

Question \(X^2\) \(df\) p-value Decision (α = 0.05)
Military spending vs party 18.97 4 \(\approx 8\times 10^{-4}\) Reject \(H_0\) — clear association
Space spending vs party 1.33 4 \(\approx 0.86\) Fail to reject \(H_0\) — no evidence of association

Same 149 people, same three parties, same three opinion levels — but the topic changes everything. Party views split on military spending; party views look indistinguishable on space spending.

The chi-square test answers each question on its own — for these variables, is there an association at all?

Connecting to Topic 10

The chi-square test generalizes the two-proportion test from topic 10:

Two Proportions (Topic 10) Chi-Square Test (Topic 14)
Table size 2 × 2 only Any \(r \times c\)
Statistic \(\hat{p}_1 - \hat{p}_2\) \(X^2\)
Reference distribution Standard normal Chi-square, \(df = (r-1)(c-1)\)
What we test \(p_1 - p_2 = 0\) Independence
Tail(s) used for p-value One- or two-sided, depending on \(H_A\) Always right tail

For a 2×2 table the chi-square test is equivalent to a two-sided topic-10 test — they give the same p-value and same decision. Chi-square is the right tool once the table grows beyond 2×2, because no single “difference in proportions” can summarize bigger tables.

Looking Ahead

We’ve added the chi-square test to the toolkit — for two categorical variables of any size, asking whether the two are associated.

Next: multiple means. Topic 15 tackles the matching question for numerical data — given three or more groups, are any of their mean responses different? — using the F-statistic and ANOVA.

References