Contingency Tables
Scatter plots work when both variables are numbers. But what if both are categories, like grade level and where students eat lunch? Then you organize the data in a contingency table (two-way table) and compare percentages to see whether the two variables are related.
Key ideas
Section titled “Key ideas”Two-way (contingency) tables
Section titled “Two-way (contingency) tables”A contingency table counts how many individuals fall into each combination of two categorical variables. One variable labels the rows, the other labels the columns, and each cell holds a count.
| Packed lunch | Cafeteria | Off campus | Total | |
|---|---|---|---|---|
| Junior (Gr 9–10) | ||||
| Senior (Gr 11–12) | ||||
| Total |
- Row totals (right column) and column totals (bottom row) are the marginal totals.
- The bottom-right number is the grand total. Both the row totals and the column totals add up to it, which is a handy check.
Relative frequencies
Section titled “Relative frequencies”A relative frequency divides a count by the grand total:
For example, , so of all students surveyed are juniors who pack a lunch.
Row and column percentages
Section titled “Row and column percentages”To compare groups fairly when they’re different sizes, use percentages within each group.
- Row percentage: divide each cell by its row total. Use this to compare the rows (here, juniors versus seniors).
- Column percentage: divide each cell by its column total. Use this to compare the columns.
A row percentage is exactly a conditional probability: the percentage of seniors who eat off campus is .
Is there a relationship?
Section titled “Is there a relationship?”If the two variables are not related, each row would have roughly the same row percentages (and they would match the overall percentages in the Total row). If the row percentages differ a lot, the data suggest a relationship. As always, a relationship doesn’t prove cause and effect (see correlation and causation).
Worked examples
Section titled “Worked examples”Example 1: Completing a table
Section titled “Example 1: Completing a table”A survey of students asked whether they keep their phone in their bedroom at night and whether they usually get at least hours of sleep. Complete the table.
| 8 h or more | Under 8 h | Total | |
|---|---|---|---|
| Phone in bedroom | |||
| No phone in bedroom | |||
| Total |
Solution.
- Phone, under 8 h: .
- No phone total: , so no phone, 8 h or more: .
- Column totals: and .
| 8 h or more | Under 8 h | Total | |
|---|---|---|---|
| Phone in bedroom | |||
| No phone in bedroom | |||
| Total |
Check: . ✓
Example 2: Relative frequencies
Section titled “Example 2: Relative frequencies”Using the lunch table above, find the relative frequency of (a) seniors who eat off campus (b) all students who eat in the cafeteria.
Solution.
(a) , or of all students surveyed.
(b) , or .
Example 3: Row percentages and a relationship
Section titled “Example 3: Row percentages and a relationship”Use row percentages to compare juniors and seniors in the lunch table. Is there a relationship between grade level and where students eat lunch?
Solution. Divide each cell by its row total.
| Packed lunch | Cafeteria | Off campus | |
|---|---|---|---|
| Junior | |||
| Senior |
The patterns are very different. Only about of juniors eat off campus, compared with about of seniors, and juniors are much more likely to pack a lunch. So in this survey, grade level and lunch location appear to be related. (A possible reason: many schools let only senior students leave at lunch.)
In probability language, .
Example 4: Row or column percentages?
Section titled “Example 4: Row or column percentages?”Using the lunch table, what percentage of the students who eat off campus are seniors? Why is this different from the percentage of seniors who eat off campus?
Solution. “Of the students who eat off campus” means look only at the Off campus column:
The percentage of seniors who eat off campus uses the Senior row instead: .
Same cell, different group. Ask “out of whom?” The group after “of” tells you which total to divide by.
Common mistakes
Section titled “Common mistakes”Comparing raw counts when groups are different sizes. seniors and juniors pack a lunch, but there are more seniors overall. Compare percentages, not counts.
Dividing by the wrong total. Relative frequency uses the grand total, row percentage uses the row total, and column percentage uses the column total. Decide which group the question is about first.
Mixing up “percentage of seniors who…” with “percentage of … who are seniors”. These are different, just like and .
Forgetting to check totals. Row totals and column totals must both add up to the grand total. If they don’t, there’s an arithmetic error somewhere.
Calling a relationship “cause and effect”. A contingency table can show that two variables are related, not why.
Practice
Section titled “Practice”1. (Warm-up) Using the completed table in Example 1, how many students surveyed get under hours of sleep? How many keep their phone in their bedroom?
Solution
get under hours; keep their phone in their bedroom.
2. (Warm-up) Using Example 1, find the relative frequency of students who keep their phone in their bedroom and get hours or more.
Solution
, or about .
3. (Warm-up) To answer “What percentage of Grade 12 students play a sport?”, where grade labels the rows and sport labels the columns, would you use a row percentage or a column percentage?
Solution
A row percentage: you look only at the Grade 12 row and divide by its total.
4. (Core) Using Example 1, find the percentage of each group (phone, no phone) that gets hours or more. Does there seem to be a relationship?
Solution
Phone in bedroom: . No phone: .
Students without a phone in their bedroom were more than twice as likely to get hours of sleep, so there does appear to be a relationship. (This survey can’t prove the phone causes less sleep.)
5. (Core) A survey of students:
| Takes music | No music | Total | |
|---|---|---|---|
| On a sports team | |||
| Not on a team | |||
| Total |
Is there a relationship between being on a sports team and taking music? Use row percentages.
Solution
On a team: take music. Not on a team: take music.
The row percentages are identical (and equal to the overall ), so there’s no evidence of a relationship in this data.
6. (Core) A survey of households:
| Dog | Cat | No pet | Total | |
|---|---|---|---|---|
| Urban | ||||
| Rural | ||||
| Total |
- (a) Find the row percentages for each type of household.
- (b) What percentage of cat owners live in rural areas?
- (c) Describe any relationship.
Solution
(a) Urban: dog , cat , no pet . Rural: dog , cat , no pet .
(b) .
(c) Rural households in this survey were more likely to have a cat and more likely to have some pet; urban households were more likely to have a dog or no pet. Location and pet type appear to be related.
7. (Core) Students aged to were asked their favourite movie genre:
| Action | Comedy | Drama | Total | |
|---|---|---|---|---|
| Ages 13–15 | ||||
| Ages 16–18 | ||||
| Total |
Find and , and compare the two age groups.
Solution
.
.
Row percentages: ages 13–15 are action, comedy, drama; ages 16–18 are action, comedy, drama. The younger group strongly prefers action, while the older group leans toward comedy and drama, so age and favourite genre seem related.
8. (Challenge) A survey of people includes adults and teens. of the adults and of the teens prefer streaming to cable TV (everyone chose one). Build the contingency table, then find the percentage of streamers who are teens.
Solution
Adults who stream: , so prefer cable. Teens who stream: , so prefer cable.
| Streaming | Cable | Total | |
|---|---|---|---|
| Adults | |||
| Teens | |||
| Total |
Percentage of streamers who are teens: .
9. (Challenge) A table has three rows. Row A has “yes” and “no”. Row B has a total of , and row C has a total of . How many “yes” answers should rows B and C have if there’s no relationship between the row variable and the answer? Explain.
Solution
With no relationship, every row has the same percentage of “yes” answers. Row A: .
Row B: “yes” (and “no”). Row C: “yes” (and “no”).
Check: overall, , the same as each row.