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.
Adjust the survey data
| Year of study | Have used AI | Have not used AI | Total |
|---|---|---|---|
| First year | 62 | 38 | 100 |
| Third year | 128 | 32 | 160 |
| Grand total | 190 | 70 | 260 |
Each row represents a year of study, and each column represents AI use. Each cell counts people who meet both category conditions.
Plot the counts
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 study | Have used AI | Have not used AI | Total |
|---|---|---|---|
| First year | 62.0% | 38.0% | 100.0% |
| Third year | 80.0% | 20.0% | 100.0% |
| Grand total | 73.1% | 26.9% | 100.0% |
Within each year, the percentages for “Have used AI” and “Have not used AI” add up to 100%.
100% stacked bar chart
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.
| Year of study | Have used AI | Have not used AI | Total |
|---|---|---|---|
| First year | 62 | 38 | 100 |
| Third year | 128 | 32 | 160 |
| Grand total | 190 | 70 | 260 |
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
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
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.
Even a significant χ² test does not by itself establish that year of study causes differences in AI tool use.