Numerical and categorical variables: back-to-back stem plots, parallel dot plots and boxplots
Compare groups with boxplots, dot plots and back-to-back stem plots in Year 12 VCE General Mathematics. Do workers who drive into Melbourne really take longer than those who ride or catch the train? When a measurement is split into groups, putting the displays side by side on one scale shows at a glance whether the groups differ.
You will read and build each display, find medians, quartiles, IQRs and outliers using the fences, and decide whether the typical value changes from group to group. You will write clear sentences comparing centre and spread, choose the right display for two or more groups, and then move on to associations between two numerical variables on a scatterplot.
Theory
To see whether a numerical variable is associated with a categorical variable, compare its distribution across the categories. This Year 12 General Mathematics guide for students in Victoria shows how to read parallel boxplots, parallel dot plots and back-to-back stem plots, compare medians and spreads, and describe the association in context.
When the explanatory variable is categorical (such as way of travelling) and the response is numerical (such as commute time), we display the response separately for each category, on the same scale, and compare the groups. Three displays are used:
- a back-to-back stem plot, for exactly two groups: the stems run down the middle, one group’s leaves on each side (leaves on the left get larger moving away from the stem);
- parallel dot plots, one dot plot per group on a common scale;
- parallel boxplots, one boxplot per group, built from each group’s five-number summary (minimum, \(Q_1\), median, \(Q_3\), maximum), with any outliers plotted as separate points.
To describe the association, compare the centres (medians) and the spreads (IQR, or range) of the groups. If the medians differ clearly from one category to another, the variables are associated. If the medians are about the same, there is no association, even if the spreads differ.
A back-to-back stem plot of commute times for workers living in and out of a country town:
| In town | Out of town | |
|---|---|---|
| 8 | 0 | |
| 8 7 5 4 2 1 | 1 | 9 |
| 6 3 1 | 2 | 2 5 7 9 |
| 4 | 3 | 1 3 6 8 |
| 4 | 2 5 | |
| Key: 1 | 4 = 14 minutes | ||
Spread of each group:
Fences for outliers on a boxplot (a value beyond a fence is plotted as a separate point):
Median of \(n\) ordered values: the value in position
How to describe an association between a numerical and a categorical variable
- Identify the variables. The categorical variable is explanatory; the numerical variable is the response.
- Choose a display. Two groups: a back-to-back stem plot, parallel dot plots or parallel boxplots. Three or more groups: parallel dot plots or parallel boxplots (a back-to-back stem plot has only two sides).
- Find the medians (and the quartiles, IQR or range) of every group. For a boxplot, check the fences for outliers.
- Compare centres. Clearly different medians mean the variables are associated; similar medians mean no association.
- Compare spreads and write the conclusion in context, quoting the values: “Group A tended to be higher than group B (median \(a\) compared with \(b\)), and was more variable (IQR \(c\) compared with \(d\)).”
| In town | Out of town | |
|---|---|---|
| 8 | 0 | |
| 8 7 5 4 2 1 | 1 | 9 |
| 6 3 1 | 2 | 2 5 7 9 |
| 4 | 3 | 1 3 6 8 |
| 4 | 2 5 | |
| Key: 1 | 4 = 14 minutes | ||
With \(n = 11\), the median is the \(6\)th value. Read the left side from the stem outwards.
| \(\text{position}\) | \(=\) | \(\dfrac{11 + 1}{2}\) |
| \(\) | \(=\) | \(6\text{th value}\) |
| \(\text{median (in town)}\) | \(=\) | \(17\) |
| \(\text{median (out of town)}\) | \(=\) | \(31\) |
| \(\text{range (in town)}\) | \(=\) | \(34 - 8\) |
| \(\) | \(=\) | \(26\) |
| \(\text{range (out of town)}\) | \(=\) | \(45 - 19\) |
| \(\) | \(=\) | \(26\) |
(a) 17 and 31 minutes. (b) Both ranges are 26 minutes. (c) Yes. Workers living out of town tended to have longer commutes (median 31 minutes compared with 17), although the spreads are the same.
With \(n = 10\), the median is halfway between the \(5\)th and \(6\)th values.
| \(\text{median (morning)}\) | \(=\) | \(\dfrac{4 + 4}{2}\) |
| \(\) | \(=\) | \(4\) |
| \(\text{median (afternoon)}\) | \(=\) | \(\dfrac{2 + 2}{2}\) |
| \(\) | \(=\) | \(2\) |
(a) Morning 4, afternoon 2 snapper. (b) The catch is associated with the session: morning trips tended to catch more snapper (median 4 compared with 2). Both groups have a range of \(5\).
Stop A: 3, 4, 4, 5, 6, 6, 7, 8, 9, 18
Stop B: 5, 7, 8, 9, 10, 11, 12, 13, 14, 15
Split the \(10\) ordered values into a lower half and an upper half of \(5\) each; the quartiles are their medians.
| \(\text{median}\) | \(=\) | \(\dfrac{6 + 6}{2}\) |
| \(\) | \(=\) | \(6\) |
| \(Q_1\) | \(=\) | \(\text{median of } 3, 4, 4, 5, 6\) |
| \(\) | \(=\) | \(4\) |
| \(Q_3\) | \(=\) | \(\text{median of } 6, 7, 8, 9, 18\) |
| \(\) | \(=\) | \(8\) |
| \(\text{IQR}\) | \(=\) | \(8 - 4\) |
| \(\) | \(=\) | \(4\) |
| \(\text{upper fence}\) | \(=\) | \(8 + 1.5 \times 4\) |
| \(\) | \(=\) | \(14\) |
(a) Min \(3\), \(Q_1 = 4\), median \(6\), \(Q_3 = 8\), max \(18\). (b) \(18 > 14\), so \(18\) is an outlier: it is drawn as a separate point and the whisker stops at \(9\). (c) Stop B tended to have longer waits (median \(10.5\) minutes compared with \(6\)), and its middle \(50\%\) of waits were a little more spread out (IQR \(5\) compared with \(4\)).
Read the median (line in the box) and the box ends (\(Q_1\) and \(Q_3\)) for each year level.
| \(\text{IQR (Year 8)}\) | \(=\) | \(15 - 9\) |
| \(\) | \(=\) | \(6\) |
| \(\text{IQR (Year 10)}\) | \(=\) | \(20 - 13\) |
| \(\) | \(=\) | \(7\) |
| \(\text{IQR (Year 12)}\) | \(=\) | \(27 - 17\) |
| \(\) | \(=\) | \(10\) |
| \(17 = Q_1 \text{ (Year 12)}\) | \(\Rightarrow\) | \(75\% \text{ above}\) |
(a) Medians \(12\), \(16\) and \(22\) hours; IQRs \(6\), \(7\) and \(10\) hours. (b) 75%. (c) Study time is associated with year level: the median rises from \(12\) to \(16\) to \(22\) hours as year level increases, and study times also become more variable (IQR \(6\) up to \(10\)).
Common pitfalls
Frequently asked questions
How do you compare two boxplots?
Compare the medians first: if they differ clearly, the variables are associated. Then compare the spreads using the IQRs or ranges, and mention any outliers. Quote the values in a sentence in context.
When should you use a back-to-back stem plot?
Use it when a numerical variable is compared across exactly two groups. For three or more groups use parallel boxplots or parallel dot plots.
How do you read the left side of a back-to-back stem plot?
The stem is in the middle and the left leaves increase moving away from the stem. A leaf of 4 on the left of stem 1 means 14.
How do you know if there is an association between a numerical and a categorical variable?
Look at the medians of the groups. If the median changes noticeably from one category to another, the variables are associated. If the medians are about the same, there is no association.
How do you find an outlier on a boxplot?
Work out the fences Q1 - 1.5 x IQR and Q3 + 1.5 x IQR. Any value below the lower fence or above the upper fence is an outlier and is plotted as a separate point.
What percentage of data lies above the first quartile?
About 75%. Each quartile marks off a quarter of the data, so 25% lies below Q1 and 75% lies above it.