Post · 6 min read· pp. 195–198

3.2.4 Variance


Video Available Video Available

Consider two random variables XX and YY with the following PMFs.

\labeleq:X−varPX(x)={0.5for x=−1000.5for x=1000otherwise(3.3)\label{eq:X-var} \nonumber P_X(x) = \left\{ \begin{array}{l l} 0.5 & \quad \text{for } x=-100\\ 0.5 & \quad \text{for } x=100\\ 0 & \quad \text{otherwise} \end{array} \right. \hspace{10pt} (3.3)

\labeleq:Y−varPY(y)={1for y=00otherwise(3.4)\label{eq:Y-var} \nonumber P_Y(y) = \left\{ \begin{array}{l l} 1 & \quad \text{for } y=0\\ 0 & \quad \text{otherwise} \end{array} \right. \hspace{20pt} (3.4)

Note that EX=EY=0EX=EY=0. Although both random variables have the same mean value, their distribution is completely different. YY is always equal to its mean of $0$, while XX is either $100$ or −100-100, quite far from its mean value. The variance is a measure of how spread out the distribution of a random variable is. Here, the variance of YY is quite small since its distribution is concentrated at a single value, while the variance of XX will be larger since its distribution is more spread out.

The variance of a random variable XX, with mean EX=μXEX=\mu_X, is defined as

Var(X)=E[(X−μX)2].\textrm{Var}(X)=E\big[ (X-\mu_X)^2\big].

By definition, the variance of XX is the average value of (X−μX)2(X-\mu_X)^2. Since (X−μX)2≥0(X-\mu_X)^2 \geq 0, the variance is always larger than or equal to zero. A large value of the variance means that (X−μX)2(X-\mu_X)^2 is often large, so XX often takes values far from its mean. This means that the distribution is very spread out. On the other hand, a low variance means that the distribution is concentrated around its average.

Note that if we did not square the difference between XX and its mean, the result would be $0$. That is

E[X−μX]=EX−E[μX]=μX−μX=0.E[X-\mu_X]=EX-E[\mu_X]=\mu_X-\mu_X=0.
XX is sometimes below its average and sometimes above its average. Thus, X−μXX-\mu_X is sometimes negative and sometimes positive, but on average it is zero.

To compute Var(X)=E[(X−μX)2]Var(X)=E\big[ (X-\mu_X)^2\big], note that we need to find the expected value of g(X)=(X−μX)2g(X)=(X-\mu_X)^2, so we can use LOTUS. In particular, we can write

Var(X)=E[(X−μX)2]=∑xk∈RX(xk−μX)2PX(xk).\textrm{Var}(X)=E\big[ (X-\mu_X)^2\big]=\sum_{x_k \in R_X} (x_k-\mu_X)^2 P_X(x_k).
For example, for XX and YY defined in Equations 3.3 and 3.4, we have
Var(X)=(−100−0)2(0.5)+(100−0)2(0.5)=10,000\textrm{Var}(X)=(-100-0)^2(0.5)+(100-0)^2(0.5)=10,000
Var(Y)=(0−0)2(1)=0.\textrm{Var}(Y)=(0-0)^2(1)=0.

As we expect, XX has a very large variance while Var(Y)=0(Y)=0.

Note that Var(X)(X) has a different unit than XX. For example, if XX is measured in metersmeters then Var(X)(X) is in meters2meters^2. To solve this issue, we define another measure, called the standard deviation, usually shown as σX\sigma_X, which is simply the square root of variance.

The standard deviation of a random variable XX is defined as

SD(X)=σX=Var(X).\textrm{SD}(X)= \sigma_X= \sqrt {\textrm{Var}(X)}.

The standard deviation of XX has the same unit as XX. For XX and YY defined in Equations 3.3 and 3.4, we have

σX\sigma_X=10,000=100=\sqrt{10,000}= 100
σY\sigma_Y=0=0=\sqrt{0}=0.

Here is a useful formula for computing the variance.

Computational formula for the variance:

Var(X)=E[X2]−[EX]2(3.5)\hspace{70pt} \textrm{Var}(X)=E\big[X^2\big]-\big[EX\big]^2 \hspace{70pt} (3.5)

To prove it note that \begin{align}%\label{} \nonumber \textrm{Var}(X) &= E\big[ (X-\mu_X)^2\big]\ \nonumber &= E \big[ X^2-2 \mu_X X + \mu_X^2 \big]\ \nonumber &= E\big[X^2\big]-2E\big[\mu_X X\big]+E\big[\mu_X^2\big] &\textrm{ by linearity of expectation.} \end{align}

Note that for a given random variable XX, μX\mu_X is just a constant real number. Thus, E[μXX]=μXE[X]=μX2E\big[\mu_X X\big]=\mu_X E[X]=\mu_X^2, and E[μX2]=μX2E[\mu_X^2 \big]=\mu_X^2, so we have

\begin{align}%\label{} \nonumber\textrm{Var}(X) &= E\big[X^2\big]-2\mu_X^2+\mu_X^2\ \nonumber &= E\big[X^2\big]-\mu_X^2. \end{align}

Equation 3.5 is usually easier to work with compared to Var(X)=E[(X−μX)2]\textrm{Var}(X)=E\big[ (X-\mu_X)^2\big]. To use this equation, we can find E[X2]=EX2E[X^2]=EX^2 using LOTUS

EX2=∑xk∈RXxk2PX(xk),E X^2=\sum_{x_k \in R_X} x_k^2 P_X(x_k),
and then subtract μX2\mu_X^2 to obtain the variance.


Example

I roll a fair die and let XX be the resulting number. Find EXEX, Var(X)(X), and σX\sigma_X.

  • Solution
    • We have RX={1,2,3,4,5,6}R_X=\{1,2,3,4,5,6\} and PX(k)=16P_X(k)=\frac{1}{6} for k=1,2,...,6k=1,2,...,6. Thus, we have
      EX=1⋅16+2⋅16+3⋅16+4⋅16+5⋅16+6⋅16=72;EX=1 \cdot \frac{1}{6}+ 2 \cdot \frac{1}{6}+ 3 \cdot \frac{1}{6}+ 4 \cdot \frac{1}{6}+ 5 \cdot \frac{1}{6}+ 6 \cdot \frac{1}{6}=\frac{7}{2};
      EX2=1⋅16+4⋅16+9⋅16+16⋅16+25⋅16+36⋅16=916.EX^2=1 \cdot \frac{1}{6}+ 4\cdot \frac{1}{6}+ 9\cdot \frac{1}{6}+ 16 \cdot \frac{1}{6}+ 25\cdot \frac{1}{6}+ 36 \cdot \frac{1}{6}=\frac{91}{6}.
      Thus
      Var(X)=E[X2]−(EX)2=916−(72)2=916−494≈2.92,\textrm{Var}(X)=E\big[X^2\big]-\big(EX\big)^2=\frac{91}{6}-\left(\frac{7}{2}\right)^2=\frac{91}{6}-\frac{49}{4}\approx 2.92,
      σX=Var(X)≈2.92≈1.71\sigma_X= \sqrt {\textrm{Var}(X)}\approx \sqrt{2.92} \approx 1.71

Note that variance is not a linear operator. In particular, we have the following theorem.

Theorem For a random variable XX and real numbers aa and bb,

Var(aX+b)=a2Var(X)(3.6)\hspace{70pt} \textrm{Var}(aX+b)=a^2 \textrm{Var}(X) \hspace{70pt} (3.6)

Proof

If Y=aX+bY=aX+b, EY=aEX+bEY=aEX+b. Thus, \begin{align}%\label{} \nonumber \textrm{Var} (Y) &= E[ (Y-EY)^2 ]\ \nonumber &= E[ (aX+b-aEX-b)^2 ]\ \nonumber &= E[a^2(X-\mu_X)^2]\ \nonumber &= a^2 E[(X-\mu_X)^2]\ \nonumber &= a^2 \textrm{Var}(X)\ \end{align}

From Equation 3.6, we conclude that, for standard deviation, SD(aX+b)=∣a∣SD(X)\textrm{SD}(aX+b)=|a|\textrm{SD}(X). We mentioned that variance is NOT a linear operation. But there is a very important case, in which variance behaves like a linear operation and that is when we look at sum of independent random variables.

Theorem If X1,X2,⋯ ,XnX_1, X_2,\cdots ,X_n are independent random variables and X=X1+X2+⋯+XnX=X_1+X_2+\cdots+X_n, then

Var(X)=Var(X1)+Var(X2)+⋯+Var(Xn)(3.7)\hspace{70pt} \textrm{Var}(X)=\textrm{Var}(X_1)+\textrm{Var}(X_2)+\cdots+\textrm{Var}(X_n) \hspace{70pt} (3.7)

We will prove this theorem in Chapter 6, but for now we can look at an example to see how we can use it.


Example

If X∼Binomial(n,p)X \sim Binomial(n,p) find Var(X)(X).

  • Solution
    • We know that we can write a Binomial(n,p)Binomial(n,p) random variable as the sum of nn independent Bernoulli(p)Bernoulli(p) random variables, i.e., X=X1+X2+⋯+XnX=X_1+X_2+\cdots+X_n. Thus, we conclude

      Var(X)=Var(X1)+Var(X2)+⋯+Var(Xn).\textrm{Var}(X)=\textrm{Var}(X_1)+\textrm{Var}(X_2)+\cdots+\textrm{Var}(X_n).
      If Xi∼Bernoulli(p)X_i \sim Bernoulli(p), then its variance is
      Var(Xi)=E[Xi2]−(EXi)2=12⋅p+02⋅(1−p)−p2=p(1−p).\textrm{Var}(X_i)=E[X_i^2]-(EX_i)^2=1^2 \cdot p+0^2 \cdot (1-p)-p^2=p(1-p).
      Thus,

      Var(X)\textrm{Var}(X)=p(1−p)+p(1−p)+⋯+p(1−p)=p(1-p)+p(1-p)+\cdots+p(1-p)
      =np(1−p)=np(1-p).