Unit 4, lesson 22

Expected Value, Variance and Sums of Random Variables

How expected value and variance summarize a probability model, how the second moment and linearity of expectation simplify them, and how covariance and independence decide the variance of a sum.

  • Video 22
  • Discrete Random Variables and Models

A product is often assembled from parts whose sizes vary, and what matters is the total. If each part has a known average and a known spread, what are the average and the spread of the total? The average of the total follows from a rule that does not depend on how the parts are related, while its spread depends on how the parts vary together. This lesson defines expected value and variance for a probability model and shows exactly where independence and covariance enter.

Key terms

Expected value

Definition Let XX be a discrete random variable with PMF pXp_X. If ∑x∣x∣ pX(x)\sum_x \lvert x \rvert \, p_X(x) is finite, the expected value of XX is

E(X)=∑xx pX(x),E(X) = \sum_{x} x \, p_X(x),

with the sum running over the support of XX. The condition holds automatically when the support is finite. More generally, for a function gg the expected value of g(X)g(X) is E(g(X))=∑xg(x) pX(x)E(g(X)) = \sum_x g(x) \, p_X(x), provided ∑x∣g(x)∣ pX(x)\sum_x \lvert g(x) \rvert \, p_X(x) is finite. The expected value is also called the mean of XX and written μ\mu or μX\mu_X.

In plain words The expected value is a probability-weighted average of the possible values, the balance point of the PMF. Over many independent repetitions of the same model, the average of the observed values tends to settle near it. It need not be a value that XX can take, and a single trial need not come out near it.

Example Let XX be −1-1 with probability 1/41/4 and 11 with probability 3/43/4. Then

E(X)=(−1)⋅14+1⋅34=12.\begin{aligned} E(X) &= (-1) \cdot \tfrac14 + 1 \cdot \tfrac34 \\[0.4em] &= \tfrac12 . \end{aligned}

No single trial gives 1/21/2, since XX is always −1-1 or 11. The value 1/21/2 is the point where the two masses balance, closer to 11 because that value carries more probability.

Variance of a random variable

Definition Let XX be a discrete random variable whose second moment

E(X2)=∑xx2 pX(x)E(X^2) = \sum_x x^2 \, p_X(x)

is finite. Then the mean μ=E(X)\mu = E(X) is finite too, and the variance of XX is the expected squared deviation from the mean,

Var⁡(X)=E((X−μ)2).\operatorname{Var}(X) = E\bigl((X - \mu)^2\bigr).

The standard deviation is SD⁡(X)=Var⁡(X)\operatorname{SD}(X) = \sqrt{\operatorname{Var}(X)}. Expanding the square gives the identity

Var⁡(X)=E(X2)−(E(X))2.\operatorname{Var}(X) = E(X^2) - \bigl(E(X)\bigr)^2 .

The variance is never negative, and it equals 00 exactly when X=μX = \mu with probability 11. For constants aa and bb,

Var⁡(aX+b)=a2Var⁡(X),SD⁡(aX+b)=∣a∣SD⁡(X).\begin{gathered} \operatorname{Var}(aX + b) = a^2 \operatorname{Var}(X), \\[0.4em] \operatorname{SD}(aX + b) = \lvert a \rvert \operatorname{SD}(X). \end{gathered}

In plain words Variance measures spread as an average squared distance from the mean, so its unit is the square of the unit of XX, and the standard deviation returns to the original unit. The second moment measures squared distance from 00 instead of from the mean, which is why the two are equal exactly when the mean is 00. Shifting XX moves the mean but not the spread, and multiplying XX by aa multiplies the spread by ∣a∣\lvert a \rvert.

Example For the variable XX above, the deviations from μ=1/2\mu = 1/2 are −3/2-3/2 and 1/21/2, with squares 9/49/4 and 1/41/4, so

Var⁡(X)=94⋅14+14⋅34=34.\begin{aligned} \operatorname{Var}(X) &= \tfrac94 \cdot \tfrac14 + \tfrac14 \cdot \tfrac34 \\[0.4em] &= \tfrac{3}{4} . \end{aligned}

Both values of XX square to 11, so the second moment is E(X2)=1E(X^2) = 1, and the identity gives 1−(1/2)2=3/41 - (1/2)^2 = 3/4 again. The standard deviation is 3/2≈0.866\sqrt{3}/2 \approx 0.866.

