Summarizing a list of numbers
Before you start
You need nothing else first. This unit starts from scratch.
The idea in one paragraph
Two numbers summarize a long list well. The mean, or average, says where the values sit: add them up and divide by how many there are. The standard deviation says how spread out they are: roughly, how far a typical value lies from the mean. Two lists can share a mean and still differ a lot in spread. Together the two numbers give the center and the width of the data.
The mean is the balance point
Five friends rate a film from 0 to 10: 4, 8, 6, 5 and 7. The mean is the sum divided by the count: 30 / 5 = 6. If the ratings were weights on a ruler, the ruler would balance at 6. Each value's deviation is its distance from the mean, with a sign: here −2, +2, 0, −1 and +1. The deviations always add to zero, which is what "balance point" means.
The standard deviation is a typical distance from the mean
Five other friends rate the same film 2, 10, 6, 3 and 9. Their mean is also 30 / 5 = 6, but they disagree far more. To measure that, average the squared deviations, then take the square root. Squaring makes every deviation positive and counts large ones more. The average of the squares is the variance. Its square root, the standard deviation, is back in the same units as the data (rating points, here).
σ = √( average of (value − mean)2 )
The Greek letter σ (sigma) is the usual symbol for the standard deviation, and μ (mu) for the mean.
| Ratings | Deviations from 6 | Squares | Mean of squares | σ | |
|---|---|---|---|---|---|
| Group 1 | 4, 8, 6, 5, 7 | −2, 2, 0, −1, 1 | 4, 4, 0, 1, 1 | 10 / 5 = 2 | √2 ≈ 1.41 |
| Group 2 | 2, 10, 6, 3, 9 | −4, 4, 0, −3, 3 | 16, 16, 0, 9, 9 | 50 / 5 = 10 | √10 ≈ 3.16 |
Same mean, 6. Group 2's standard deviation is more than twice group 1's, which matches how much more they disagree.
Your turn. Find the mean and standard deviation of 1, 3, 5, 7.
Answer
The mean is 16 / 4 = 4. The deviations are −3, −1, 1, 3, with squares 9, 1, 1, 9. Their mean is 20 / 4 = 5, so σ = √5 ≈ 2.24.
mean = standard deviation =
This page divides by the number of values, n. When a list is a sample from a larger group and you
want to estimate the larger group's spread, statisticians divide by n − 1 instead, which gives a
slightly larger number. NumPy's np.std divides by n unless you pass
ddof=1. Also, one extreme value can drag the mean a long way; the median, the middle
value once the list is sorted, is less sensitive to it.
mean.py: the two summaries in NumPy
import numpy as np
a = np.array([4, 8, 6, 5, 7])
b = np.array([2, 10, 6, 3, 9])
print(a.mean(), b.mean()) # same middle
print(round(a.std(), 3), round(b.std(), 3)) # different spread
6.0 6.0 1.414 3.162
Check yourself
-
What is the mean of 2, 4 and 9?
Answer
15 / 3 = 5.
-
You add 10 to every value in a list. What happens to the mean and to the standard deviation? What if you multiply every value by 3 instead?
Answer
Adding 10 raises the mean by 10 and leaves the standard deviation alone, because every deviation stays the same. Multiplying by 3 triples both the mean and the standard deviation.
-
When is a list's standard deviation exactly zero?
Answer
When every value is the same. Then every deviation is zero.
Go further
Optional background, for readers who want more than this page.
-
Basic probability: Expectation and Variance Seeing Theory, Brown University; chapter 1, second and third sections Interactive page Basic
Mean and spread for chance outcomes, with draws you can watch accumulate.
-
A plain walk-through with dogs' heights, and the n versus n − 1 question.
Where this shows up
Units that build on this one
- The bell curve (normal distribution) Basic
- Normalizing data Basic
- Loss: one number for how wrong Intermediate
- A moving average of the weights (EMA) Intermediate