Article
Counting, averages and ranges
Your teacher says, "The class average on the test was 62." What does that tell you? It is one number that stands for the whole class. A number like this is a statistic. It is useful, but it also hides things. This article shows how to compute the common statistics, and what each one cannot tell you.
Eight numbers that describe a list
Seven students said how many minutes of homework they did last night: 10, 35, 20, 35, 40, 25, 45. Here are the statistics, worked by hand:
| Statistic | What it is | How to find it | Result |
|---|---|---|---|
| Count | how many values | count them | 7 |
| Sum | all the values added | 10 + 35 + 20 + 35 + 40 + 25 + 45 | 210 |
| Mean | the usual "average" | sum ÷ count | 210 ÷ 7 = 30 |
| Median | the middle value | sort the list, take the middle one | 35 |
| Mode | the value that appears most often | count how often each value appears | 35 |
| Minimum | the smallest value | look for the smallest | 10 |
| Maximum | the biggest value | look for the biggest | 45 |
| Range | how far the values spread | maximum − minimum | 45 − 10 = 35 |
The median needs a sorted list. Sorted, the list is 10, 20, 25, 35, 35, 40, 45. Three values are on each side of the fourth, so the fourth value, 35, is the median. If the count is even, no single value is in the middle. Take the two middle values and find their mean. For 10, 20, 30, 40 the median is (20 + 30) ÷ 2 = 25.
The mode is a value, not a count. Here it is 35, not 2. A list can have two modes, or none (when every value appears once).
Check your understanding
What is the median of this list?
8, 3, 9, 5, 4
Computing them with a program
A program can do the same work, even for a million values. In AP pseudocode, this loop finds the sum, the smallest and the largest in one pass:
minutes ← [10, 35, 20, 35, 40, 25, 45]
total ← 0
smallest ← minutes[1]
largest ← minutes[1]
FOR EACH m IN minutes
{
total ← total + m
IF(m < smallest)
{
smallest ← m
}
IF(m > largest)
{
largest ← m
}
}
DISPLAY(total / LENGTH(minutes))
DISPLAY(largest - smallest)m | total | smallest | largest |
|---|---|---|---|
| start | 0 | 10 | 10 |
| 10 | 10 | 10 | 10 |
| 35 | 45 | 10 | 35 |
| 20 | 65 | 10 | 35 |
| 35 | 100 | 10 | 35 |
| 40 | 140 | 10 | 40 |
| 25 | 165 | 10 | 40 |
| 45 | 210 | 10 | 45 |
It displays 30 (the mean) and 35 (the range). Note that smallest and largest start as the first element, not as 0.
AP pseudocode has no command that sorts a list, so the exam describes sorting in words. Python can sort. This program finds all the statistics. Change the list and run it again.
Python counts from 0, so the middle of 7 sorted values is ordered[3], the fourth one. // divides and drops the remainder. An empty list makes count 0, and dividing by 0 is an error, so a careful program checks for that first.
What each statistic hides
One number cannot show everything. An outlier is a value far away from the others. Five people in a small firm earn (in thousands) 30, 32, 35, 38, 215:
| Statistic | Value | What it suggests |
|---|---|---|
| Mean | (30 + 32 + 35 + 38 + 215) ÷ 5 = 70 | "A typical person earns 70." Wrong: four of five earn less than 40. |
| Median | 35 | Closer to what most people earn. |
The outlier, 215, pulls the mean up a lot. It hardly moves the median. So when a few values are extreme, the median describes a "typical" value better.
Two lists can also share a mean and look very different. 30, 30, 30, 30, 30 and 0, 0, 30, 60, 60 both have a mean of 30. Only the range (0 against 60) shows the difference.
| Statistic | What it can hide |
|---|---|
| Mean | outliers pull it away from the typical value |
| Median | how big the extreme values are |
| Mode | everything except the most common value |
| Range | the values between the smallest and largest |
Check your understanding
Five students say how much pocket money they get each week: 4, 5, 6, 7, 40. Which statistic best describes a typical student?
Common mistakes
- Finding the median without sorting. The middle of an unsorted list is just a random value.
- Forgetting the even-count rule. With four values, the median is the mean of the middle two.
- Giving the count as the mode. If 35 appears twice, the mode is 35, not 2.
- Using the maximum as the range. The range is maximum minus minimum.
- Dividing by the wrong number. The mean divides by the count (
LENGTH), not by the largest value. - Trusting the mean when there is an outlier. Check the median too.
On the exam
Expect a small list or table and "What is the median?", or "Which statistic changes the most if the largest value is replaced by a much bigger one?" (the mean and the range change, and the median stays the same). Other questions give a loop and ask what it computes, such as the sum, the count of values over a limit, or the largest value. Trace it with a table. Also expect "Which of the following can be determined from the mean alone?" A mean says nothing about how the values are spread.
Key words
Statistic: one number that summarises a data set.
Mean: the sum of the values divided by how many there are.
Median: the middle value of a sorted list. For an even count, the mean of the two middle values.
Mode: the value that appears most often.
Range: the maximum minus the minimum.
Outlier: a value far away from the rest of the data.