Grade by Grade
D. Statistical Analysis · Two-Variable Data Analysis and Validity

Two Categorical Variables: Contingency Tables

D2.1 D2.5About 70 minutes
Learning goals
  • I can organize two categorical variables in a contingency (two-way) table with marginal totals.
  • I can calculate joint, marginal and conditional relative frequencies.
  • I can compare conditional distributions to decide whether two categorical variables are associated.
  • I can calculate the counts expected if there were no association, and draw a segmented bar graph.

Words to know

contingency table
A two-way table that shows the counts for every combination of two categorical variables. Also called a two-way table or cross-tabulation.
joint frequency
The count in one cell of the table, for one category of each variable.
marginal frequency
A row total or column total, written in the margin of the table.
conditional distribution
The percentages for one variable within a single category of the other variable, such as the distribution of housework hours among women only.
association
Two categorical variables are associated if the conditional distributions differ from one category to another.
expected count
The count a cell would have if the variables were not associated: (row total × column total) ÷ grand total.
segmented bar graph
A bar graph in which each bar is 100% and is divided into the percentages of each category.

When both variables are categories

You cannot make a scatter plot of gender and how much unpaid housework someone does if the housework is recorded in categories. Correlation needs numbers. For two categorical variables, the tool is a contingency table.

The curriculum suggests an example from Statistics Canada, which publishes tables comparing groups on things like income and time spent on unpaid work. Here you will work with a made-up survey in the same style.

The survey

A researcher asked 400 adults in an Ontario city how many hours of unpaid housework (cooking, cleaning, laundry, home repairs) they do in a typical week. She recorded each person's gender and put each answer in one of three categories. (Real surveys also include people of other genders; this practice table shows two groups.)

less than 5 h5 to 14 h15 h or moreTotal
Women339988220
Men638136180
Total96180124400
Weekly unpaid housework by gender, 400 adults (made-up data).
YesNoTotalGrade 11abrow totalGrade 12cdrow totalTotalcol totalcol totalgrand totaljoint counts (blue) · marginal totals (yellow) · grand total (green)
The parts of any contingency table. The inside cells are joint counts; the totals around the edge are marginal totals.

Three kinds of relative frequency

  1. Joint: a cell divided by the grand total. For example, 88 ÷ 400 = 22% of all respondents are women who do 15 h or more.
  2. Marginal: a row or column total divided by the grand total. For example, 124 ÷ 400 = 31% of all respondents do 15 h or more.
  3. Conditional: a cell divided by its own row (or column) total. For example, among women, 88 ÷ 220 = 40% do 15 h or more; among men, 36 ÷ 180 = 20% do.

To compare groups of different sizes (220 women, 180 men), always use conditional percentages. Raw counts mislead: 99 women and 81 men do 5 to 14 h, but that is 45% of both groups.

less than 5 h5 to 14 h15 h or moreTotal
Women15%45%40%100%
Men35%45%20%100%
Conditional distributions: each row is divided by its own row total.
Weekly unpaid housework: percent of each groupWomen15%45%40%Men35%45%20%0%25%50%75%100%less than 5 h5 to 14 h15 h or more
A segmented bar graph shows each group's conditional distribution as a 100% bar. The bars split differently, so housework hours and gender are associated in this sample.

Is there an association?

If gender and housework hours were not associated, each gender would have the same conditional distribution, equal to the overall (marginal) distribution: 96/400 = 24%, 180/400 = 45%, 124/400 = 31%.

That lets you compute the expected count for each cell if there were no association:

expected count = (row total × column total) ÷ grand total

You may recognize this from the unit Probability: if two events A and B are independent, P(A and B) = P(A) × P(B). Comparing observed counts with expected counts shows where the groups differ. (University statistics courses turn this comparison into a formal test, the chi-square test.)

Worked example

Example 1: Expected counts

Find the expected counts for the housework table if gender and hours were not associated, and compare with the observed counts.

  1. Women, less than 5 h: 220 × 96 ÷ 400 = 52.8 (observed 33).
  2. Women, 5 to 14 h: 220 × 180 ÷ 400 = 99 (observed 99).
  3. Women, 15 h or more: 220 × 124 ÷ 400 = 68.2 (observed 88).
  4. Men: 180 × 96 ÷ 400 = 43.2 (observed 63); 180 × 180 ÷ 400 = 81 (observed 81); 180 × 124 ÷ 400 = 55.8 (observed 36).
  5. Check: each row of expected counts adds to its row total (52.8 + 99 + 68.2 = 220 ✓).

More women than expected do 15 h or more (88 vs 68.2), and more men than expected do less than 5 h (63 vs 43.2). The middle category matches exactly. In this sample, gender and unpaid housework hours are associated. (Expected counts may be decimals; they are averages, not real people.)

Worked example

Example 2: Row or column percentages?

Using the housework table, what percent of the people who do 15 h or more are women? Why is this different from the percent of women who do 15 h or more?

  1. "Of the people who do 15 h or more" means divide by the column total: 88 ÷ 124 ≈ 71.0%.
  2. "Of the women" means divide by the row total: 88 ÷ 220 = 40%.
  3. The two questions have different denominators, so they have different answers.

