Post · 7 min read· pp. 187–191

3.2.2 Expectation


Video Available Video Available

If you have a collection of numbers a1,a2,...,aNa_1,a_2,...,a_N, their average is a single number that describes the whole collection. Now, consider a random variable XX. We would like to define its average, or as it is called in probability, its expected value or mean. The expected value is defined as the weighted average of the values in the range.

Expected value (= mean=average): Definition Let XX be a discrete random variable with range RX={x1,x2,x3,...}R_X=\{x_1,x_2,x_3, ...\} (finite or countably infinite). The expected value of XX, denoted by EXEX is defined as

EX=∑xk∈RXxkP(X=xk)=∑xk∈RXxkPX(xk).EX=\sum_{x_k \in R_X} x_k P(X=x_k)=\sum_{x_k \in R_X} x_k P_X(x_k).

To understand the concept behind EXEX, consider a discrete random variable with range RX={x1,x2,x3,...}R_X=\{x_1,x_2,x_3, ...\}. This random variable is a result of random experiment. Suppose that we repeat this experiment a very large number of times NN, and that the trials are independent. Let N1N_1 be the number of times we observe x1x_1, N2N_2 be the number of times we observe x2x_2, ...., NkN_k be the number of times we observe xkx_k, and so on. Since P(X=xk)=PX(xk)P(X=x_k)=P_X(x_k), we expect that

PX(x1)≈N1N,P_X(x_1)\approx \frac{N_1}{N},
PX(x2)≈N2N,P_X(x_2)\approx \frac{N_2}{N},
...\hspace{10pt} . \hspace{20pt} . \hspace{20pt} .
PX(xk)≈NkN,P_X(x_k)\approx \frac{N_k}{N},
...\hspace{10pt} . \hspace{20pt} . \hspace{20pt} .
In other words, we have Nk≈NPX(xk)N_k \approx N P_X(x_k). Now, if we take the average of the observed values of XX, we obtain

Average \textrm{Average }=N1x1+N2x2+N3x3+...N=\frac{N_1 x_1+N_2 x_2+N_3 x_3+...}{N}
≈x1NPX(x1)+x2NPX(x2)+x3NPX(x3)+...N\approx \frac{x_1 N P_X(x_1)+x_2N P_X(x_2)+x_3N P_X(x_3)+...}{N}
=x1PX(x1)+x2PX(x2)+x3PX(x3)+...=x_1 P_X(x_1)+x_2 P_X(x_2)+x_3 P_X(x_3)+...
=EX.=EX.

Thus, the intuition behind EXEX is that if you repeat the random experiment independently NN times and take the average of the observed data, the average gets closer and closer to EXEX as NN gets larger and larger. We sometimes denote EXEX by μX\mu_X.

Different notations for expected value of XX: EX=E[X]=E(X)=μXEX=E[X]=E(X)=\mu_X.

Let's compute the expected values of some well-known distributions.


Example

Let X∼Bernoulli(p)X \sim Bernoulli(p). Find EXEX.

  • Solution
    • For the Bernoulli distribution, the range of XX is RX={0,1}R_X=\{0,1\}, and PX(1)=pP_X(1)=p and PX(0)=1−pP_X(0)=1-p. Thus,

      EXEX=0⋅PX(0)+1⋅PX(1)=0 \cdot P_X(0)+1 \cdot P_X(1)
      =0⋅(1−p)+1⋅p=0 \cdot (1-p)+ 1 \cdot p
      =p=p.

For a Bernoulli random variable, finding the expectation EXEX was easy. However, for some random variables, to find the expectation sum, you might need a little algebra. Let's look at another example.


Example

