Two-Way Tables & Categorical Association
Cross-classifying two categorical variables and reading association straight off the counts — no p-values yet.
Two variables, one table
So far you have studied one categorical variable at a time — favorite color, yes or no, pass or fail. Many real questions involve two categorical variables measured on the same individuals: smoking status and lung disease, treatment and outcome, region and opinion. A two-way table (also called a contingency table) lays out the counts for every combination of the two variables' categories.
This lesson is entirely descriptive: everything here is counting and dividing, with no p-values and no hypothesis test. It builds the vocabulary — marginal, joint, and conditional distributions — that the chi-square test in the next lesson turns into an actual inference.
Marginal, joint, and conditional distributions
Take a survey of 100 residents, cross-classified by region and opinion on a new policy:
- North: 30 favor, 20 oppose (row total 50)
- South: 15 favor, 35 oppose (row total 50)
- Column totals: 45 favor, 55 oppose (grand total 100)
Three different distributions live inside this one table:
- The marginal distribution of a single variable is its row or column totals, ignoring the other variable entirely — e.g. 45 of the 100 residents favor the policy, however their region breaks down.
- The joint distribution is each cell count divided by the grand total — e.g. the joint probability of being from the North and favoring the policy is 30/100.
- The conditional distribution restricts to one row or column and divides by that total — e.g. among Northerners only, the conditional proportion favoring is 30/50.
Judging association from conditional distributions
To ask whether region and opinion are related, do not stare at the raw counts — compare the conditional distributions across groups. If North's split between favor and oppose looks the same as South's split, the variables move independently of each other. If the splits differ, that difference is association.
A segmented bar chart draws each group's conditional distribution as one full-height bar, divided into segments by proportion. Two bars with matching segment heights say "no association"; bars that lean differently say the opposite.
- Expected count, North and favor: \( E = (50)(45)/100 = 22.5 \).
- Expected count, North and oppose: \( E = (50)(55)/100 = 27.5 \).
- Expected count, South and favor: \( E = (50)(45)/100 = 22.5 \).
- Expected count, South and oppose: \( E = (50)(55)/100 = 27.5 \).
- Joint: \( P(\text{North and favor}) = 30/100 = 0.30 \).
- Marginals: \( P(\text{North}) = 50/100 = 0.50 \). \( P(\text{favor}) = 45/100 = 0.45 \).
- Conditional: \( P(\text{favor} \mid \text{North}) = 30/50 = 0.60 \).
- Hospital 1: A = 9/10 = 0.90. B = 85/100 = 0.85. A beats B here.
- Hospital 2: A = 30/100 = 0.30. B = 2/10 = 0.20. A beats B here too.
- Combined A: \( (9 + 30)/(10 + 100) = 39/110 \approx 0.355 \).
- Combined B: \( (85 + 2)/(100 + 10) = 87/110 \approx 0.791 \).
Check your understanding
- A two-way (contingency) table cross-classifies two categorical variables measured on the same individuals.
- MARGINAL = row or column totals (one variable alone). JOINT = cell divided by the grand total (both variables at once). CONDITIONAL = cell divided by its own row or column total (one variable given a level of the other).
- Judge association by comparing conditional distributions across groups, not by eyeballing raw counts.
- Expected count under independence: E = (row total)(column total) / n.
- Association is a property of the data; a causal claim needs random assignment.
- Simpson's paradox: an association present in every subgroup can reverse when the subgroups are combined, if a lurking variable is unevenly split across them.