Linearity of expectation

Definition Let XX and YY be random variables defined on the same sample space, with finite expected values, and let aa, bb and cc be constants. Then

E(aX+bY+c)=aE(X)+bE(Y)+c.\begin{aligned} &E(aX + bY + c) \\[0.4em] &\quad = aE(X) + bE(Y) + c . \end{aligned}

The rule extends to any finite sum, E(X1+⋯+Xn)=E(X1)+⋯+E(Xn)E(X_1 + \dots + X_n) = E(X_1) + \dots + E(X_n), and it holds whether or not the variables are independent. It applies to linear combinations. For a function gg that is not linear, E(g(X))E(g(X)) need not equal g(E(X))g(E(X)).

In plain words The mean of a total is the total of the means, whatever the relation between the parts, as long as each part has a finite mean. Doubling a quantity doubles its mean, and adding a constant adds the same constant to the mean.

Example Let YY have the same distribution as the variable XX above. Then E(X+Y)=12+12=1E(X + Y) = \tfrac12 + \tfrac12 = 1, whether YY is chosen independently of XX or Y=XY = X on every trial. For U=2X+1U = 2X + 1, linearity gives E(U)=2⋅12+1=2E(U) = 2 \cdot \tfrac12 + 1 = 2. Squaring is not linear, and indeed E(X2)=1E(X^2) = 1 while (E(X))2=14\bigl(E(X)\bigr)^2 = \tfrac14.

Independent random variables

Definition Discrete random variables XX and YY are independent if

P(X=x,Y=y)=P(X=x) P(Y=y)\begin{aligned} &P(X = x, Y = y) \\[0.4em] &\quad = P(X = x)\,P(Y = y) \end{aligned}

for every pair of values xx and yy. Equivalently, for every xx with P(X=x)>0P(X = x) > 0, the conditional distribution of YY given X=xX = x is the same as the distribution of YY. Several variables X1,…,XnX_1, \dots, X_n are independent if their joint probabilities factor in the same way for every list of values. If XX and YY are independent and have finite expected values, then E(XY)=E(X) E(Y)E(XY) = E(X)\,E(Y). An independent copy of XX is a random variable that is independent of XX and has the same distribution.

In plain words Independent variables carry no information about each other, so learning the value of one leaves the probabilities for the other unchanged. Having the same distribution is a different property. A variable and itself have the same distribution, but they are not independent unless the variable is constant with probability 11.

Example Let YY be an independent copy of XX. The four pairs of values have the probabilities in the table, each the product of the two separate probabilities.

Joint probabilityY=−1Y = -1Y=1Y = 1
X=−1X = -11/161/163/163/16
X=1X = 13/163/169/169/16

If instead Y=XY = X, the pair X=−1X = -1 and Y=1Y = 1 is impossible. Its probability is 00, while P(X=−1) P(Y=1)=3/16P(X = -1)\,P(Y = 1) = 3/16, so these two variables are not independent.

Covariance of random variables

Definition For random variables XX and YY with finite second moments and means μX\mu_X and μY\mu_Y, the covariance is

Cov⁡(X,Y)=E((X−μX)(Y−μY))=E(XY)−μXμY.\begin{aligned} &\operatorname{Cov}(X, Y) \\[0.4em] &\quad = E\bigl((X - \mu_X)(Y - \mu_Y)\bigr) \\[0.4em] &\quad = E(XY) - \mu_X \mu_Y . \end{aligned}

In particular Cov⁡(X,X)=Var⁡(X)\operatorname{Cov}(X, X) = \operatorname{Var}(X). Independent variables with finite second moments have covariance 00, because E(XY)=E(X) E(Y)E(XY) = E(X)\,E(Y). The converse is false. Covariance 00 does not imply independence, as the example below shows. When both standard deviations are positive, the correlation

Corr⁡(X,Y)=Cov⁡(X,Y)SD⁡(X)SD⁡(Y)\begin{aligned} &\operatorname{Corr}(X, Y) \\[0.4em] &\quad = \frac{\operatorname{Cov}(X, Y)}{\operatorname{SD}(X)\operatorname{SD}(Y)} \end{aligned}