Let X∼Geometric(p)X \sim Geometric(p). Find EXEX.

  • Solution
    • For the geometric distribution, the range is RX={1,2,3,...}R_X=\{1,2,3,... \} and the PMF is given by

      PX(k)=qk−1p, for k=1,2,...P_X(k) = q^{k-1}p, \hspace{20pt} \text{ for } k=1,2,...
      where, $0 < p < 1$ and q=1−pq=1-p. Thus, we can write

      EXEX=∑xk∈RXxkPX(xk)=\sum_{x_k \in R_X} x_k P_X(x_k)
      =∑k=1∞kqk−1p=\sum_{k=1}^{\infty} k q^{k-1}p
      =p∑k=1∞kqk−1=p\sum_{k=1}^{\infty} k q^{k-1}.

      Now, we already know the geometric sum formula

      ∑k=0∞xk=11−x, for ∣x∣<1.\sum_{k=0}^{\infty} x^k= \frac{1}{1-x}, \hspace{20pt} \textrm{ for } |x| < 1.
      But we need to find a sum ∑k=1∞kqk−1\sum_{k=1}^{\infty} k q^{k-1}. Luckily, we can convert the geometric sum to the form we want by taking derivative with respect to xx, i.e.,
      ddx∑k=0∞xk=ddx11−x, for ∣x∣<1.\frac{d}{dx} \sum_{k=0}^{\infty} x^k= \frac{d}{dx} \frac{1}{1-x}, \hspace{20pt} \textrm{ for } |x| < 1.
      Thus, we have
      ∑k=0∞kxk−1=1(1−x)2, for ∣x∣<1.\sum_{k=0}^{\infty} k x^{k-1}= \frac{1}{(1-x)^2}, \hspace{20pt} \textrm{ for } |x| < 1.
      To finish finding the expectation, we can write

      EXEX=p∑k=1∞kqk−1=p\sum_{k=1}^{\infty} k q^{k-1}
      =p1(1−q)2=p \frac{1}{(1-q)^2}
      =p1p2=p \frac{1}{p^2}
      =1p=\frac{1}{p}.

      So, for X∼Geometric(p)X \sim Geometric(p), EX=1pEX=\frac{1}{p}. Note that this makes sense intuitively. The random experiment behind the geometric distribution was that we tossed a coin until we observed the first heads, where P(H)=pP(H)=p. Here, we found out that on average you need to toss the coin 1p\frac{1}{p} times in this experiment. In particular, if pp is small (heads are unlikely), then 1p\frac{1}{p} is large, so you need to toss the coin a large number of times before you observe a heads. Conversely, for large pp a few coin tosses usually suffices.


Example

Let X∼Poisson(λ)X \sim Poisson(\lambda). Find EXEX.

  • Solution
    • Before doing the math, we suggest that you try to guess what the expected value would be. It might be a good idea to think about the examples where the Poisson distribution is used. For the Poisson distribution, the range is RX={0,1,2,⋯ }R_X=\{0,1,2,\cdots \} and the PMF is given by

      PX(k)=e−λλkk!, for k=0,1,2,...P_X(k) = \frac{e^{-\lambda} \lambda^k}{k!}, \hspace{20pt} \text{ for } k=0,1,2,...
      Thus, we can write

      EXEX=∑xk∈RXxkPX(xk)=\sum_{x_k \in R_X} x_k P_X(x_k)
      =∑k=0∞ke−λλkk!= \sum_{k=0}^{\infty} k \frac{e^{-\lambda} \lambda^k}{k!}
      =e−λ∑k=1∞λk(k−1)!=e^{-\lambda} \sum_{k=1}^{\infty} \frac{ \lambda^k}{(k-1)!}
      =e−λ∑j=0∞λ(j+1)j!=e^{-\lambda} \sum_{j=0}^{\infty} \frac{\lambda^{(j+1)}}{j!}( by letting j=k−1)(\textrm{ by letting }j=k-1)
      =λe−λ∑j=0∞λjj!=\lambda e^{-\lambda} \sum_{j=0}^{\infty} \frac{ \lambda^j}{j!}
      =λe−λeλ=\lambda e^{-\lambda} e^{\lambda}( Taylor series for eλ)(\textrm{ Taylor series for } e^{\lambda})
      =λ=\lambda.

      So the expected value is λ\lambda. Remember, when we first talked about the Poisson distribution, we introduced its parameter λ\lambda as the average number of events. So it is not surprising that the expected value is EX=λEX=\lambda.


