How to calculate mean, variance, and standard deviation

The mean tells us where the data are centered. Variance and standard deviation tell us how spread out the values are around that mean. We’ll calculate all three and see what changes when the data are a sample.

Find the population or sample mean

A population contains the whole group you want to describe. A sample is part of that group. Add the values and divide by their count. We use N and μ for population size and mean, and n and x̄ for sample size and mean.

μ=∑i=1NxiNx̄=∑i=1nxin

Square the deviations, then choose the denominator

Subtract the mean from each value and square the result. Squaring keeps the positive and negative deviations from canceling. Add the squares.

σ2=∑i=1N(xi-μ)2Ns2=∑i=1n(xi-x̄)2n-1

For a sample with at least two observations, dividing by n-1 gives an unbiased estimate of population variance under the usual random sampling assumptions. That means it is correct on average over repeated samples. An individual estimate can be above or below the population variance.

Take the square root to get standard deviation

σ=σ2,s=s2

Variance is in squared units. Taking the square root puts standard deviation back in the units of the original values. The square root of an unbiased variance estimate is generally biased as an estimate of population standard deviation.

Example: Find all three measures for a sample

A principal samples ten teachers’ ages. Their ages add to 432, so the mean is 43210=43.2 years. Subtract 43.2 from each age, then square each difference.

Deviations from the sample mean of 43.2 years
AgeDeviationSquared deviation
43-0.20.04
35-8.267.24
38-5.227.04
5612.8163.84
29-14.2201.64
33-10.2104.04
462.87.84
6319.8392.04
495.833.64
40-3.210.24

The squared deviations add to 1,007.60. The sample has ten observations, so divide by nine before taking the square root.

s2=1007.609≈111.96s=1007.609≈10.58

The sample variance is about 111.96 square years and the sample standard deviation is about 10.58 years.