lies between −1-1 and 11. These are quantities of the model. The sample covariance sxys_{xy} and the sample correlation rr are their counterparts computed from observed data.

In plain words Covariance averages the product of the two deviations from the means, weighting by probability. Deviations with the same sign give a positive product and deviations with opposite signs a negative one, so the covariance is positive when the same-sign products outweigh the others, negative when they are outweighed, and 00 when the two balance. Both the sizes of the deviations and how often each case occurs count. It reflects linear association, so even a strong curved relation can have covariance 00.

Example For Y=XY = X with XX as above, Cov⁡(X,X)=Var⁡(X)=3/4\operatorname{Cov}(X, X) = \operatorname{Var}(X) = 3/4 and the correlation is 11. For an independent copy, the table gives E(XY)=116−316−316+916=14=E(X) E(Y)E(XY) = \tfrac{1}{16} - \tfrac{3}{16} - \tfrac{3}{16} + \tfrac{9}{16} = \tfrac14 = E(X)\,E(Y), so the covariance is 00. To see that covariance 00 does not imply independence, let VV take the values −1-1, 00 and 11 with probability 1/31/3 each, and compare VV with its square V2V^2. Here E(V)=0E(V) = 0 and E(V⋅V2)=E(V3)=0E(V \cdot V^2) = E(V^3) = 0, so Cov⁡(V,V2)=0\operatorname{Cov}(V, V^2) = 0. Yet V2V^2 is determined by VV, and P(V=0,V2=0)=1/3P(V = 0, V^2 = 0) = 1/3 differs from P(V=0) P(V2=0)=1/9P(V = 0)\,P(V^2 = 0) = 1/9, so the two are not independent.

Variance of a sum

Definition For random variables XX and YY with finite second moments and constants aa and bb,

Var⁡(aX+bY)=a2Var⁡(X)+b2Var⁡(Y)+2abCov⁡(X,Y).\begin{aligned} &\operatorname{Var}(aX + bY) \\[0.4em] &\quad = a^2 \operatorname{Var}(X) \\[0.4em] &\qquad + b^2 \operatorname{Var}(Y) \\[0.4em] &\qquad + 2ab \operatorname{Cov}(X, Y). \end{aligned}

When Cov⁡(X,Y)=0\operatorname{Cov}(X, Y) = 0, in particular when XX and YY are independent, both X+YX + Y and X−YX - Y have variance Var⁡(X)+Var⁡(Y)\operatorname{Var}(X) + \operatorname{Var}(Y). For a sum of nn variables, the variance is the sum of the nn variances plus twice the sum of the covariances over all pairs. Standard deviations do not add in general. The equality SD⁡(X+Y)=SD⁡(X)+SD⁡(Y)\operatorname{SD}(X + Y) = \operatorname{SD}(X) + \operatorname{SD}(Y) holds exactly when Cov⁡(X,Y)=SD⁡(X)SD⁡(Y)\operatorname{Cov}(X, Y) = \operatorname{SD}(X)\operatorname{SD}(Y), which for two variables with positive standard deviations means correlation 11.

In plain words Variances add for uncorrelated parts, and the covariance term corrects for parts that move together or against each other. For two independent parts that both vary, their deviations from the means have the same sign in some trials and opposite signs in others, so the standard deviation of the total is smaller than the sum of the two standard deviations.

Example For an independent copy YY of XX, the sum X+YX + Y takes the values −2-2, 00 and 22 with probabilities 1/161/16, 6/166/16 and 9/169/16. Its mean is 11, and its variance is 3/4+3/4=3/23/4 + 3/4 = 3/2, which a direct computation from these three probabilities confirms. Its standard deviation is 3/2≈1.225\sqrt{3/2} \approx 1.225, less than SD⁡(X)+SD⁡(Y)=3≈1.732\operatorname{SD}(X) + \operatorname{SD}(Y) = \sqrt{3} \approx 1.732. If instead Y=XY = X, the sum is 2X2X, with the same mean 11 and variance

Var⁡(2X)=34+34+2⋅34=3,\begin{aligned} \operatorname{Var}(2X) &= \tfrac34 + \tfrac34 + 2 \cdot \tfrac34 \\[0.4em] &= 3, \end{aligned}