Before looking at more examples, we would like to talk about an important property of expectation, which is linearity. Note that if XX is a random variable, any function of XX is also a random variable, so we can talk about its expected value. For example, if Y=aX+bY=aX+b, we can talk about EY=E[aX+b]EY=E[aX+b]. Or if you define Y=X1+X2+⋯+XnY=X_1+X_2+\cdots+X_n, where XiX_i's are random variables, we can talk about EY=E[X1+X2+⋯+Xn]EY=E[X_1+X_2+\cdots+X_n]. The following theorem states that expectation is linear, which makes it easier to calculate the expected value of linear functions of random variables.

Expectation is linear: Theorem We have

  • E[aX+b]=aEX+bE[aX+b]=aEX+b, for all a,b∈Ra,b \in \mathbb{R};
  • E[X1+X2+⋯+Xn]=EX1+EX2+⋯+EXnE[X_1+X_2+\cdots+X_n]=EX_1+EX_2+\cdots+EX_n, for any set of random variables X1,X2,⋯ ,XnX_1, X_2,\cdots,X_n.

We will prove this theorem later on in Chapter 5, but here we would like to emphasize its importance with an example.


Example

Let X∼Binomial(n,p)X \sim Binomial(n,p). Find EXEX.

  • Solution
    • We provide two ways to solve this problem. One way is as before: we do the math and calculate EX=∑xk∈RXxkPX(xk)EX=\sum_{x_k \in R_X} x_k P_X(x_k) which will be a little tedious. A much faster way would be to use linearity of expectation. In particular, remember that if X1,X2,...,XnX_1, X_2, ...,X_n are independent Bernoulli(p)Bernoulli(p) random variables, then the random variable XX defined by X=X1+X2+...+XnX=X_1+X_2+...+X_n has a Binomial(n,p)Binomial(n,p) distribution. Thus, we can write

      EXEX=E[X1+X2+⋯+Xn]=E[X_1+X_2+\cdots+X_n]
      =EX1+EX2+⋯+EXn=EX_1+EX_2+\cdots+EX_nby linearity of expectation\hspace{20pt} \textrm{by linearity of expectation}
      =p+p+⋯+p=p+p+\cdots+p
      =np=np.

      We will provide the direct calculation of EX=∑xk∈RXxkPX(xk)EX=\sum_{x_k \in R_X} x_k P_X(x_k) in the Solved Problems section and as you will see it needs a lot more algebra than above. The bottom line is that linearity of expectation can sometimes make our calculations much easier. Let's look at another example.


Example

Let X∼Pascal(m,p)X \sim Pascal(m,p). Find EXEX. (Hint: Try to write X=X1+X2+⋯+XmX=X_1+X_2+\cdots+X_m, such that you already know EXiEX_i.)

  • Solution
    • We claim that if the XiX_i's are independent and Xi∼Geometric(p)X_i \sim Geometric(p), for i=1i=1, $2$, ⋯\cdots, mm, then the random variable XX defined by X=X1+X2+⋯+XmX=X_1+X_2+\cdots+X_m has Pascal(m,p)Pascal(m,p). To see this, you can look at Problem 5 in Section 3.1.6 and the discussion there. Now, since we already know EXi=1pEX_i=\frac{1}{p}, we conclude

      EXEX=E[X1+X2+⋯+Xm]=E[X_1+X_2+\cdots+X_m]
      =EX1+EX2+⋯+EXm=EX_1+EX_2+\cdots+EX_mby linearity of expectation\hspace{20pt} \textrm{by linearity of expectation}
      =1p+1p+⋯+1p=\frac{1}{p}+\frac{1}{p}+\cdots+\frac{1}{p}
      =mp=\frac{m}{p}.

      Again, you can try to find EXEX directly and as you will see, you need much more algebra compared to using the linearity of expectation.