Sub topic 2
The Interquartile Range
This chapter assumes you can order a list of numbers, find a median, and work with decimals and percents.
The Interquartile Range
The interquartile range (IQR) is the distance between the first quartile (Q1) and the third quartile (Q3). It measures the spread of the middle half of the data:
IQR = Q3 - Q1
The range uses the largest and smallest values, so one extreme value can change it a lot. The IQR ignores the outer quarters, so it changes much less.
The Five-Number Summary
The five-number summary lists the minimum, Q1, the median (Q2), Q3, and the maximum, in that order. A boxplot draws these five values. The box spans Q1 to Q3, a line inside the box marks the median, and the whiskers reach toward the minimum and maximum.
The following Python function computes the quartiles and the IQR:
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:] # skip the middle value when n is odd
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.0Percentiles: What They Mean
A percentile is a value below which a given percent of the data falls. The 90th percentile is the value that 90 percent of the data is at or below. Q1 is the 25th percentile, the median is the 50th, and Q3 is the 75th.
Finding and Interpreting a Percentile Rank
A percentile rank tells you where one value sits in the data. Count the values at or below it, then divide by the total:
percentile rank = (count at or below x / total count) × 100
For the data above, 13 has 6 of 9 values at or below it, so its percentile rank is 6/9 × 100 ≈ 66.7. You can say that 13 is at about the 67th percentile.
Exercise
For the data set [3, 5, 7, 8, 12, 13, 14, 18, 21], what is the percentile rank of 18?
Show answer
Eight of the nine values are at or below 18, so the rank is 8/9 × 100 ≈ 88.9, or about the 89th percentile.