Sub topic 3
Reading a Boxplot
This chapter assumes you can order numbers, find a median, and read a labeled axis. Every example uses the data set 3, 5, 7, 8, 12, 13, 14, 18, 21.
Reading a Boxplot
A boxplot shows five values: the minimum, Q1, the median (Q2), Q3, and the maximum. The box runs from Q1 to Q3, a line inside the box marks the median, and whiskers extend toward the smallest and largest values.
Each section of the plot does not hold the same amount of data. Only the quartile positions are fixed, so the number of values between two marks can differ.
Drawing a Boxplot from Data
The quartile values come from the sorted list. This function returns Q1, Q2, and Q3:
def median(values):
n = len(values)
mid = n // 2
if n % 2 == 1:
return values[mid]
return (values[mid - 1] + values[mid]) / 2
def quartiles(data):
s = sorted(data)
half = len(s) // 2
lower = s[:half]
upper = s[half + len(s) % 2:]
return median(lower), median(s), median(upper)
data = [3, 5, 7, 8, 12, 13, 14, 18, 21]
q1, q2, q3 = quartiles(data)
print(q1, q2, q3) # 6.0 12 16.0
print(q3 - q1) # 10.0 (the IQR)Outliers and the 1.5 x IQR Rule
Under the common convention, a value is an outlier when it falls below Q1 - 1.5 x IQR or above Q3 + 1.5 x IQR. For the data above, the fences are -9 and 31. No value lies outside them, so none is flagged.
Comparing Two Boxplots
Compare distributions with the median, the IQR, and the range.
| Measure | Set A | Set B |
|---|---|---|
| Median | 12 | 14 |
| IQR | 10 | 5 |
| Range | 18 | 8 |
Set B is centered higher, and its middle half is more tightly grouped.
GRE Strategies and Common Pitfalls
- A quartile is a data value, not a percent. Q3 = 16 means the third quartile is 16.
- Do not assume each box section holds the same number of values.
- Check whether a question gives the outlier rule before applying it.
Exercise
For Set B (10, 11, 12, 13, 14, 15, 16, 17, 18), what is the IQR?
Show answer
Q1 = 11.5 and Q3 = 16.5, so the IQR is 5.