Search

Search papers and lessons

Mean and Variance

Level 1 · 8 min read

The mean is the centre of a set of values and the variance is the average squared distance from that centre; their square root, the standard deviation, measures spread in the original units.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Sign in to see your progress

TL;DR

The mean tells you where a set of values is centred. The variance tells you how spread out they are around that centre: it is the average of the squared distances from the mean. Taking the square root gives the standard deviation, which measures spread in the same units as the data.

Both numbers summarise a distribution with two figures instead of the whole list of values. Where you'll see it: in error bars on lab measurements, in the z-scores used to flag unusual results, and in the two parameters that define a Gaussian.

Intuition

Suppose five friends weigh 60, 62, 64, 66 and 68 kg. You want one number for a typical weight. The mean, 64 kg, is the balance point: the values on either side of it cancel out exactly. The mean says where the data sits, but two groups can share a mean and look nothing alike. Weights of 63, 64, 64, 64, 65 and weights of 50, 58, 64, 70, 78 both average 64.

To describe the difference you need a spread measure. The obvious idea is to average the distances from the mean. But positive and negative distances cancel, so you square each distance first. Squaring also punishes large deviations more than small ones, which is useful when you care about big misses. The average of those squares is the variance. Its units are squared (kg²), which is awkward to read, so you take the square root to get the standard deviation, in kg again.

flowchart LR
  A[Values] --> B[Mean: the centre]
  B --> C[Distance of each value from the mean]
  C --> D[Square each distance]
  D --> E[Average the squares: variance]
  E --> F[Square root: standard deviation]

The math

Mean (expected value)

For a random variable XX that takes value xix_i with probability pip_i, the mean is the expected value:

μ=E[X]=∑ixi pi.\mu = \mathbb{E}[X] = \sum_i x_i \, p_i.

Here μ\mu (the Greek letter mu) is the centre of the distribution, and pip_i is the probability of outcome xix_i. For a finite list of observed values x1,…,xnx_1, \dots, x_n with equal weight, the sample mean is xˉ=1n∑i=1nxi\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i. It is the same operation with each value weighted 1/n1/n.

Variance

Definition: Variance

The variance of a random variable XX with mean μ\mu is

σ2=Var(X)=E[(X−μ)2].\sigma^2 = \mathrm{Var}(X) = \mathbb{E}\big[(X - \mu)^2\big].

Its square root σ=Var(X)\sigma = \sqrt{\mathrm{Var}(X)} is the standard deviation.

Here σ2\sigma^2 is the variance and σ\sigma the standard deviation. The expression X−μX - \mu is the signed distance from the centre, and squaring it removes the sign.

There is a shortcut formula that is usually easier to compute. Expand the square and use linearity of expectation (the mean of a sum is the sum of the means):

E[(X−μ)2]=E[X2−2μX+μ2]=E[X2]−2μ E[X]+μ2=E[X2]−2μ2+μ2=E[X2]−μ2.\begin{aligned} \mathbb{E}\big[(X-\mu)^2\big] &= \mathbb{E}\big[X^2 - 2\mu X + \mu^2\big] \\ &= \mathbb{E}[X^2] - 2\mu\,\mathbb{E}[X] + \mu^2 \\ &= \mathbb{E}[X^2] - 2\mu^2 + \mu^2 \\ &= \mathbb{E}[X^2] - \mu^2. \end{aligned}

So the variance is the mean of the squares minus the square of the mean.

Scaling and shifting

Adding a constant moves the data but does not change its spread. Multiplying by a constant aa stretches it. The rules are

E[aX+b]=aμ+b,Var(aX+b)=a2 Var(X).\mathbb{E}[aX + b] = a\mu + b, \qquad \mathrm{Var}(aX + b) = a^2\,\mathrm{Var}(X).

The second follows because (aX+b)−(aμ+b)=a(X−μ)(aX + b) - (a\mu + b) = a(X - \mu), and squaring gives a2(X−μ)2a^2 (X - \mu)^2. Notice that the standard deviation scales by ∣a∣|a|, not a2a^2.

Adding independent quantities

If XX and YY are independent, their variances add:

Var(X+Y)=Var(X)+Var(Y).\mathrm{Var}(X + Y) = \mathrm{Var}(X) + \mathrm{Var}(Y).

Expanding (X−μX+Y−μY)2(X - \mu_X + Y - \mu_Y)^2 gives two squared terms plus a cross term 2(X−μX)(Y−μY)2(X - \mu_X)(Y - \mu_Y). Independence makes the expected cross term zero: the average of a product of independent deviations is the product of their averages, and each of those averages is 0. Standard deviations do not add: σX+Y=σX2+σY2\sigma_{X+Y} = \sqrt{\sigma_X^2 + \sigma_Y^2}, which is less than σX+σY\sigma_X + \sigma_Y whenever both are positive.

Worked examples

Example
A fair die

