Contents
Measuring Spread with Range, Variance and Standard Deviation
Two datasets can have the same mean and still look very different. Exam scores of 49, 50, 51 and scores of 10, 50, 90 both average 50, but the second group is far more scattered. Spread measures that difference.
Range
Range = maximum value − minimum value
Range is quick to compute, but it uses only two values, so it says nothing about how the rest of the data is arranged.
Variance
s² = Σ(xᵢ − x̄)² / (n − 1)
- s²: the sample variance. It is the average squared distance of the values from their mean, so it is measured in squared units.
- xᵢ − x̄: the deviation, meaning how far one value sits from the mean.
- Squaring: removes negative signs so deviations above and below the mean don't cancel out, and it gives larger gaps more weight.
- n − 1: the number of observations minus one. The reason is explained below.
Standard Deviation
s = √s²
- s: the sample standard deviation. It tells you how far a typical value sits from the mean, in the same units as the original data.
When you have every member of the population, the formula changes to σ² = Σ(xᵢ − μ)² / N.
- σ² (sigma squared): the population variance.
- μ (mu): the true population mean.
- N: the population size. Dividing by N is correct here because nothing is being estimated.
Why n − 1 for a Sample
A sample’s values sit closer to the sample’s own mean than to the true population mean. Dividing by n would therefore underestimate the true spread, and dividing by n − 1 corrects for that.
Example: Find the range, variance and standard deviation of 4, 8, 6, 5, 7, treated as a sample.
- Mean: (4 + 8 + 6 + 5 + 7) / 5 = 30 / 5 = 6
- Deviations from the mean: −2, 2, 0, −1, 1
- Squared deviations: 4, 4, 0, 1, 1, which add up to 10
- Sample variance: 10 / (5 − 1) = 2.5
- Standard deviation: √2.5 ≈ 1.58
- Range: 8 − 4 = 4
A typical value in this data is about 1.58 units away from the mean of 6.
import numpy as np
import pandas as pd
data = [4, 8, 6, 5, 7]
print(np.var(data))
print(np.var(data, ddof=1))
print(pd.Series(data).std())Code Explanation:
- np.var(data) divides by n by default, so it returns 2.0, the population variance.
- ddof=1 changes the divisor to n − 1, so the second line returns 2.5, the sample variance.
- pd.Series(data).std() uses n − 1 by default and returns about 1.58.
- NumPy and pandas use different defaults, which often leads to mismatched results, so always check which one your tool uses.
Probability and Statistics for Data Science
Abhishek Pati








