Sub topic 4
Quartiles: Splitting the Data into Four Parts
This chapter assumes you can sort numbers from least to greatest, find the median of a short list, and do basic arithmetic with fractions and decimals. The previous chapters covered ordering data and the median. Quartiles reuse the median several times, so that skill is the foundation here.
What a quartile is
A quartile is a value that cuts an ordered data set into four parts that each hold about the same number of data points. Three cut points are needed to make four parts:
- Q1, the first (lower) quartile, has about 25% of the data at or below it.
- Q2, the second quartile, is the median. About 50% of the data is at or below it.
- Q3, the third (upper) quartile, has about 75% of the data at or below it.
A quartile is a value from the number line, in the same units as the data. It is not a count and not a percent. If a data set is test scores, Q1 is a score, such as 72 points.
Each quarter holds about the same number of data points. The quarters do not have the same width on the number line. A quarter where the values are packed closely together covers a short stretch of the line. A quarter where the values are scattered covers a long stretch. This difference matters a great deal when you read boxplots later.
The median-of-halves method
The standard classroom procedure, and the one GRE problems assume, uses only the median:
- Sort the data from least to greatest.
- Find the median of the whole list. This is Q2.
- Split the list into a lower half and an upper half at the median.
- Find the median of the lower half. This is Q1.
- Find the median of the upper half. This is Q3.
The only decision is what to do with the middle value when the list has an odd number of entries. In this method, you leave it out of both halves. When the list has an even number of entries, the median falls between two values, and every value belongs to exactly one half.
Worked example: an odd number of values
Take the nine values 3, 5, 7, 8, 12, 13, 14, 18, 21. They are already sorted.
- The median is the 5th value, 12. So Q2 = 12.
- Leave 12 out. The lower half is 3, 5, 7, 8. Its median is (5 + 7) / 2 = 6. So Q1 = 6.
- The upper half is 13, 14, 18, 21. Its median is (14 + 18) / 2 = 16. So Q3 = 16.
The following program does the same steps. The quartiles function sorts first, so you can pass it an unsorted list.
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.0The slice s[half + len(s) % 2:] is the key line. When the length is odd, len(s) % 2 is 1, so the upper half starts one position later and skips the middle value. When the length is even, it adds 0 and nothing is skipped.
Worked example: an even number of values
Take 2, 4, 6, 8, 10, 12. There are six values.
- The median falls between 6 and 8, so Q2 = (6 + 8) / 2 = 7. The value 7 is not in the list. That is fine.
- The lower half is 2, 4, 6, with median 4. So Q1 = 4.
- The upper half is 8, 10, 12, with median 10. So Q3 = 10.
Here each half has an odd number of values, so its median is a value from the list. With eight values, each half has four values, and Q1 and Q3 are averages of two neighbors. The table shows how the sizes work out.
| Number of values n | Middle value left out? | Size of each half | Q1 is the median of |
|---|---|---|---|
| 6 | No | 3 | the 3 smallest values |
| 7 | Yes | 3 | the 3 smallest values |
| 8 | No | 4 | the 4 smallest values |
| 9 | Yes | 4 | the 4 smallest values |
Repeated values and non-integer results
Repeated values are separate data points. Never merge them. Consider 2, 2, 3, 3, 3, 5, 9, 9, which has eight values.
- Q2 = (3 + 3) / 2 = 3.
- The lower half is 2, 2, 3, 3, so Q1 = (2 + 3) / 2 = 2.5.
- The upper half is 3, 5, 9, 9, so Q3 = (5 + 9) / 2 = 7.
You can check this with the earlier code.
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)
print(quartiles([2, 2, 3, 3, 3, 5, 9, 9])) # (2.5, 3.0, 7.0)
print(quartiles([2, 4, 6, 8, 10, 12])) # (4, 7.0, 10)A quartile can therefore be a number that does not appear in the data, such as 2.5 above. Do not round it to a nearby data value.
Quartiles and the spread of the data
Quartiles give you more than a center. The distance from Q1 to Q3 shows how widely the middle half of the data is spread. For the nine-value example, Q3 − Q1 = 16 − 6 = 10. This distance is the interquartile range, which the next chapter develops. For now, notice that it ignores the lowest quarter and the highest quarter, so a single extreme value cannot change it much. The range, which is the maximum minus the minimum, can be changed greatly by one extreme value.
You can also use the quartiles to see how the data is arranged. In the example, the gaps between the cut points are 12 − 6 = 6 and 16 − 12 = 4. Both quarters of the middle half hold the same number of values, but they cover different stretches of the number line. The lower-middle quarter is longer, so the values there are sparser.
Common errors
- Forgetting to sort. Quartiles are positions in the ordered list. If you split the list as given, the result is meaningless.
- Including the median in both halves when n is odd. In the nine-value example, keeping 12 in both halves would give Q1 = 7 and Q3 = 14, which are different answers. Some textbooks and software do use that variant, and others interpolate between values, so tools can disagree. A well-formed GRE problem either states the method, supplies the quartiles directly, or is built so that the answer does not depend on the method. When you must compute, use the median-of-halves method described here.
- Treating a quartile as a percent. "Q3 = 40" does not mean 40% of the data. It means about 75% of the data is at or below the value 40.
- Confusing "the first quartile" with "in the first quartile." The first quartile is the cut point Q1. A value "in the first quartile" lies in the lowest quarter of the data, at or below Q1.
- Assuming equal widths. Each quarter of the data holds about the same number of points. It does not span the same distance on the number line.
- Dropping the half-step. When a half has an even count, average the two middle values. The result may end in .5.
Putting it together
For a quartile question on the GRE, work through these steps in order:
- Sort the values, even if they look nearly ordered.
- Count them and decide whether n is odd or even.
- Find Q2.
- Split the list, leaving out the middle value if n is odd.
- Take the median of each half.
- Re-read what the question asks for. It may want a quartile, a difference such as Q3 − Q1, or a count of values above or below a quartile.
Exercise
Find Q1, Q2, and Q3 for the data 4, 9, 1, 7, 15, 11, 6. Then find Q3 − Q1.
Show answer
Sorted: 1, 4, 6, 7, 9, 11, 15. There are 7 values, so the median is the 4th value, Q2 = 7. Leave out 7. The lower half 1, 4, 6 has median 4, so Q1 = 4. The upper half 9, 11, 15 has median 11, so Q3 = 11. Q3 − Q1 = 11 − 4 = 7.
Exercise
Find Q1, Q2, and Q3 for 10, 12, 15, 18, 20, 22, 25, 31. Then find Q3 − Q1.
Show answer
There are 8 values, so Q2 = (18 + 20) / 2 = 19. The lower half 10, 12, 15, 18 has median (12 + 15) / 2 = 13.5, so Q1 = 13.5. The upper half 20, 22, 25, 31 has median (22 + 25) / 2 = 23.5, so Q3 = 23.5. Q3 − Q1 = 23.5 − 13.5 = 10.
Exercise
A data set of 40 values has Q3 = 62. Roughly how many values are greater than 62, and does Q3 = 62 mean that 62% of the values are below 62?
Show answer
About 10 values are greater than 62, because Q3 has about 75% of the 40 values (30 values) at or below it, and 40 − 30 = 10. No. Q3 is a value in the data's units, not a percent, so 62 is the cut point, not a percentage of the data.