Unit 5, lesson 31

Linearity of Expectation

Why the expected value of a sum or linear combination is the same combination of expected values when each is finite, with no independence needed, and why products and squares need their own calculation.

  • Video 31
  • Linearity and Indicators

A repair visit has two parts, finding the fault and fixing it, and a quick diagnosis often comes with a long repair. To plan for the expected length of a visit, do you need the distribution of the total time, or a guarantee that the two parts are independent? You need neither. This lesson shows that the expectation of a sum is the sum of the expectations whenever those expectations are finite, whatever the dependence between the terms, and it marks where the shortcut stops, at products and squares.

Key terms

Finite expectation

Definition A random variable XX has finite expectation when E[∣X∣]<∞E[\lvert X \rvert] < \infty. For a discrete variable with PMF pXp_X this means

∑x∣x∣ pX(x)<∞,\sum_{x} \lvert x \rvert \, p_X(x) < \infty,

and then E[X]=∑xx pX(x)E[X] = \sum_x x \, p_X(x) is a real number that does not depend on the order in which the terms are added. A variable with finitely many possible values has finite expectation, and so does every bounded variable. When E[∣X∣]=∞E[\lvert X \rvert] = \infty, the expectation is +∞+\infty, −∞-\infty or undefined, and the rules on this page are stated only for finite expectations.

In plain words Before an expected value is used in arithmetic, check that it is an actual number. A valid distribution on infinitely many values can still have a weighted sum of values that grows without bound, and two infinite expectations of opposite sign cannot be combined into a meaningful answer.

Example Let XX take the value nn with probability 1n(n+1)\frac{1}{n(n+1)} for n=1,2,3,…n = 1, 2, 3, \dots. These probabilities add to 11, because 1n(n+1)=1n−1n+1\frac{1}{n(n+1)} = \frac{1}{n} - \frac{1}{n+1} and the sum telescopes. Yet

E[X]=∑n=1∞nn(n+1)=∑n=1∞1n+1=∞.\begin{aligned} E[X] &= \sum_{n=1}^{\infty} \frac{n}{n(n+1)} \\[0.4em] &= \sum_{n=1}^{\infty} \frac{1}{n+1} = \infty . \end{aligned}

Now let Y=−XY = -X. The sum X+YX + Y is the constant 00, so E[X+Y]=0E[X + Y] = 0, but the expression E[X]+E[Y]E[X] + E[Y] would read ∞+(−∞)\infty + (-\infty), which has no value.

Expectation of a sum

Definition Let XX and YY be random variables defined on the same probability model, each with finite expectation. Then X+YX + Y has finite expectation and

E[X+Y]=E[X]+E[Y].E[X + Y] = E[X] + E[Y].

No independence is assumed. To see why in a model with finitely many outcomes ω1,…,ωm\omega_1, \dots, \omega_m, write pi=P({ωi})p_i = P(\{\omega_i\}), xi=X(ωi)x_i = X(\omega_i) and yi=Y(ωi)y_i = Y(\omega_i). An expectation can be computed outcome by outcome, since grouping the outcomes that give the same value returns the PMF formula. So

E[X+Y]=∑ipi(xi+yi)=∑ipixi+∑ipiyi=E[X]+E[Y].\begin{aligned} E[X + Y] &= \sum_{i} p_i (x_i + y_i) \\[0.4em] &= \sum_{i} p_i x_i + \sum_{i} p_i y_i \\[0.4em] &= E[X] + E[Y]. \end{aligned}

The same splitting works with countably many outcomes, because finite expectations make both series absolutely convergent, and the rule holds for random variables in general, discrete or not.

In plain words To average a total, average each part and add. Which values of XX occur together with which values of YY matters for the distribution of X+YX + Y, but not for its mean.

Example Three equally likely job types give the task durations (X,Y)=(1,4)(X, Y) = (1, 4), (2,2)(2, 2) and (5,0)(5, 0) in hours. The separate means are E[X]=1+2+53=83E[X] = \frac{1 + 2 + 5}{3} = \frac{8}{3} and E[Y]=4+2+03=2E[Y] = \frac{4 + 2 + 0}{3} = 2. The totals X+YX + Y are 55, 44 and 55, so the direct calculation gives E[X+Y]=143E[X + Y] = \frac{14}{3}, which equals 83+2\frac{8}{3} + 2. The durations are strongly dependent, since the value of XX identifies the job type and therefore fixes YY, and the rule holds anyway.

