James's Math Hub
Statistics & Probability

Lesson 6 / 13 · 12 min read

Random Variables & Expected Value

Probability distributions, expected value, and the variance of a random variable.

What is a random variable?

A random variable XX assigns a number to each outcome of a random process. Discrete random variables take countable values (a dice roll, a count of successes); continuous ones take any value in a range (a height, a waiting time).

Probability distribution

For a discrete random variable, the distribution lists each value with its probability. Every probability is between 0 and 1, and they sum to 1.

Example. XX = the number on a fair die. P(X=k)=16P(X = k) = \frac{1}{6} for k=1,2,,6k = 1, 2, \ldots, 6.

Expected value (the mean of a random variable)

E[X]=μ=ixiP(xi)E[X] = \mu = \sum_i x_i\, P(x_i)

It's the long-run average if you repeated the process forever — each value weighted by its probability.

Example (fair die). E[X]=(1+2+3+4+5+6)16=216=3.5E[X] = (1 + 2 + 3 + 4 + 5 + 6)\cdot\frac{1}{6} = \frac{21}{6} = 3.5.

Example (a game). Win $5 with probability 0.20.2, otherwise lose $2:

E[profit]=0.2(5)+0.8(2)=11.6=0.6E[\text{profit}] = 0.2(5) + 0.8(-2) = 1 - 1.6 = -0.6

You lose about 60 cents per play on average.

Variance and standard deviation

Variance measures spread around the mean:

Var(X)=σ2=i(xiμ)2P(xi)\mathrm{Var}(X) = \sigma^2 = \sum_i (x_i - \mu)^2\, P(x_i)

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

Example. XX pays 00 with probability 0.50.5 and 1010 with probability 0.50.5. Then μ=5\mu = 5, and

Var(X)=(05)2(0.5)+(105)2(0.5)=12.5+12.5=25\mathrm{Var}(X) = (0-5)^2(0.5) + (10-5)^2(0.5) = 12.5 + 12.5 = 25

so σ=5\sigma = 5.

Transformation rules

For constants aa and bb:

E[aX+b]=aE[X]+bE[aX + b] = a\,E[X] + b Var(aX+b)=a2Var(X)\mathrm{Var}(aX + b) = a^2\,\mathrm{Var}(X)

Adding a constant shifts the mean but leaves the spread alone; multiplying scales the mean by aa and the variance by a2a^2.

Sums of random variables

E[X+Y]=E[X]+E[Y](always)E[X + Y] = E[X] + E[Y] \quad (\text{always}) Var(X+Y)=Var(X)+Var(Y)(if independent)\mathrm{Var}(X + Y) = \mathrm{Var}(X) + \mathrm{Var}(Y) \quad (\text{if independent})

Means always add. Variances add only when the variables are independent.

Key takeaways

  • A random variable turns outcomes into numbers, with a probability distribution that sums to 1.
  • E[X]=xiP(xi)E[X] = \sum x_i\,P(x_i) is the long-run average.
  • Var(X)=(xiμ)2P(xi)\mathrm{Var}(X) = \sum (x_i - \mu)^2 P(x_i); σ\sigma is its square root.
  • E[aX+b]=aE[X]+bE[aX + b] = aE[X] + b and Var(aX+b)=a2Var(X)\mathrm{Var}(aX + b) = a^2\mathrm{Var}(X).
  • Means always add; variances add for independent variables.