Expectation and Variance

Load a die face by face and watch the two numbers that summarise any random quantity move.

Expectation and Variance

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

Expectation is the probability-weighted average: E[X] = Σ x · P(x).
It is a balance point, not a prediction. A fair die has E[X] = 3.5, a value it can never roll.
Variance is the expected squared distance from the mean: E[(X − μ)²].
Expectation is linear no matter what. Variance only adds across independent variables — a distinction that matters constantly.

Overview

Average and spread

For a discrete random variable X, the expected value weights each outcome by its probability: E[X] = Σₓ xP(X=x). Variance is the expected squared deviation from the mean, and standard deviation is its square root:

Var(X) = E[(X−E[X])²]   σ = √Var(X)

For a fair six-sided die, E[X] = 3.5 and Var(X) = 35/12. The mean need not be a possible outcome; it summarises the distribution, not a prediction of one roll.

In this guide
  1. Rules that simplify calculations
  2. Calculate the mean and spread of a distribution
  3. Try this above
  4. Sources and next steps

Expectation and Variance

Expectation is a distribution’s long-run average; variance measures how far values spread around that average.

Rules that simplify calculations

Expectation is linear: E[aX+bY] = aE[X]+bE[Y], whether or not X and Y are independent. Variance is different: Var(X+Y) = Var(X)+Var(Y)+2Cov(X,Y). Only when covariance is zero does it reduce to the sum of variances; independence is sufficient but not necessary. See covariance and correlation.

Variance is measured in squared units, while standard deviation returns to the original units. The mean, variance, and standard deviation lesson shows how these summaries are calculated from data.

Calculate the mean and spread of a distribution

For a fair die, each result 1 through 6 has probability 1/6. The expectation is (1+2+3+4+5+6)/6=3.5. To calculate variance, find each result's distance from 3.5, square those distances, and average: Var(X)=[(−2.5)²+(−1.5)²+(−0.5)²+(0.5)²+(1.5)²+(2.5)²]/6=35/12. The standard deviation is √(35/12), about 1.71. A single roll remains an integer; expectation is a distribution average, not a prediction of one roll.

Expanding the squared deviation gives the shortcut Var(X)=E[X²]−(E[X])². For aX+b, the expectation is aE[X]+b, while variance is a²Var(X): shifting every result leaves spread unchanged, and scaling results by a multiplies variance by a². For sums, Var(X+Y)=Var(X)+Var(Y)+2Cov(X,Y), so variances add directly only when covariance is zero. Independence is sufficient for zero covariance when moments exist, but it is not necessary. These distinctions prevent an incorrect assumption that all random variables in a sum are independent.

Try this above

Change the probability assigned to each outcome. Watch the mean move and compare the spread with the distribution’s shape.

For a continuous random variable, replace the probability-weighted sum with an integral against the probability density: E[X]=∫x f(x)dx, when the integral exists. The same idea applies: outcomes with more probability contribute more to the average. Variance is finite only when the second moment exists. Some heavy-tailed distributions have a defined mean but infinite variance, so standard-deviation-based summaries and the usual central limit theorem may fail. Check existence conditions before applying algebraic rules to an unusual distribution.

For independent X and Y, covariance is zero and Var(X+Y)=Var(X)+Var(Y). If they are perfectly positively related, the covariance term increases the sum's variance; if they tend to move oppositely, it can reduce it. For example, adding two measurements from the same process is not equivalent to adding two independent outcomes. Check the dependence structure before applying the shortcut. The expectation's linearity is more general: E[X+Y]=E[X]+E[Y] does not require independence, which is a useful contrast to variance.

Sources and next steps

Check yourself

0 of 3

Answer without scrolling back up.

  1. A fair die has E[X] = 3.5. What does that tell you?

  2. When does Var(X + Y) = Var(X) + Var(Y)?

  3. Why is Var(X) = E[X^2] - (E[X])^2 numerically dangerous?

Cheat sheet

Expectation and Variance

Calculate expected value and variance from a probability distribution. Apply the linearity and independence rules that simplify real problems.

MATHS · vizlearn.in/maths/expectation_and_variance.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.