Unit 06.02: Box plots, and what they hide
Box plots compare many groups compactly and cannot show shape.
Identical summaries, different distributions
A unimodal and a bimodal distribution with nearly identical quartiles.
The code reports the five-number summary of each.
import numpy as np
rng = np.random.default_rng(2)
unimodal = rng.normal(50, 10, 300)
bimodal = np.concatenate([rng.normal(35, 5, 150), rng.normal(65, 5, 150)])
print(f"{'group':>10} {'Q1':>7} {'median':>8} {'Q3':>7} {'IQR':>7}")
for name, data in [("unimodal", unimodal), ("bimodal", bimodal)]:
q1, med, q3 = np.percentile(data, [25, 50, 75])
print(f"{name:>10} {q1:>7.1f} {med:>8.1f} {q3:>7.1f} {q3 - q1:>7.1f}")
print("""
Two very different distributions with nearly identical five-number summaries.
A box plot of each would look the same, and one of them is two populations.
Box plots are excellent for comparing many groups at once and they cannot show
shape. Overlay the points, or use a violin, when shape is the question.
""")
The quartiles match closely, so the two box plots would look nearly identical - and one of them is two separate populations.
That is the trade box plots make. They are excellent for comparing the level and spread of many groups at once, and blind to everything between the quartiles.
The mistake this prevents
The mistake is using a box plot when shape is the question. Overlay the individual points, or use a violin plot, whenever the number of groups is small enough to allow it.
Takeaway
Box plots compare level and spread across many groups and hide shape. Overlay points or use a violin when shape matters.
