Variance, Moments and Generating Functions
Variance and standard deviation, higher moments, and using MGFs to derive distributions of sums.
Assumes you know
Variance, Moments and Generating Functions
Intuition first
The mean tells you where a distribution sits. It says nothing about how spread out it is. A company where everyone earns £50,000 and one where half earn £20,000 and half £80,000 have the same mean and completely different realities.
Variance measures that spread as the average squared distance from the mean. Squaring does two things: it makes deviations positive so they cannot cancel, and it penalises large deviations disproportionately — which is why variance is sensitive to outliers, and why the standard deviation, its square root, is what gets reported since it lives in the original units.
Beyond variance there are higher moments — skewness for asymmetry, kurtosis for tail weight — and a remarkable device, the moment generating function, that packages every moment into a single function and turns questions about sums of random variables into questions about products.
Variance and standard deviation
The computational form is almost always easier:
Deriving the computational formulaAdvanced
Expand the square inside the expectation, treating as the constant it is:
Apply linearity of expectation:
Now substitute :
Two things worth noticing. The formula is more convenient because needs only one pass over the distribution — you do not have to know first. And it immediately proves , since variance cannot be negative.
The catch: numerically, subtracting two large nearly-equal numbers loses precision. For data with large mean and small variance, the two-pass formula is more accurate, which is why production code uses Welford's algorithm rather than accumulating .
Properties
Adding a constant shifts the distribution without changing its spread, so vanishes. Scaling by scales deviations by and squared deviations by .
| Symbol | Meaning | Read aloud |
|---|---|---|
| Var(X) or σ² | Variance — mean squared deviation | variance of X |
| σ | Standard deviation, in the units of X | sigma |
| E[Xᵏ] | kth raw moment about the origin | k-th moment |
| E[(X−μ)ᵏ] | kth central moment | k-th central moment |
| Mₓ(t) | Moment generating function, E[e^{tX}] | M of t |
Solved problem 1 · Variance of a fair die, three ways
Compute for a fair six-sided die.
Step 1 — the two ingredients
From the expectation lesson:
Step 2 — computational formula
Common denominator 12:
Step 3 — verify by the definition
Deviations from 3.5 and their squares:
Step 4 — standard deviation
Interpretable: a typical roll is about 1.7 away from 3.5.
Answer
, .
Solved problem 2 · Variance of a sum, with and without independence
Two fair dice. Let be the sum and the difference. Find and . Then find and compare with .
Step 1 — independence and the sum
The dice are independent, so covariance is zero:
Step 2 — the difference
Identical to the sum. Subtracting an independent quantity adds variance exactly as adding one does.
Step 3 — doubling a single die
Step 4 — compare, and note why they differ
Exactly double. Both have mean 7, but can only take even values with equal probability, while concentrates around 7 because there are more ways to make 7 than to make 2.
This is averaging at work: two independent draws partially cancel each other's deviations, whereas doubling one draw doubles its deviation with nothing to offset it.
Answer
; , twice as large. Independent draws average out; scaling one draw does not.
Higher moments
Skewness — third standardised moment, measuring asymmetry:
Positive means a long right tail (income, claim sizes); negative means a long left tail.
Kurtosis — fourth standardised moment, measuring tail weight:
The normal distribution has kurtosis 3, so excess kurtosis subtracts 3 to make normal the zero point. Positive excess kurtosis means heavier tails than normal — more extreme events than a Gaussian model would predict, which is the standard failure of financial risk models.
Moment generating functions
when the expectation exists for in a neighbourhood of zero. Its usefulness comes from two properties.
Moments by differentiation:
Sums become products: for independent and ,
Why both properties holdAdvanced
Moments. Expand the exponential as a power series and take expectations term by term:
So is a power series whose coefficient on is . Differentiating times and evaluating at isolates exactly that term, leaving . Every moment is encoded in this one function — hence "generating".
Sums. For independent and , the variables and are also independent, so the expectation factorises:
This converts convolution — the genuinely awkward operation of finding the distribution of a sum — into multiplication. Combined with the fact that an MGF determines the distribution uniquely, it gives a clean method: multiply the MGFs, recognise the result, and you have the distribution of the sum.
It is how one proves that a sum of independent Poissons is Poisson, a sum of independent normals is normal, and a sum of independent exponentials is gamma. It is also the engine behind one standard proof of the Central Limit Theorem.
Solved problem 3 · Moments from an MGF
has MGF for . Find and .
Step 1 — first derivative
Step 2 — evaluate at zero for the mean
Step 3 — second derivative
Step 4 — variance
Step 5 — identify the distribution
The form is the gamma MGF with shape and scale . Gamma has mean and variance , matching both results.
Answer
, . The MGF identifies the distribution as Gamma(3, 2).
import numpy as np
rng = np.random.default_rng(0)
d1 = rng.integers(1, 7, 400_000)
d2 = rng.integers(1, 7, 400_000)
for name, v, theory in (
("Var(X)", d1, 35/12),
("Var(X1+X2)", d1 + d2, 35/6),
("Var(X1-X2)", d1 - d2, 35/6),
("Var(2X1)", 2 * d1, 35/3),
):
print(f"{name:12s} empirical {v.var():8.4f} theory {theory:8.4f}")
# Standard error of the mean: sigma / sqrt(n).
for n in (10, 100, 1000):
means = rng.integers(1, 7, size=(20_000, n)).mean(axis=1)
print(f"n={n:<5} SD of sample mean {means.std():.4f} "
f"theory {np.sqrt(35/12)/np.sqrt(n):.4f}")Exercise 1
has mean 10 and variance 4. Find the mean and variance of .
Show solutionHide solution
Mean, by linearity:
Variance — the additive constant drops out, the multiplier squares:
So , three times . The standard deviation scales by while the variance scales by , which is the practical reason to report standard deviations: they transform the way intuition expects.
Exercise 2
Independent and each have variance 9. A student computes , reasoning that the variances cancel. Correct them.
Show solutionHide solution
The error is treating variance as linear. The scaling rule is , and for we get — the minus sign is squared away, so the variance of is added.
Intuitively: subtracting an independent random quantity does not cancel randomness, it introduces more. Each of and fluctuates independently, and the difference fluctuates more than either alone.
A concrete check: if and are independent fair-coin values in , then takes values with probabilities — genuinely more spread out than either input, which lives in .
Zero variance would require and to be perfectly correlated, , in which case and .
Next: Covariance and Correlation, which is the missing term in the variance-of-a-sum formula.