Linearity of expectation

Definition A linear combination of random variables X1,…,XnX_1, \dots, X_n is a random variable a1X1+⋯+anXna_1X_1 + \cdots + a_nX_n, where the number of terms nn is fixed and the coefficients a1,…,ana_1, \dots, a_n are fixed real numbers. Linearity of expectation states that if X1,…,XnX_1, \dots, X_n are defined on the same probability model and each has finite expectation, then for every fixed real number cc the variable a1X1+⋯+anXn+ca_1X_1 + \cdots + a_nX_n + c has finite expectation and

E[ ∑i=1naiXi+c]=∑i=1naiE[Xi]+c.\begin{aligned} &E\Bigl[\,\sum_{i=1}^{n} a_i X_i + c\Bigr] \\[0.4em] &\qquad = \sum_{i=1}^{n} a_i E[X_i] + c . \end{aligned}

It follows from the sum rule applied repeatedly, together with E[aX]=aE[X]E[aX] = aE[X], since every value is multiplied by aa, and E[c]=cE[c] = c, since the probabilities add to 11. Negative coefficients are allowed, so E[X−Y]=E[X]−E[Y]E[X - Y] = E[X] - E[Y]. The number of terms has to be fixed. A sum with a random number of terms needs its own argument about how the count and the terms are related.

In plain words Expectation passes through sums, constant multiples and added constants. Combine the means in the same way the variables are combined, and ignore any dependence between them.

Example In the job table above, a fixed preparation time of half an hour adds 12\frac12 to every total, so the expected total becomes 143+12=316\frac{14}{3} + \frac{1}{2} = \frac{31}{6} hours. A charge of 33 tokens per hour of task XX, less a discount of 22 tokens, is C=3X−2C = 3X - 2, and linearity gives E[C]=3⋅83−2=6E[C] = 3 \cdot \frac{8}{3} - 2 = 6 tokens. Directly, the three charges are 11, 44 and 1313 tokens, whose average is 183=6\frac{18}{3} = 6.

Expectation of a product

Definition For random variables XX and YY on the same probability model, E[XY]E[XY] is the expectation of the single random variable XYXY, whose value on each outcome is the product of the values of XX and YY. In a finite outcome table with the notation above,

E[XY]=∑ipi xiyi,E[XY] = \sum_{i} p_i \, x_i y_i ,

which depends on which values occur together. In general E[XY]E[XY] need not equal E[X]E[Y]E[X]E[Y]. If XX and YY are independent and both have finite expectations, then E[XY]=E[X]E[Y]E[XY] = E[X]E[Y], a separate product rule with its own hypothesis. The converse is false, so the equation E[XY]=E[X]E[Y]E[XY] = E[X]E[Y] does not show that XX and YY are independent. Finite expectations of XX and YY also do not guarantee a finite E[XY]E[XY], for example when Y=XY = X and E[X2]=∞E[X^2] = \infty.

In plain words Linearity covers adding and scaling, not multiplying. The average of a product depends on whether large values of one variable come with large or with small values of the other, and multiplying two separate averages throws that information away.

Example In the job table, the products XYXY are 44, 44 and 00 square hours, so E[XY]=83E[XY] = \frac{8}{3}. The product of the means is 83⋅2=163\frac{8}{3} \cdot 2 = \frac{16}{3}, twice as large. Long first tasks come with short second tasks here, and that pairing makes the average product smaller than the product of the averages.

Expectation of a square

Definition The expectation of the square of XX is E[X2]E[X^2], the expectation of the random variable X2X^2. For a discrete variable,

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

a sum of nonnegative terms that is either a finite number or +∞+\infty. It should not be confused with the square of the expectation, (E[X])2(E[X])^2. More generally, E[g(X)]E[g(X)] averages the values g(x)g(x), while g(E[X])g(E[X]) applies gg to a single number. The two agree for every XX with finite expectation when g(x)=ax+bg(x) = ax + b, by linearity, but they can differ for other functions, and g(x)=x2g(x) = x^2 is the standard example. For XX with finite expectation, the difference E[X2]−(E[X])2E[X^2] - (E[X])^2 is the variance, the subject of a later lesson in this unit.

