Sub topic 8
Standard deviation step by step
This chapter assumes you can find a mean, square numbers, take square roots, and work with negative numbers. It builds on the earlier chapters on the mean and on deviations from the mean.
What standard deviation measures
The range uses only two values, the largest and the smallest. Standard deviation (SD) uses every value. It describes the typical distance between a value and the mean of the data set. A small SD means the values cluster near the mean. A large SD means they are spread out.
SD has the same units as the data. If the data are heights in inches, the SD is in inches. That is why the recipe ends with a square root.
The five-step recipe
The GRE uses the population standard deviation. It treats the list you are given as the whole group, so you divide by the number of values, n.
- Find the mean.
- Subtract the mean from each value. These differences are the deviations.
- Square each deviation.
- Average the squared deviations, which means adding them and dividing by n. This result is the variance.
- Take the square root of the variance.
Worked example
Use the data set 2, 4, 4, 4, 5, 5, 7, 9, which has n = 8.
Step 1. The sum is 40, so the mean is 40 / 8 = 5.
Step 2. Subtract 5 from each value:
| Value | Deviation | Squared deviation |
|---|---|---|
| 2 | -3 | 9 |
| 4 | -1 | 1 |
| 4 | -1 | 1 |
| 4 | -1 | 1 |
| 5 | 0 | 0 |
| 5 | 0 | 0 |
| 7 | 2 | 4 |
| 9 | 4 | 16 |
Step 3. The squared deviations are in the third column.
Step 4. Their sum is 9 + 1 + 1 + 1 + 0 + 0 + 4 + 16 = 32. The variance is 32 / 8 = 4.
Step 5. The SD is the square root of 4, which is 2.
The same steps in Python:
import math
data = [2, 4, 4, 4, 5, 5, 7, 9]
mean = sum(data) / len(data)
deviations = [x - mean for x in data]
squared = [d ** 2 for d in deviations]
variance = sum(squared) / len(data)
sd = math.sqrt(variance)
print(deviations) # [-3.0, -1.0, -1.0, -1.0, 0.0, 0.0, 2.0, 4.0]
print(squared) # [9.0, 1.0, 1.0, 1.0, 0.0, 0.0, 4.0, 16.0]
print(variance) # 4.0
print(sd) # 2.0The standard library gives the same answer in one call:
import statistics
data = [2, 4, 4, 4, 5, 5, 7, 9]
print(statistics.mean(data)) # 5
print(statistics.median(data)) # 4.5
print(statistics.mode(data)) # 4
print(max(data) - min(data)) # 7
print(statistics.pstdev(data)) # 2.0The function pstdev is the population version. The name stdev is a different calculation, covered below.
Why each step is there
Why square the deviations?
The deviations from the mean always add up to zero. In the example, -3 - 1 - 1 - 1 + 0 + 0 + 2 + 4 = 0. Averaging raw deviations would therefore always give 0, which tells you nothing. Squaring makes every term nonnegative, so values below and above the mean both add to the spread.
Squaring also gives far values more weight. A deviation of 4 contributes 16, while a deviation of 1 contributes only 1. This is why SD reacts strongly to values far from the mean.
Why take the square root at the end?
Squaring changed the units. Squared inches are not inches. The square root returns the answer to the original units, so the SD can be compared directly with the data and the mean.
A useful check: the zero deviation sum
After step 2, add up your deviations. If the total is not 0, you have an arithmetic error in the mean or in one subtraction. This check takes a few seconds and catches most mistakes before you square anything.
A second example with a messy answer
Take 1, 3, 5, 7. The mean is 16 / 4 = 4. The deviations are -3, -1, 1, 3, and the squares are 9, 1, 1, 9. The squares sum to 20, so the variance is 20 / 4 = 5. The SD is the square root of 5, which is about 2.24.
The GRE often leaves the answer as a square root, or asks only for an estimate. You can see that the square root of 5 lies between 2 and 3, since 2 squared is 4 and 3 squared is 9. That is often all a question needs.
Properties worth memorizing
- The SD is never negative.
- The SD is 0 exactly when every value is identical. For 6, 6, 6, 6, every deviation is 0, so the SD is 0.
- The SD is not the same as the range. The data 2, 4, 4, 4, 5, 5, 7, 9 have a range of 7 but an SD of 2.
- Values far from the mean raise the SD more than values near it.
- The SD depends on the distances between values, not on where the values sit on the number line. The set 102, 104, 104, 104, 105, 105, 107, 109 has the same SD of 2 as the original set.
The last property is why adding the same constant to every value leaves the SD unchanged. Multiplying every value by a constant k multiplies the SD by the absolute value of k. The later chapter on transformations covers this in full. Here is a quick check on the example data:
import statistics
data = [2, 4, 4, 4, 5, 5, 7, 9]
transformed = [3 * x + 10 for x in data]
print(statistics.pstdev(data)) # 2.0
print(statistics.pstdev(transformed)) # 6.0The SD becomes 3 times larger. The shift of +10 has no effect.
Population versus sample
When data are a sample drawn from a larger group, statisticians often divide the sum of squared deviations by n - 1 instead of n. This is the sample standard deviation. For the example data it gives the square root of 32 / 7, about 2.14, instead of 2.
import statistics
data = [2, 4, 4, 4, 5, 5, 7, 9]
print(statistics.pstdev(data)) # 2.0
print(statistics.stdev(data)) # about 2.138Common errors
- Forgetting the square root. If you stop at step 4, you have the variance, not the SD. In the example, 4 is the variance and 2 is the SD.
- Dividing the sum of squares by the wrong count. Divide by the number of values, counting repeats. The list 2, 4, 4, 4, 5, 5, 7, 9 has n = 8, not 5.
- Squaring the sum of deviations. You square each deviation first, then add. The sum of deviations is 0, so squaring it would give 0.
- Dropping signs. A deviation of -3 squares to 9, not -9. A squared term is never negative.
- Using the median instead of the mean. The standard deviation is measured from the mean. In the example the median is 4.5, but all deviations use 5.
- Skipping repeated values. Each copy of a repeated value counts separately. The value 4 appears three times and contributes 1 three times.
You can confirm that last point with the example data:
import statistics
data = [2, 4, 4, 4, 5, 5, 7, 9]
with_mean_added = data + [statistics.mean(data)]
print(statistics.mean(with_mean_added)) # 5
print(statistics.pstdev(data)) # 2.0
print(statistics.pstdev(with_mean_added)) # less than 2.0The new SD is the square root of 32 / 9, about 1.89.
Estimating without full calculation
The GRE rarely needs the exact SD. It more often asks which of two sets has the larger SD. In those questions, compare how far the values sit from the mean.
Take set A: 1, 2, 3, 4, 5, and set B: 1, 1, 3, 5, 5. Both have mean 3 and range 4. In B, four of the five values are 2 away from the mean. In A, the values are mostly closer to the mean. The squared deviations for A sum to 10, giving a variance of 2. For B they sum to 16, giving a variance of 3.2. So B has the larger SD even though the ranges match.
The rule: with the same mean and the same number of values, the set whose values sit farther from the center has the larger SD. The next chapter develops this idea further.
Exercise
Find the population standard deviation of the data set 2, 2, 8, 8. Show the mean, the deviations, and the variance.
Show answer
The mean is 20 / 4 = 5. The deviations are -3, -3, 3, 3, and they sum to 0. The squared deviations are 9, 9, 9, 9, which sum to 36. The variance is 36 / 4 = 9. The standard deviation is the square root of 9, which is 3.
Exercise
Set P is 1, 2, 3, 4, 5. Set Q is 11, 12, 13, 14, 15. Without calculating, which set has the larger standard deviation, and why?
Show answer
They have the same standard deviation. Set Q is set P with 10 added to every value. That shifts the mean from 3 to 13 but leaves each value's distance from its mean unchanged. Both have variance 2 and SD equal to the square root of 2.
Exercise
A data set has 5 values, and the sum of the squares of their deviations from the mean is 45. What is the standard deviation?
Show answer
The variance is 45 / 5 = 9. The standard deviation is the square root of 9, which is 3.