Let XX be the value of one roll of a fair six-sided die. Each face has probability 1/61/6.

  1. Mean: μ=1+2+3+4+5+66=216=3.5\mu = \frac{1+2+3+4+5+6}{6} = \frac{21}{6} = 3.5.
  2. Mean of squares: E[X2]=1+4+9+16+25+366=916≈15.1667\mathbb{E}[X^2] = \frac{1+4+9+16+25+36}{6} = \frac{91}{6} \approx 15.1667.
  3. Variance: σ2=15.1667−3.52=15.1667−12.25=2.9167\sigma^2 = 15.1667 - 3.5^2 = 15.1667 - 12.25 = 2.9167, which is exactly 35/1235/12.
  4. Standard deviation: σ=2.9167≈1.708\sigma = \sqrt{2.9167} \approx 1.708.
  5. Interpretation: a typical roll is about 1.7 faces away from 3.5. The mean is not a face you can roll, which is normal: the mean is a balance point, not an outcome.
Example
Exam scores, population and sample

Eight students score 2, 4, 4, 4, 5, 5, 7 and 9.

  1. Sum is 40, so the mean is xˉ=40/8=5\bar{x} = 40/8 = 5.
  2. Deviations from 5 are −3,−1,−1,−1,0,0,2,4-3, -1, -1, -1, 0, 0, 2, 4. Their squares are 9,1,1,1,0,0,4,169, 1, 1, 1, 0, 0, 4, 16, which sum to 32.
  3. If these eight are the whole class, the variance is 32/8=432/8 = 4 and the standard deviation is 2.
  4. If they are a sample from a larger group, divide by n−1=7n - 1 = 7 instead. The variance estimate is 32/7≈4.57132/7 \approx 4.571 and the standard deviation is about 2.14.
  5. Interpretation: the spread is about two points. Dividing by n−1n - 1 corrects the tendency of the sample to look less spread out than the full population.
Example
Converting units

A temperature sensor reports Celsius with standard deviation 2 degrees. What is the spread in Fahrenheit?

  1. The conversion is F=1.8 C+32F = 1.8\,C + 32, so a=1.8a = 1.8 and b=32b = 32.
  2. Var(F)=a2 Var(C)=1.82×4=3.24×4=12.96\mathrm{Var}(F) = a^2\,\mathrm{Var}(C) = 1.8^2 \times 4 = 3.24 \times 4 = 12.96.
  3. σF=12.96=3.6\sigma_F = \sqrt{12.96} = 3.6, which is 1.8×21.8 \times 2.
  4. Interpretation: the shift by 32 has no effect on spread, and the stretch by 1.8 multiplies the standard deviation by 1.8.

Tradeoffs and failure modes

Mean and variance are the right summaries when the data is roughly symmetric and free of extreme values. They are misleading when it is not.

SituationProblemBetter choice
One extreme value (an outlier)The mean moves toward it and the variance inflatesMedian and interquartile range
Heavy-tailed or skewed data (incomes, response times)The mean describes no typical person; the variance may be huge or even infiniteMedian, quantiles, log-transform
Comparing spread across different scalesStandard deviation depends on unitsCoefficient of variation σ/μ\sigma/\mu (for positive μ\mu only)
Growth rates, multiplicative effectsArithmetic mean overstates typical growthGeometric mean
Very small samplesDividing by nn underestimates the varianceDivide by n−1n - 1

Some practical warnings:

  • Two numbers can hide shape. A bimodal set of values can have the same mean and variance as a flat one. Plot the data before trusting the summary.
  • The shortcut formula can fail numerically. If the values are large and their spread is small, E[X2]−μ2\mathbb{E}[X^2] - \mu^2 subtracts two nearly equal numbers and loses precision. Use an online method such as Welford's algorithm in code.
  • Squared units are hard to read. Report the standard deviation for anything a person will interpret.

History

The arithmetic mean is far older than probability. Astronomers and surveyors averaged repeated measurements to reduce error long before anyone called it an expectation. The link to chance came from gambling. In 1657 Christiaan Huygens published a short treatise on dice games that introduced the idea of expected value, the average winnings over many plays.

Spread measures came later. Carl Friedrich Gauss, working on measurement errors in the early 1800s, relied on squared deviations in his least-squares method. The term "standard deviation" was introduced by Karl Pearson in the 1890s. The term "variance" was introduced by Ronald Fisher in 1918, in a paper on heredity. Both names stuck because the squared-deviation measure turned out to be the one that adds cleanly for independent quantities, which is what makes it so useful in later statistics.

Check yourself

QuestionWhat is the variance of a random variable that equals 3 with certainty?Show answer

The variance is 0. There is no spread: every value is the mean, so every squared distance from the mean is 0.

QuestionValues are x=1,2,3,6x = 1, 2, 3, 6 with equal weight. What is the variance?Show answer

The mean is (1+2+3+6)/4=3(1+2+3+6)/4 = 3. The squared deviations are 4,1,0,94, 1, 0, 9, which sum to 14. Dividing by 4 gives variance 3.53.5.

QuestionWhy do we square the deviations instead of averaging their absolute values or just averaging them?Show answer

Plain deviations average to zero for any dataset, because the positive and negative distances cancel exactly. Absolute values would work as a spread measure, but squaring gives a smooth function that is easy to differentiate and adds cleanly for independent quantities. That is why the variance, not the mean absolute deviation, underlies most of probability theory.

QuestionA measurement error is the sum of two independent sources, and each source has variance 4. What is the standard deviation of the total error, and why is it not 8?Show answer

The variances add: 4+4=84 + 4 = 8, so the standard deviation is 8≈2.83\sqrt{8} \approx 2.83. It is not 8 because standard deviations do not add. Only variances add for independent quantities.

Sources