Topic contents

Lesson 2

Contingency tables: are two categorical variables related?

Examine the same survey data using counts, row percentages, and column percentages

Put two categorical variables into one table

A survey asks university students whether they have used generative AI tools. One variable is year of study (first year / third year), and the other is whether AI tools are used (yes / no). Each person belongs to only one cell.

Class question: if more third-year students have used AI, can we say that AI use is more common among third-year students?

Adjust the survey data

Year of studyHave used AIHave not used AITotal
First year6238100
Third year12832160
Grand total19070260

Each row represents a year of study, and each column represents AI use. Each cell counts people who meet both category conditions.

Total sample size is fixed at 260

Plot the counts

050100First year · Have used AI: 62First year · Have not used AI: 38First yearThird year · Have used AI: 128Third year · Have not used AI: 32Third year
  • Have used AI
  • Have not used AI
Bar chart of AI users and nonusers by year of study

The legend distinguishes users from nonusers. This display compares counts, rather than percentages.

Third-year AI users: 128; first-year AI users: 62. However, the sample sizes differ, so compare row percentages to assess how common AI use is.

To compare two years of study, first look at the proportions within each year

The survey includes 100 and 160 students from the two years, respectively. To compare how common AI use is in each year, we usually calculate row percentages: a cell count divided by its row total.

Year of studyHave used AIHave not used AITotal
First year62.0%38.0%100.0%
Third year80.0%20.0%100.0%
Grand total73.1%26.9%100.0%
First-year usage proportion=62100=62.0%;Third-year=128160=80.0%\text{First-year usage proportion}=\frac{62}{100}=62.0\%;\quad\text{Third-year}=\frac{128}{160}=80.0\%

Within each year, the percentages for “Have used AI” and “Have not used AI” add up to 100%.

100% stacked bar chart

0%20%40%60%80%100%First year · Have used AI: 62%First year · Have not used AI: 38%First yearThird year · Have used AI: 80%Third year · Have not used AI: 20%Third year
  • Have used AI
  • Have not used AI
100% stacked bar chart comparing years of study
62.0% First-year usage proportion
80.0% Third-year usage proportion

In the sample, the third-year usage proportion is higher than the first-year proportion; the difference in percentage points is 18.0.

Row and column percentages answer different questions

If we instead ask which year most AI users come from, the denominator is no longer the number of students in a particular year. It is the total number of students who have used AI. Use column percentages for this question.

Table display
Year of studyHave used AIHave not used AITotal
First year6238100
Third year12832160
Grand total19070260

First-year users: 62; third-year users: 128; total users: 190.

A frequency table answers “How many people?” Row percentages answer “What proportion of each year uses AI?” Column percentages answer “Which year do users come from?”

The same table changes meaning when the denominator changes

0%20%40%60%80%100%First year · Have used AI: 62%First year · Have not used AI: 38%First yearThird year · Have used AI: 80%Third year · Have not used AI: 20%Third year
  • Have used AI
  • Have not used AI
100% stacked bar chart comparing years of study

Frequency table: shows the number of people in each cell, but does not account for the groups' different sample sizes.

If a column has a count of 0, its percentages cannot be calculated and must not be reported as 0%.

Do different percentages in two years establish a population association?

A contingency table describes the distribution and differences of two categorical variables in a sample. However, different sample proportions do not automatically imply a statistically significant association between the variables in the population.

Observe the sample difference

0%20%40%60%80%100%First year · Have used AI: 62%First yearThird year · Have used AI: 80%Third year
Chart comparing AI usage proportions in two years of study
+18.0 (percentage points) Third year − first year
260 people Current total survey count

How should we interpret this?

The current usage proportion is 62.0% for first-year students and 80.0% for third-year students. The sample difference in percentage points is 18.0. This is a descriptive finding; it does not yet justify saying that the populations “differ significantly.”

The same difference in proportions may lead to different statistical decisions at different sample sizes. To answer “Could this difference simply reflect sampling variability?”, we need the chi-square test of independence introduced next.

Next lesson: Assuming the variables are independent, how do we calculate the expected count E for each cell? How far do observed counts O differ from expected counts E, and why does this produce a χ² statistic?

Even a significant χ² test does not by itself establish that year of study causes differences in AI tool use.