Unit 5: Data analysis · Data tools

Article

Counting, averages and ranges

8 min read

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:

StatisticWhat it isHow to find itResult
Counthow many valuescount them7
Sumall the values added10 + 35 + 20 + 35 + 40 + 25 + 45210
Meanthe usual "average"sum ÷ count210 ÷ 7 = 30
Medianthe middle valuesort the list, take the middle one35
Modethe value that appears most oftencount how often each value appears35
Minimumthe smallest valuelook for the smallest10
Maximumthe biggest valuelook for the biggest45
Rangehow far the values spreadmaximum − minimum45 − 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:

AP pseudocode
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)
mtotalsmallestlargest
start01010
10101010
35451035
20651035
351001035
401401040
251651040
452101045

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.

Runs in your browser

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:

StatisticValueWhat it suggests
Mean(30 + 32 + 35 + 38 + 215) ÷ 5 = 70"A typical person earns 70." Wrong: four of five earn less than 40.
Median35Closer 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.

StatisticWhat it can hide
Meanoutliers pull it away from the typical value
Medianhow big the extreme values are
Modeeverything except the most common value
Rangethe 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.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this site. All lessons and questions here are written by JrCodex.