Difficulty: Introductory | Prerequisites: Part 1 notes (frequency tables, proportions, bar graphs).
The previous set of notes covered summarising a single categorical variable. This picks up the next step: what happens when you have two categorical variables measured on the same individuals and want to know whether (and how) they are related. Two-way tables are the workhorse for this, and you will use them again when you reach chi-square tests later in the course. If you are comfortable with frequency tables and proportions from Part 1, you are ready for this material.
A two-way table (contingency table) cross-tabulates two categorical variables so you can see how often each combination occurs. You can express the cell counts as percentages of the grand total, of each row total, or of each column total, and each version answers a different question. Comparing conditional proportions across groups (the "difference in proportions") is the key numerical summary; side-by-side and segmented bar charts are the key visual summaries.
Two-way table (contingency table)
A table with rows for one categorical variable and columns for another. Each cell shows the count (or proportion) of observations that fall in that particular row-column combination. If one variable has m categories and the other has n categories, the table is m x n.
Think of it as a grid that answers "how many are in group A and group B at the same time?".
Marginal totals (marginals)
The row totals and column totals that sit along the edges (margins) of the two-way table. Each marginal total is the sum of counts in its row or column.
In simple terms, this means: marginals tell you the overall distribution of each variable on its own, ignoring the other variable.
Grand total
The total count of all observations in the table. It equals the sum of any complete set of marginals (all row totals, or all column totals).
Joint proportion (percentage of grand total)
A cell count divided by the grand total. It tells you what fraction of all observations fall in that specific combination.
Conditional proportion (row percentage or column percentage)
A cell count divided by its row total (row percentage) or its column total (column percentage). It answers "among those in this particular row (or column), what proportion fall in this cell?".
In simple terms, this means: you are zooming in on one group and asking about the breakdown within that group.
Difference in proportions
The subtraction of one group's conditional proportion from another group's conditional proportion for the same category. Notated as p̂₁ – p̂₂.
Think of it as a single number that captures how much two groups differ on a particular outcome.
Side-by-side bar chart (clustered bar chart)
A bar graph where each category has a cluster of bars placed next to each other, one bar per group, making it easy to compare group sizes within each category.
Segmented bar chart (stacked bar chart)
A bar graph where the bars for each group are stacked on top of one another rather than placed side by side. Shows both the total and the composition at a glance.
To study the relationship between two categorical variables, you must observe both variables on the same individuals.
Example (Gender and Information Source, n = 20 students): each student reported their gender (Male / Female) and their preferred news source (TV / Radio / Newspaper / Internet).
The raw data is a list of 20 rows. To make sense of it, you build a 2 x 4 contingency table:
Rows: Male, Female
Columns: TV, Radio, Newspaper, Internet
Each cell: the number of students in that row-column combination
It does not matter which variable goes in the rows and which in the columns. The analysis works either way.
Once you have the frequency table, there are three ways to turn the counts into percentages, and each answers a different question.
Percentages of the grand total (joint proportions)
Divide every cell by the grand total (20 in the example) and multiply by 100.
Example: Male + TV = 4/20 = 20%. This means 20% of all students are male and prefer TV.
The entire table sums to 100%.
Percentages of the row totals (row conditional proportions)
Divide each cell by its row total.
Example: Male + TV = 4/10 = 40%. This means 40% of male students prefer TV.
Each row sums to 100%.
Percentages of the column totals (column conditional proportions)
Divide each cell by its column total.
Example: Male + TV = 4/5 = 80%. This means 80% of TV-preferring students are male.
Each column sums to 100%.
This is the single most important (and most tested) concept in this section.
Three questions that sound similar but have different answers:
"What proportion of students are male and prefer TV?" = joint proportion = cell / grand total = 4/20 = 20%.
"What proportion of male students prefer TV?" = row conditional = cell / row total = 4/10 = 40%.
"What proportion of TV-preferring students are male?" = column conditional = cell / column total = 4/5 = 80%.
The denominators differ: grand total vs. row total vs. column total. The wording tells you which denominator to use.
"of [group]" means condition on that group, so divide by that group's total.
"[group A] and [group B]" with no conditioning language means divide by the grand total.
The difference in proportions compares how two groups differ on a single outcome.
Formula: p̂₁ – p̂₂, where each p̂ is a conditional proportion.
Example: difference in the proportion preferring TV between males and females:
p̂(Male, TV) = 4/10 = 0.40
p̂(Female, TV) = 1/10 = 0.10
Difference = 0.40 – 0.10 = 0.30, or 30 percentage points.
Interpretation: males were 30 percentage points more likely to prefer TV than females in this sample.
The sign depends on the order of subtraction. Always state which group is listed first.
Side-by-side bar chart
For each category of one variable, you place a cluster of bars next to each other, one bar per level of the other variable.
Good for comparing the size of each group within a category at a glance.
Segmented bar chart (stacked bar chart)
Same idea, but the bars are stacked on top of one another instead of placed side by side.
Good for seeing both the total for each category and how it breaks down by group.
Both chart types are used for two categorical variables. Choose side-by-side when the priority is comparing individual group sizes; choose segmented when the priority is seeing part-to-whole composition.
Joint proportion: cell count / grand total
Row conditional proportion: cell count / row total
Column conditional proportion: cell count / column total
Difference in proportions: p̂₁ – p̂₂ (each is a conditional proportion from the row or column percentage table)
Marginal total (row): sum of all cells in that row
Marginal total (column): sum of all cells in that column
Grand total: sum of all cells, or sum of all row marginals, or sum of all column marginals
Two-way tables appear whenever someone wants to know whether two categorical traits are associated. Medical researchers cross-tabulate treatment group and outcome (recovered / not recovered). Political pollsters cross-tabulate party affiliation and preferred news network (the exercise in this lecture is exactly that scenario). Retailers cross-tabulate customer segment and purchase category. The difference in proportions is the first step toward answering "do these groups behave differently?", which is the question that formal hypothesis testing will later make rigorous.
Confusing "proportion of A who are B" with "proportion of B who are A." These use different denominators and almost always give different numbers. (40% of males prefer TV is not 80% of TV-preferring students being male.)
Confusing a joint proportion with a conditional proportion. "20% of all students are male and prefer TV" is not the same statement as "40% of male students prefer TV." The first uses the grand total as denominator; the second uses the row total.
Assuming that if two variables appear in the same table, they must be associated. A two-way table can also show no association (when the conditional proportions are roughly the same across rows).
Misreading marginal totals as cell counts. The row and column totals sit at the edges of the table, not inside it.
⚠️ You will almost certainly be given a two-way table and asked to compute a specific proportion. Read the wording carefully to decide whether it calls for a joint, row-conditional, or column-conditional proportion.
⚠️ Be prepared for "caution" questions that test whether you understand that "proportion of A who are B" differs from "proportion of B who are A."
⚠️ Know how to compute and interpret a difference in proportions, including stating the direction (which group is higher) and the magnitude.
⚠️ Know the difference between a side-by-side bar chart and a segmented bar chart, and when each is appropriate.
⚠️ The practice exercise (political party and news network) is representative of exam-level complexity: compute the grand total, identify marginals, find conditional proportions, and calculate differences.
True or false: in a two-way table, it does not matter which variable is in the rows and which is in the columns.
Fill in the blank: the row totals and column totals are called ___.
True or false: "the proportion of female students who prefer Internet" and "the proportion of Internet-preferring students who are female" are the same number.
True or false: a segmented bar chart stacks bars on top of one another.
Fill in the blank: the difference in proportions is calculated as p̂₁ ___ p̂₂.
Q: Using the political-party / news-network exercise table (Democrat: ABC 200, CBS 200, NBC 250, PBS 150; Republican: ABC 450, CBS 350, NBC 500, PBS 200; Other: ABC 150, CBS 400, NBC 100, PBS 50), how many viewers were surveyed in total?
A: 200 + 200 + 250 + 150 + 450 + 350 + 500 + 200 + 150 + 400 + 100 + 50 = 3,000.
Q: How many viewers preferred to watch CBS?
A: 200 + 350 + 400 = 950.
Q: What percentage of the survey respondents were Republican?
A: Republican total = 450 + 350 + 500 + 200 = 1,500. Percentage = 1,500 / 3,000 = 50%.
Q: What percentage of Democrats preferred ABC?
A: Democrat total = 200 + 200 + 250 + 150 = 800. Percentage = 200 / 800 = 25%.
Q: What is the difference in ABC preference percentages between Democrats and Republicans?
A: Democrats preferring ABC = 200/800 = 25%. Republicans preferring ABC = 450/1,500 = 30%. Difference = 25% – 30% = –5 percentage points (Republicans are 5 points higher).
Two-way tables are the descriptive foundation for the chi-square test of independence, which you will encounter later in the course. That test formalises the question "is there a statistically significant association between these two variables?" by comparing observed cell counts to expected counts under the assumption of no association. The difference in proportions also reappears in inference: constructing confidence intervals and running hypothesis tests for two proportions (p̂₁ – p̂₂) relies on the same calculation you practised here.
two-way table, contingency table, cross-tabulation, crosstab, marginal totals, marginals, grand total, joint proportion, conditional proportion, row percentage, column percentage, difference in proportions, side-by-side bar chart, clustered bar chart, segmented bar chart, stacked bar chart, bivariate categorical data, association between categorical variables, STA 270, intro statistics, chi-square preview, comparing groups