# What is the mathematical formula for calculating the variance of a discrete random variable?

Oct 24, 2015

Let ${\mu}_{X} = E \left[X\right] = {\sum}_{i = 1}^{\infty} {x}_{i} \cdot {p}_{i}$ be the mean (expected value) of a discrete random variable $X$ that can take on values ${x}_{1} , {x}_{2} , {x}_{3} , \ldots$ with probabilities $P \left(X = {x}_{i}\right) = {p}_{i}$ (these lists may be finite or infinite and the sum may be finite or infinite). The variance is ${\sigma}_{X}^{2} = E \left[{\left(X - {\mu}_{X}\right)}^{2}\right] = {\sum}_{i = 1}^{\infty} {\left({x}_{i} - {\mu}_{X}\right)}^{2} \cdot {p}_{i}$

#### Explanation:

The previous paragraph is the definition of the variance ${\sigma}_{X}^{2}$. The following bit of algebra, using the linearity of the expected value operator $E$, shows an alternative formula for it, which is often easier to use.

${\sigma}_{X}^{2} = E \left[{\left(X - {\mu}_{X}\right)}^{2}\right] = E \left[{X}^{2} - 2 {\mu}_{X} X + {\mu}_{X}^{2}\right]$

$= E \left[{X}^{2}\right] - 2 {\mu}_{X} E \left[X\right] + {\mu}_{X}^{2} = E \left[{X}^{2}\right] - 2 {\mu}_{X}^{2} + {\mu}_{X}^{2}$

$= E \left[{X}^{2}\right] - {\mu}_{X}^{2} = E \left[{X}^{2}\right] - {\left(E \left[X\right]\right)}^{2}$,

where $E \left[{X}^{2}\right] = {\sum}_{i = 1}^{\infty} {x}_{i}^{2} \cdot {p}_{i}$