AP Statistics · Exploring two-variable data
Two-way tables
1Organising two categorical variables
A two-way table shows counts for two categorical variables at once: one variable for rows, one for columns.
400 students are asked about their grade level and whether they play a sport.
- Grade 9: sport 60, no sport 40 (total 100).
- Grade 10: sport 70, no sport 80 (total 150).
- Grade 11: sport 50, no sport 100 (total 150).
- Totals: sport 180, no sport 220, overall 400.
(Lessons here list tables as rows; on the exam you will see a grid.)
Check yourself
In the table above, how many students are in Grade 10 and do not play a sport?
Show the answer
80
Row Grade 10, column no sport.
2Marginal and joint relative frequencies
- Marginal relative frequency: a row or column total divided by the grand total. Example: proportion who play sport $= \frac{180}{400} = 0.45$.
- Joint relative frequency: one cell divided by the grand total. Example: Grade 9 and sport $= \frac{60}{400} = 0.15$.
Check yourself
What proportion of all students are in Grade 11?
Show the answer
0.375
150/400.
3Conditional relative frequencies
A conditional relative frequency restricts attention to one row or column:
- Among Grade 9 students, proportion who play sport $= \frac{60}{100} = 0.60$.
- Among Grade 10: $\frac{70}{150} \approx 0.47$. Among Grade 11: $\frac{50}{150} \approx 0.33$.
Conditional distributions are what you compare to look for an association.
A segmented bar chart compares conditional distributions across groups
Association: two variables are associated if knowing the value of one changes the distribution of the other. Here the proportion playing sport falls with grade level (60%, 47%, 33%), so grade level and sport participation are associated.
If the conditional distributions were the same for every grade, there would be no association.
Check yourself
Of sport players, what proportion are in Grade 9?
Show the answer
1/3
60/180.
4Displaying two-way data
- Side-by-side bar chart: bars for each combination, grouped by one variable.
- Segmented (stacked) bar chart: each bar represents 100% of one group, divided into segments by the other variable. Ideal for comparing conditional distributions.
- Mosaic plot: like a segmented bar chart, but bar widths show group sizes too.
Check yourself
Which graph best compares conditional distributions across groups of different sizes?
Show the answer
Segmented bar chart with each bar scaled to 100%
Percentages within each group.
5Going deeper: marginal, joint and conditional distributions, and Simpson's paradox
A two-way table shows counts for two categorical variables on the same individuals.
Worked example (used throughout): 300 students were classified by sex and by whether they play a school sport.
- Female: 60 play, 90 do not: 150.
- Male: 80 play, 70 do not: 150.
- Totals: 140 play, 160 do not: 300.
Three kinds of proportion
Marginal relative frequency: a row or column total divided by the grand total. It describes one variable alone.
- Proportion who play a sport: 140 ÷ 300 = 46.7%.
Joint relative frequency: one cell divided by the grand total.
- Proportion who are female and play: 60 ÷ 300 = 20%.
Conditional relative frequency: one cell divided by its row or column total. It describes one variable within a category of the other.
- Among females, the proportion who play: 60 ÷ 150 = 40%.
- Among males: 80 ÷ 150 = 53.3%.
- Among those who play, the proportion who are female: 60 ÷ 140 = 42.9%.
Read the question for the denominator. "What percent of females play?" divides by the number of females. "What percent of players are female?" divides by the number of players. The words "of," "among" and "given" name the group that goes on the bottom.
Association: two categorical variables are associated if knowing the value of one helps to predict the other, that is, if the conditional distributions differ between groups.
- Here 40% of females and 53.3% of males play a sport. The percentages differ, so there is an association between sex and playing a sport in this sample.
- If the conditional distributions were the same for every group, there would be no association (the variables would be independent).
- Whether the association is statistically significant needs a chi-square test.
Which variable to condition on? Usually compare the distribution of the response variable across the categories of the explanatory variable.
Graphs: segmented bar graphs (each bar totals 100%) and side-by-side bar graphs show conditional distributions; a mosaic plot also shows the group sizes by the widths of the bars. Similar-looking segments across the bars mean little or no association.
Association is not causation. A lurking variable may be responsible.
Simpson's paradox: an association that holds within each of several groups can reverse when the groups are combined.
Worked example (a classic medical study): two treatments, A and B, for kidney stones.
- Small stones: A succeeded in 81 of 87 (93%); B in 234 of 270 (87%).
- Large stones: A succeeded in 192 of 263 (73%); B in 55 of 80 (69%).
- All patients: A succeeded in 273 of 350 (78%); B in 289 of 350 (83%).
- A is better for small stones and better for large stones.
- Yet B appears better overall.
- Explanation: stone size is a lurking variable. Treatment A was given mostly to patients with large stones, which are harder to treat whatever the method; B was given mostly to the easy cases.
- The combined figures compare unlike groups. The conclusion from the separate tables (A is better) is the sound one.
The lesson: before trusting a comparison of overall percentages, ask whether the groups differ in some other important way.
Probability language: the same table gives probabilities for a randomly chosen student. P(plays) = 0.467 is marginal; P(female and plays) = 0.20 is joint; P(plays | female) = 0.40 is conditional.
Common mistakes
- Using the grand total as the denominator for a conditional proportion.
- Confusing "percent of females who play" with "percent of players who are female."
- Claiming an association from counts without comparing percentages.
- Claiming no association because two counts are equal.
- Inferring cause from an association.
Check yourself
In a two-way table, 45 of the 120 students who study French also study music. The value 45 ÷ 120 is:
Show the answer
A conditional relative frequency
The denominator is the total for one category (French students), not the grand total.
6For top marks
- Be precise: "of the Grade 9 students, 60% play a sport" (conditional) is different from "60 students are Grade 9 sport players" (joint count).
- Compare conditional relative frequencies to decide on association; quote them.
- Association does not prove causation.
- Make sure the denominator matches the "given" group.
"Since 60% of Grade 9 students but only 33% of Grade 11 students play a sport, there is an association between grade level and sport participation in this sample."
Check yourself
P(sport | Grade 11) uses which denominator?
Show the answer
The Grade 11 total, 150
Condition on Grade 11.
Now test yourself
This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.
Practise in Impera