In plain words Read the brackets. Squaring each outcome and then averaging is a different instruction from averaging and then squaring. Squaring first lets outcomes far from zero count more heavily, and when XX has finite expectation the two results agree only if XX equals one value with probability one.

Example In the job table, X2X^2 takes the values 11, 44 and 2525, so E[X2]=303=10E[X^2] = \frac{30}{3} = 10. Squaring the mean gives (83)2=649(\frac{8}{3})^2 = \frac{64}{9}, about 7.117.11. Both numbers are well defined, and they answer different questions.

Check yourself

  1. Three scenarios have probabilities 0.20.2, 0.50.5 and 0.30.3 and give the paired durations (A,B)=(0,5)(A, B) = (0, 5), (4,1)(4, 1) and (6,3)(6, 3) in hours. Find E[2A+B]E[2A + B] with linearity, then check it directly from the rows.
Show the answer

The separate means are E[A]=0⋅0.2+4⋅0.5+6⋅0.3=3.8E[A] = 0 \cdot 0.2 + 4 \cdot 0.5 + 6 \cdot 0.3 = 3.8 hours and E[B]=5⋅0.2+1⋅0.5+3⋅0.3=2.4E[B] = 5 \cdot 0.2 + 1 \cdot 0.5 + 3 \cdot 0.3 = 2.4 hours. Linearity gives E[2A+B]=2⋅3.8+2.4=10E[2A + B] = 2 \cdot 3.8 + 2.4 = 10 hours. Directly, the rows give 2A+B=52A + B = 5, 99 and 1515, and the weighted average is 5⋅0.2+9⋅0.5+15⋅0.3=1+4.5+4.5=105 \cdot 0.2 + 9 \cdot 0.5 + 15 \cdot 0.3 = 1 + 4.5 + 4.5 = 10 hours. The two durations are not assumed independent, and neither calculation needs that.

  1. A fair die is rolled. Let XX be the number shown and Y=7−XY = 7 - X the number on the opposite face. Find E[X+Y]E[X + Y], E[XY]E[XY] and E[X]E[Y]E[X]E[Y].
Show the answer

The sum X+YX + Y equals 77 on every outcome, so E[X+Y]=7E[X + Y] = 7, in agreement with E[X]+E[Y]=72+72E[X] + E[Y] = \frac72 + \frac72. For the product, write XY=7X−X2XY = 7X - X^2. The second moment is E[X2]=1+4+9+16+25+366=916E[X^2] = \frac{1 + 4 + 9 + 16 + 25 + 36}{6} = \frac{91}{6}, so linearity gives

E[XY]=7E[X]−E[X2]=492−916=283.\begin{aligned} E[XY] &= 7E[X] - E[X^2] \\[0.4em] &= \frac{49}{2} - \frac{91}{6} = \frac{28}{3}. \end{aligned}

Directly, the six products are 66, 1010, 1212, 1212, 1010 and 66, with average 566=283\frac{56}{6} = \frac{28}{3}. The product of the means is (72)2=494=12.25(\frac72)^2 = \frac{49}{4} = 12.25, larger than 283≈9.33\frac{28}{3} \approx 9.33. Linearity applies to the sum and to 7X−X27X - X^2, but not to the product X⋅YX \cdot Y itself.

  1. Let XX take the values −1-1, 00 and 11 with probability 13\frac13 each, and let Y=X2Y = X^2. Show that E[XY]=E[X]E[Y]E[XY] = E[X]E[Y]. Are XX and YY independent?
Show the answer

The product XY=X3XY = X^3 equals XX on every outcome, because each possible value satisfies x3=xx^3 = x. So E[XY]=E[X]=0E[XY] = E[X] = 0, and also E[X]E[Y]=0⋅23=0E[X]E[Y] = 0 \cdot \frac23 = 0. The two sides agree. The variables are still dependent, since YY is determined by XX and is not constant. For instance, P(X=0,Y=0)=13P(X = 0, Y = 0) = \frac13, while P(X=0)P(Y=0)=13⋅13=19P(X = 0)P(Y = 0) = \frac13 \cdot \frac13 = \frac19. Independence implies the product rule, but the product rule alone does not imply independence.

How this lesson connects