Sub topic 4
Quartiles: Splitting the Data into Four Parts
Assume you know how to order a data set and find its median. Quartiles extend the idea of a median by dividing an ordered data set into four sections. They help describe where the data is concentrated and how widely it is spread.
The Three Quartiles
The three quartiles are:
- Q1, the first quartile, marks the middle of the lower half of the data.
- Q2, the second quartile, is the median of the entire data set.
- Q3, the third quartile, marks the middle of the upper half of the data.
The quartiles do not necessarily divide the numerical distance into four equal lengths. They divide the ordered observations into four groups containing approximately equal numbers of data values.
Consider the ordered data set:
3, 5, 7, 8, 12, 13, 14, 18, 21There are nine values. The middle value is 12, so:
- Q2 = 12
- The lower half is 3, 5, 7, 8
- The upper half is 13, 14, 18, 21
Find the median of each half:
- Q1 = (5 + 7) / 2 = 6
- Q3 = (14 + 18) / 2 = 16
Therefore, the quartiles are:
| Quartile | Value | Meaning |
|---|---|---|
| Q1 | 6 | Middle of the lower half |
| Q2 | 12 | Middle of the entire data set |
| Q3 | 16 | Middle of the upper half |
The first quarter of the observations is at or below Q1, about half are at or below Q2, and three quarters are at or below Q3.
A Reliable Procedure
For a small data set, use this procedure:
- Sort the values from least to greatest.
- Find the median of the entire data set. This is Q2.
- If the number of values is odd, leave Q2 out of both halves.
- Find the median of the lower half. This is Q1.
- Find the median of the upper half. This is Q3.
If a half has an even number of values, average its two middle values. If a half has an odd number of values, use its single middle value.
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):
values = sorted(data)
half = len(values) // 2
lower = values[:half]
upper = values[half + len(values) % 2:]
return median(lower), median(values), median(upper)
data = [3, 5, 7, 8, 12, 13, 14, 18, 21]
q1, q2, q3 = quartiles(data)
print(q1, q2, q3)This program prints:
6.0 12 16.0Different textbooks and software may use slightly different conventions for quartiles, especially when the number of observations is even. On the GRE, use the definition given in the problem. If no special definition is given, the lower-half and upper-half method is a common approach.
Common Errors
Do not treat Q1 as the first data value or Q3 as the third data value. Quartile numbers identify positions in the distribution, not positions in the written list.
Do not include the overall median in both halves when the data set has an odd number of values. Doing so changes Q1 and Q3.
Also, a quartile is not the same as a percent. Q1 is a value in the same units as the data, while 25% is a proportion. For the example, Q1 is 6, not 25%.
Exercise
Find Q1, Q2, and Q3 for the ordered data set 2, 4, 6, 9, 11, 15, 20.
Show answer
Q2 = 9. Excluding 9, the lower half is 2, 4, 6, so Q1 = 4. The upper half is 11, 15, 20, so Q3 = 15.