Comparing groups with box plots · Statistics & Data… | StemPy Lab
Course 2.2·Lesson 3 of 3
Comparing groups with box plots
Side-by-side box plots compare two or more groups at a glance: their centres, their spreads, their shapes and their outliers. This lesson shows how to read and write such a comparison, how to say how much the groups overlap, and what a box plot cannot show.
about 25 min1 simulation1 practice question
Lesson 3 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
compare groups by their medians, IQRs, ranges, shapes and outliers;
describe how much two groups overlap from their quartiles;
explain what a box plot hides, and when to draw a histogram as well.
Plants with and without fertiliser
A school garden club grows 26 bean plants in a made-up trial. Thirteen get fertiliser and 13 do not. After four weeks the club measures each plant, in cm.
Without fertiliser: 14,16,17,18,19, 19,20,21,22,22, 23,25,31.
With fertiliser: 17,20,22,23,24, 25,26,26,27,28, 30,31,33.
The five-number summaries are 14, 17.5, 20, 22.5 and 31 cm without fertiliser, and 17, 22.5, 26, 29 and 33 cm with it. Without fertiliser, the upper fence is 22.5+1.5×5=30 cm, so the plant of 31 cm is an outlier.
Side-by-side box plots of the heights of plants after four weeks, on one axis from 10 to 36 centimetres. The lower box plot, without fertiliser, has a box from 17.5 to 22.5, a median of 20, whiskers from 14 to 25, and a red cross for an outlier at 31. The upper box plot, with fertiliser, has a box from 22.5 to 29, a median of 26, and whiskers from 17 to 33.
How to compare
Compare the groups on four things, and always in the context of the data.
Centre. The median with fertiliser is 26 cm, against 20 cm without. Typically, fertilised plants were about 6 cm taller.
Spread. The IQRs are 6.5 cm with fertiliser and 5 cm without, so the fertilised plants varied a little more.
Shape. Without fertiliser, the box and the whiskers are fairly balanced around the median. With fertiliser, the median sits a little left of the middle of its box.
Unusual values. One unfertilised plant, at 31 cm, is an outlier. It might be worth checking that it got no fertiliser by mistake.
How much do the groups overlap?
The quartiles let you make careful statements about overlap.
The median with fertiliser, 26 cm, is above Q3 without fertiliser, 22.5 cm. So at least half of the fertilised plants were taller than about three quarters of the unfertilised plants.
The two boxes just touch: Q3 without fertiliser and Q1 with it are both 22.5 cm. The whiskers overlap a lot. Some plants without fertiliser were taller than some plants with it.
So the fertiliser group did better as a group, but not plant by plant. This trial is also small. You can learn how to test whether a difference this large could be luck in the last chapter of this collection.
What a box plot hides
A box plot shows only five numbers. Two very different data sets can share them. Look at the two data sets below. Each has 20 values with the same five-number summary: 0, 10, 20, 30 and 40. Set A is roughly flat. Set B has two humps and no values at all between 14 and 26. Their box plots are identical.
Two histograms with their box plots underneath. On the left, data set A has 20 values spread fairly evenly from 0 to 40, with bars of 1 to 3 values each. On the right, data set B has 20 values in two clusters, one from 0 to 15 and one from 25 to 40, with empty bins between 15 and 25. The two box plots underneath are identical: a box from 10 to 30, a median of 20, and whiskers from 0 to 40.
So use box plots to compare groups quickly, and draw a histogram as well when the shape matters. A box plot never shows two peaks or a gap inside the box.
You should find that the orange median sits above the blue Q3 once the shift is more than 2.5 cm. With no shift and a stretch of 1, the two box plots lie on top of each other. A stretch of 2 doubles the orange IQR to 10 cm.
Practise with new numbers
Try it in Python
The program prints the five-number summary of each group with the rule of this chapter, and then draws side-by-side box plots with matplotlib.
Common mistakes
Comparing only the medians. Say something about spread and shape too.
Saying "every plant with fertiliser was taller". Box plots compare groups, not individuals; check the overlap.
Comparing groups on different scales. Draw box plots on one shared axis.
Trusting a box plot for shape. It cannot show two peaks or gaps; draw a histogram.
Remember these
Compare centre (medians), spread (IQRs), shape and outliers, in the context of the data.
If one median is above the other group's Q3, at least half of one group beats about three quarters of the other.
Box plots on one axis make comparison easy, but they hide the detailed shape.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Group P has median 48 and IQR 10. Group Q has median 55 and IQR 22. Compare the centres and the spreads.
The median of group Y equals Q1 of group X. About what share of group X lies above the median of Y?
Two classes have identical box plots. Must their histograms look the same?