Sub topic 1
Start by Ordering the Data
Every measure in this tutorial depends on position in a sorted list. The median, the quartiles, percentiles, and the ends of a boxplot all answer the question "what value sits at this place in the ordered data?" If the list is not sorted, those questions have no answer. This chapter covers how to order data reliably, what to check afterward, and which mistakes cause wrong answers before any statistic is computed.
Prerequisites
This chapter assumes you can do the following:
- Do arithmetic with fractions, decimals, and percents, including converting between them.
- Order numbers from least to greatest, including negatives.
- Compute the mean and median of a short list.
- Read a number line and a labeled axis.
The Python snippets are optional. They check your hand work and show the same steps in code, and each one runs as written.
Why order comes first
Some statistics ignore order. The mean is the sum divided by the count, so shuffling the list never changes it. Position-based statistics behave differently:
| Statistic | Needs sorted data? | Why |
|---|---|---|
| Mean | No | It uses only the sum and the count. |
| Minimum and maximum | Not strictly, but sorting shows them at the ends | They are the first and last values in order. |
| Median | Yes | It is the value in the middle position. |
| Quartiles | Yes | They are medians of the lower and upper halves. |
| Percentiles | Yes | They are defined by how much of the data lies at or below a value. |
A common GRE error is to take the middle entry of the list as printed. That is the median only when the list happens to be in increasing order.
Sorting a list by hand
Sorting means rearranging values from least to greatest, with each value placed once for every time it appears. Take the following test scores:
14, 3, 21, 8, 5, 18, 7, 13, 12
A reliable method is to scan for the smallest remaining value, write it down, and cross it off. That gives:
3, 5, 7, 8, 12, 13, 14, 18, 21
Then check the work in three ways:
- Count. The original list has 9 values and so does the sorted list. A missing or duplicated value is the most frequent hand-sorting error.
- Scan for order. Each value should be no larger than the one after it.
- Check the ends. The first value is the minimum (3) and the last is the maximum (21).
The same steps in Python:
raw = [14, 3, 21, 8, 5, 18, 7, 13, 12]
ordered = sorted(raw)
print(ordered) # [3, 5, 7, 8, 12, 13, 14, 18, 21]
print(len(raw) == len(ordered)) # True
print(len(ordered), ordered[0], ordered[-1]) # 9 3 21sorted returns a new list and leaves raw unchanged. The list [3, 5, 7, 8, 12, 13, 14, 18, 21] is used again in later chapters, so it is worth remembering.
Positions and counting
Once the list is sorted, each value has a position. Position 1 holds the smallest value and position n holds the largest, where n is the number of values. In the list above:
| Position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| Value | 3 | 5 | 7 | 8 | 12 | 13 | 14 | 18 | 21 |
Two facts about positions are used throughout the tutorial.
- Counting from the other end. The k-th smallest value is the (n − k + 1)-th largest. In this list the 3rd smallest value, 7, is the 7th largest, since 9 − 3 + 1 = 7.
- Odd and even counts differ. With n = 9 there is one value with equal numbers of values on each side: position 5. With an even count there is no such value, and the middle falls between two positions. This difference drives the median and quartile rules in the next chapters, so always note whether n is odd or even.
Duplicate values stay in the list
Data sets often contain repeated values. Sorting never merges them. Each occurrence takes its own position, because each occurrence is one observation.
Consider this list of 8 values: 4, 9, 4, 6, 9, 4, 2, 9. Sorted, it is:
2, 4, 4, 4, 6, 9, 9, 9
If you collapse the repeats to "2, 4, 6, 9", you get 4 values instead of 8, and every position changes. For this data the middle falls between positions 4 and 5, which hold 4 and 6. With the repeats removed, the middle would fall between 4 and 6 as well, but only by coincidence. In general, removing duplicates gives wrong answers.
Expanding frequency tables
The GRE often gives data as a frequency table rather than a list. A frequency table states each value and how many times it occurs. For example:
| Value | Frequency |
|---|---|
| 2 | 3 |
| 5 | 1 |
| 6 | 2 |
| 9 | 4 |
The data set is 2, 2, 2, 5, 6, 6, 9, 9, 9, 9. Here n is the sum of the frequencies: 3 + 1 + 2 + 4 = 10. The table is already in order by value, so expanding it gives a sorted list directly. A table whose value column is not in increasing order must be reordered first.
table = {2: 3, 5: 1, 6: 2, 9: 4}
values = []
for value, count in sorted(table.items()):
values.extend([value] * count)
print(values) # [2, 2, 2, 5, 6, 6, 9, 9, 9, 9]
print(len(values)) # 10Writing out the full list is practical for small tables. For larger ones, build a running total of the frequencies, called a cumulative count, and find positions from it. The table above has cumulative counts 3, 4, 6, 10, so positions 1 to 3 hold the value 2, position 4 holds 5, positions 5 and 6 hold 6, and positions 7 to 10 hold 9.
A frequency of 0 is possible, and that value contributes nothing to the list. Do not count the number of rows in the table as n.
Mixed forms and negative numbers
Data on the GRE may mix fractions, decimals, and negatives. Convert everything to one form before comparing, usually decimals, unless the fractions share a denominator.
Order these values: 3/4, −2, 0.5, −1.5, 1/3.
- Convert to decimals: 0.75, −2, 0.5, −1.5, 0.333...
- Order them: −2, −1.5, 0.333..., 0.5, 0.75.
- Write the result in the original forms: −2, −1.5, 1/3, 0.5, 3/4.
Negative numbers cause the most mistakes. A larger absolute value means a smaller number when the sign is negative, so −2 comes before −1.5. Picturing the number line helps: the further left a value is, the smaller it is.
Sorting pitfalls in code
When you check work with code, the type of the data matters. Text sorts character by character, so "10" comes before "9" because "1" comes before "9".
as_text = ["10", "9", "100"]
print(sorted(as_text)) # ['10', '100', '9']
print(sorted(int(s) for s in as_text)) # [9, 10, 100]The same trap exists on paper in a milder form. A list such as 0.9, 0.12, 0.5 is easily misread: 0.12 is the smallest of the three even though 12 is a "bigger number" than 9 or 5. Compare decimals by place value. Pad with zeros if that helps: 0.90, 0.12, 0.50.
Data given in a chart
Some GRE questions give data as a chart or dot plot instead of a list, so there is no list to sort. A dot plot already shows the values in order along the axis. A bar chart of frequencies works like a frequency table. In both cases, the plan is the same:
- Read each value and its count from the display.
- Find n by adding the counts.
- Treat the values from left to right on the axis as the sorted list.
Read the axis scale carefully. If the labels go up by 5, a dot halfway between labels represents a value halfway between them, not a whole step.
Common errors
- Using the list as printed. The middle entry of an unsorted list is not the median.
- Dropping duplicates. Repeated values are separate observations and keep separate positions.
- Miscounting n. Count after sorting and compare with the original count. For frequency tables, add the frequencies.
- Misordering negatives and decimals. Convert to a common form and check against a number line.
- Sorting text instead of numbers. In code, convert strings to numbers first.
Exercises
Exercise
Order this data set from least to greatest and state n, the minimum, and the maximum: 7, −3, 2.5, 7, 0, −3, 1/2, 10.
Show answer
Convert 1/2 to 0.5. The sorted list is −3, −3, 0, 0.5, 2.5, 7, 7, 10. The duplicates −3 and 7 each stay in the list twice. Then n = 8, the minimum is −3, and the maximum is 10.
Exercise
A frequency table shows the value 1 with frequency 4, the value 3 with frequency 0, the value 6 with frequency 5, and the value 8 with frequency 1. What is n, and which value is in position 6 of the sorted data?
Show answer
n = 4 + 0 + 5 + 1 = 10. The sorted list is 1, 1, 1, 1, 6, 6, 6, 6, 6, 8. The cumulative counts are 4, 4, 9, 10, so positions 1 to 4 hold 1 and positions 5 to 9 hold 6. Position 6 holds the value 6. The value 3 has frequency 0, so it adds nothing to the list.