twice as large. Its standard deviation 3\sqrt{3} now equals the sum of the two standard deviations, because the correlation is 11.

Check yourself

  1. For the variable XX of this lesson, which is −1-1 with probability 1/41/4 and 11 with probability 3/43/4, let T=3X−2T = 3X - 2. Find E(T)E(T), Var⁡(T)\operatorname{Var}(T) and SD⁡(T)\operatorname{SD}(T). Why does the −2-2 change the mean but not the spread?
Show the answer

By linearity, E(T)=3⋅12−2=−12E(T) = 3 \cdot \tfrac12 - 2 = -\tfrac12. The variance is multiplied by 323^2, so Var⁡(T)=9⋅34=274=6.75\operatorname{Var}(T) = 9 \cdot \tfrac34 = \tfrac{27}{4} = 6.75, and the standard deviation is multiplied by 33, so SD⁡(T)=33/2≈2.598\operatorname{SD}(T) = 3\sqrt{3}/2 \approx 2.598. Subtracting 22 moves every value and the mean by the same amount, so every deviation from the mean stays the same. Multiplying by 33 triples every deviation, which multiplies every squared deviation by 99.

  1. Let ZZ be an independent copy of XX and W=X−ZW = X - Z. Someone argues that Var⁡(W)=Var⁡(X)−Var⁡(Z)=0\operatorname{Var}(W) = \operatorname{Var}(X) - \operatorname{Var}(Z) = 0. Find E(W)E(W) and Var⁡(W)\operatorname{Var}(W), and say when the variance of X−ZX - Z would be 00.
Show the answer

By linearity, E(W)=12−12=0E(W) = \tfrac12 - \tfrac12 = 0. The coefficient of ZZ is −1-1, and it enters the variance squared, so with covariance 00

Var⁡(W)=34+(−1)2⋅34=32.\begin{aligned} \operatorname{Var}(W) &= \tfrac34 + (-1)^2 \cdot \tfrac34 \\[0.4em] &= \tfrac32 . \end{aligned}

Directly, WW is −2-2 or 22 with probability 3/163/16 each and 00 with probability 10/1610/16, so E(W2)=4⋅616=32E(W^2) = 4 \cdot \tfrac{6}{16} = \tfrac32, which is Var⁡(W)\operatorname{Var}(W) because E(W)=0E(W) = 0. The argument fails because variances of independent parts add even in a difference. If instead Z=XZ = X on every trial, then W=0W = 0 always, and the formula gives 34+34−2⋅34=0\tfrac34 + \tfrac34 - 2 \cdot \tfrac34 = 0, the covariance term canceling both variances. More generally, the variance of X−ZX - Z is 00 exactly when X−ZX - Z is constant with probability 11, and for a ZZ with the same distribution as XX that constant must be 00.

  1. A product’s total length is T=A+B+CT = A + B + C, where each of the three parts has a standard deviation of 0.2 mm0.2\ \text{mm}. A colleague reports SD⁡(T)=0.6 mm\operatorname{SD}(T) = 0.6\ \text{mm}. Find SD⁡(T)\operatorname{SD}(T) when the three lengths are independent, and say when the colleague’s value would be right.
Show the answer

For independent parts all covariances are 00, so

Var⁡(T)=3⋅(0.2 mm)2=0.12 mm2,\begin{aligned} \operatorname{Var}(T) &= 3 \cdot (0.2\ \text{mm})^2 \\[0.4em] &= 0.12\ \text{mm}^2, \end{aligned}

and SD⁡(T)=0.12 mm≈0.346 mm\operatorname{SD}(T) = \sqrt{0.12}\ \text{mm} \approx 0.346\ \text{mm}. Adding the standard deviations gives 0.6 mm0.6\ \text{mm}, which is correct exactly when every pair of lengths has correlation 11, for example when the three parts always deviate from their means by the same amount. Then Var⁡(T)=9⋅0.04 mm2=0.36 mm2\operatorname{Var}(T) = 9 \cdot 0.04\ \text{mm}^2 = 0.36\ \text{mm}^2 and SD⁡(T)=0.6 mm\operatorname{SD}(T) = 0.6\ \text{mm}. The expected total length is the sum of the three expected lengths in either case.

How this lesson connects