Advanced Mathematics

Random Variables, Expectation and Variance

A number decided by chance, summed up by its expectation (the long-run average) and its variance (how far it typically strays).

Needs a step first: 4

A random variable attaches a number to each outcome, such as the score on a die. Its expectation E[X]=∑x P(X=x)E[X]=\sum x\,P(X=x) is the average over many repeats, and its variance Var⁡(X)=E[X2]−E[X]2\operatorname{Var}(X)=E[X^2]-E[X]^2 measures the spread. Expectation is always linear, E[X+Y]=E[X]+E[Y]E[X+Y]=E[X]+E[Y], even when XX and YY depend on each other, but variances add only for independent variables. These two numbers run through distributions, the central limit theorem, entropy and every loss function in machine learning.

Where it shows up: Training a model minimises an expected loss, and stochastic gradient descent works because a random mini-batch gradient has the true gradient as its expectation.

How to hold it: By hand, until automatic

Use linearity of expectation, E[aX+b]=aE[X]+bE[aX+b]=aE[X]+b, Var⁡(aX+b)=a2Var⁡(X)\operatorname{Var}(aX+b)=a^2\operatorname{Var}(X) and the sum rule for independent variances automatically, since they sit inside nearly every argument about data and models.

What knowing it looks like

  • Compute the expectation and variance of a discrete random variable from its table.
  • Use E[aX+b]=aE[X]+bE[aX+b]=aE[X]+b and Var⁡(aX+b)=a2Var⁡(X)\operatorname{Var}(aX+b)=a^2\operatorname{Var}(X).
  • Use linearity of expectation to find an average without working out the whole distribution.

Test yourself

Let XX be the score on one fair die. Find E[X]E[X] and Var⁡(X)\operatorname{Var}(X). Then find the mean and variance of 2X+12X+1, and of the total of two independent dice.
Show the worked answer
E[X]=216=72E[X]=\tfrac{21}{6}=\tfrac72. E[X2]=1+4+9+16+25+366=916E[X^2]=\tfrac{1+4+9+16+25+36}{6}=\tfrac{91}{6}, so Var⁡(X)=916−494=3512\operatorname{Var}(X)=\tfrac{91}{6}-\tfrac{49}{4}=\tfrac{35}{12}. For 2X+12X+1: mean 88, variance 4×3512=3534\times\tfrac{35}{12}=\tfrac{35}{3}. For two dice: mean 77, variance 2×3512=3562\times\tfrac{35}{12}=\tfrac{35}{6}. The trap: doubling one die and rolling two dice have the same mean but different variances, because two dice partly cancel each other out.

Needs a step first: 4

Learn it with an AI

Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.

Be my maths tutor. I'm learning "Random Variables, Expectation and Variance" (Core tier): A number decided by chance, summed up by its expectation (the long-run average) and its variance (how far it typically strays).
I already know: Conditional Probability.
Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away.
Finish by testing me with this: Let $X$ be the score on one fair die. Find $E[X]$ and $\operatorname{Var}(X)$. Then find the mean and variance of $2X+1$, and of the total of two independent dice.
Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.

On the way to

Recommended