The variance is the $2^{nd}$ [[Moments of a Distribution#^afe9bc|central moment]] and takes the following from. $ \begin{align} \mathrm{Var}(X) &= \mathbb E \big[(X- \mathbb E[X])^2\big] \\[2pt] \sigma_X &= \sqrt{\mathrm{Var}(X)} \end{align} $ > [!note:] > - Because of the squared function the variance is always $\ge0$. > - The standard deviation $\sigma$ takes the square root of the variance, and can therefore be interpreted in original units of $X$. There are two different ways to compute the variance of a r.v. $X$. - *Expected value rule:* We can calculate variance with the expected value rule, where we insert the function $g(Z)=(z-\mu)^2$, and calculate the [[Expectation]] of the function. $ \begin{align} \mathrm{Var}(X) &= \mathbb E[g(Z)] \\[8pt] &= \sum_z g(Z)*p_z(z) \\ &= \sum_z (z-\mu)^2*p_z(z) \end{align} $ - *Method of moments:* In this simpler form we just need to subtract the $2^{nd}$ moment by the squared expectation. $ \mathrm{Var}(X)=\mathbb E[X^2]- (\mathbb E[X])^2 $ ^559043 Derivation for method of moments: $ \begin{align} \mathrm{Var}(X) &= \mathbb E \big[(X-\mu)^2 \big] \tag{1}\\[4pt] &= \mathbb E \big[(X^2-2\mu X + \mu^2) \big] \tag{2}\\[4pt] &= \mathbb E[X^2]- 2\mu *\mathbb E[X] + \mathbb E[\mu]^2 \tag{3}\\[4pt] &= \mathbb E[X^2]- 2\mathbb E[X]^2 + \mathbb E[X]^2 \tag{4}\\[4pt] &= \mathbb E[X^2]- \mathbb E[X]^2 \tag{5} \end{align} $ where: - (2) Expand the quadratic term. - (3) Separate the expectations by linearity of expectations. - (4) $\mu = \mathbb E[X]$.