About 71% of heavy-housework respondents are women, but 40% of women are heavy-housework respondents. Always ask: percent of what? Mixing these up is a common way to misread statistics in the media.

Worked example

Example 3: Building a table from a description

In a survey of 250 Grade 12 students, 140 plan to go to university. Of those, 84 have a part-time job. Of the students not planning to go to university, 66 have a part-time job. Build the contingency table and decide whether having a job is associated with university plans.

  1. Rows: university (140) and not university (250 − 140 = 110). Columns: job, no job.
  2. University: job 84, no job 140 − 84 = 56. Not university: job 66, no job 110 − 66 = 44.
  3. Column totals: job 84 + 66 = 150; no job 56 + 44 = 100. Grand total 250 ✓.
  4. Conditional: university students with a job 84 ÷ 140 = 60%; others 66 ÷ 110 = 60%.

The conditional percentages are equal (60% in both groups), so in this sample there is no association between university plans and having a part-time job.

Reading percentages carefully

  • "Percent of women who..." → divide by the women total.
  • "Percent of ... who are women" → divide by the total of the other category.
  • "Percent of all respondents who are women and ..." → divide by the grand total.

Write the denominator in words before you calculate.

Just for fun

Statistics joke: there are two kinds of people in the world. Those who can sort people into a contingency table, and those who need a third column labelled "Total".

Hands-on activity

Your own two-way survey

You need: paper, a pencil, and at least 20 people you can ask (family, friends, a team chat). Choose two yes/no or category questions, for example:

  • "Do you prefer winter or summer?" and "Do you skate or ski at least once a year?"
  • "Do you drink coffee?" and "Are you under 30 or 30 and over?"
  1. Ask each person both questions and tally the answers in a 2 × 2 contingency table with totals.
  2. Find the conditional percentages for each row.
  3. Calculate the expected counts if there were no association.
  4. Draw a segmented bar graph.
  5. Write two sentences: is there an association in your sample? Is your sample big enough, and representative enough, to say anything about everyone?

What to look for: rows of expected counts must add to the row totals. With only 20 people, differences of a few people can change the percentages a lot, so conclusions should be cautious. Respect privacy: do not record names.

Your turn

1

A survey of 300 people: 120 are under 30. Of those, 84 stream music daily; of the 180 people 30 and over, 90 stream daily. Make the contingency table.

2

Using your table, find the conditional percent who stream daily in each age group.

3

Is age group associated with daily streaming in this sample? Explain.

4

Find the expected count for under 30, daily if there were no association.

5

What percent of daily streamers are under 30?

6

What is the joint relative frequency of 30 and over, not daily?

More practice: warm-up

1

What kind of variables go in a contingency table?

2

What is a marginal total?

3

A row has counts 12 and 28. What are the conditional percentages?

4

Write the expected-count formula.

5

In a segmented bar graph, what does each full bar add up to?

More practice: on your own

1

A table of 500 students: 260 play a sport; 150 of the sport players and 90 of the others have an A average. Find the percent with an A average in each group and comment.

2

For the same table, find the expected number of sport players with an A average if there were no association.

3

A headline says "60% of people in car crashes were wearing seat belts, so seat belts don't help". Explain the error using row and column percentages.

4

In a 2 × 2 table with grand total 200, row totals 80 and 120 and column totals 50 and 150, find all four expected counts.

5

Explain why comparing raw counts can be misleading when the two groups are different sizes.

Challenge

1

Show that if every expected count equals its observed count in a 2 × 2 table, then the row conditional percentages are equal.

2

A 2 × 2 table has a = 30, b = 20, c = 45, d = x (rows: a, b and c, d). For what value of x are the variables not associated?

3

Statistics Canada tables often show income by gender and by age group. Explain why an overall comparison by gender alone could give a different impression from comparisons within each age group.

Check your understanding

Quiz

1.

In a contingency table, a row total is an example of a:

2.

Of 150 Grade 12 students, 90 take MDM4U. Of those, 54 also take MHF4U. What percent of MDM4U students take MHF4U?

3.

Row totals 60 and 40, column totals 70 and 30, grand total 100. The expected count for the first row, first column is:

4.

Two categorical variables are associated when:

5.

Why use conditional percentages instead of raw counts to compare two groups?

6.

88 of 220 women and 36 of 180 men do 15 h or more of housework. What percent of the people who do 15 h or more are women?

For parents and teachers

Big idea (D2.1): when both variables are categories, organize them in a contingency table and compare groups with conditional percentages. If the conditional distributions differ, the variables are associated.

How to help: The single most useful habit is asking "percent of what?" When your teen states a percentage, ask them to say the denominator in words. Newspaper and Statistics Canada tables give great practice.

Common difficulties:

  • Dividing by the wrong total (row vs column vs grand total).
  • Comparing raw counts for groups of different sizes.
  • Forgetting that expected counts can be decimals.
  • Concluding that an association proves cause.