What is a two-way table?
A categorical variable puts each person or thing into a group (a category), like "walk / cycle / bus" or "younger / older". A two-way table (also called a contingency table) shows the counts for two categorical variables together: one variable along the rows, the other along the columns. Each cell holds the count for one row group AND one column group.
| Walk | Cycle | Bus | Total | |
|---|---|---|---|---|
| Younger | 12 | 6 | 2 | 20 |
| Older | 4 | 8 | 8 | 20 |
| Total | 16 | 14 | 10 | 40 |
To build one from raw data, list the categories, tally each record into its cell, then add the totals. The totals in the margins are the marginal totals; the bottom-right number is the grand total.
Joint, marginal and conditional relative frequencies
A relative frequency is a count turned into a fraction or percentage. There are three kinds:
- Joint: cell ÷ grand total. Younger walkers: 12 ÷ 40 = 0.30.
- Marginal: row or column total ÷ grand total. All walkers: 16 ÷ 40 = 0.40.
- Conditional: cell ÷ its row total (or column total). Walkers among younger students: 12 ÷ 20 = 0.60.
Read conditional ones with "given" or "among": "among older students, 40% take the bus" (8 ÷ 20). Notice that "among bus users, 80% are older" (8 ÷ 10) is a different question with a different answer. The phrase tells you which total to divide by.
Graphs and association
Useful graphs for two categorical variables:
- Side-by-side (grouped) bar chart: bars of counts for each group, next to each other.
- Segmented (stacked) bar chart: one bar per group, each 100% tall, split into coloured parts by the other variable.
- Mosaic plot: like a segmented bar chart, but bar widths show group sizes too.
Two variables are associated if knowing one changes the chances for the other. Compare the conditional percentages: 60% of younger students walk versus 20% of older ones, a big difference, so age and travel mode are associated. If the percentages were about equal in every row, the segments would line up and there would be little or no association. Association does not prove that one variable causes the other.
Two-variable data beyond tables
Two-way tables are for two categorical variables. When both variables are numbers (like height and arm span), use a scatter plot instead and look for a trend, a fitted line and residuals (see the linear regression lesson). The question is the same in both cases: does one variable tell us something about the other?
Try it: Ask 20 friends or family members two questions: "Tea or coffee?" and "Age under 30 or 30+?" Build the two-way table, find the conditional percentages for each age group, and decide whether drink choice is associated with age. Then type your counts into 3D free play to see your segmented bars.
Key formulas and definitions
- Joint relative frequency = cell ÷ grand total
- Marginal relative frequency = row (or column) total ÷ grand total
- Conditional relative frequency = cell ÷ its row (or column) total
- All joint relative frequencies add to 1; each row's conditional ones add to 1
- Association: conditional percentages differ between groups
Worked examples
1. Using the school table, how many students take the bus, and what fraction is that?
Column total for Bus = 2 + 8 = 10. Marginal relative frequency = 10 ÷ 40 = 0.25 = 25%.
2. What is the joint relative frequency of "older AND cycle"?
Cell = 8. 8 ÷ 40 = 0.20 = 20%.
3. Among younger students, what percentage cycle?
Divide by the Younger row total: 6 ÷ 20 = 0.30 = 30%.
4. Among cyclists, what percentage are younger?
Now divide by the Cycle column total: 6 ÷ 14 ≈ 0.43 = 43%. Different total, different answer from example 3.
5. Complete the table: 50 people (25 men, 25 women); 30 like football, and 18 of those are women.
Line 1: men who like football = 30 − 18 = 12. Line 2: men who do not = 25 − 12 = 13. Line 3: women who do not = 25 − 18 = 7. Line 4: check the "do not" total: 13 + 7 = 20 = 50 − 30. Every row and column adds up.
6. In a survey of 200 adults, 90 of 120 who exercise sleep well, and 30 of 80 who don't exercise sleep well. Is there an association?
Conditional: 90 ÷ 120 = 75% vs 30 ÷ 80 = 37.5%. The percentages are very different, so exercise and good sleep are associated (but this does not prove exercise causes good sleep).
Common mistakes
- Dividing by the grand total when the question says "among" or "of those who". That wording asks for a conditional frequency: divide by that group's total.
- Mixing up "among bus users, % older" with "among older students, % bus users". Same cell, different denominators.
- Comparing raw counts between groups of different sizes. Always compare percentages.
- Saying association proves cause. A third variable (like distance from school) may explain both.