<s>[INST] Variance formulae I know that the variance formula is
$$\sigma^2 = \frac{
   \left( x_1 - \bar{x} \right) ^2 +
   \left( x_2 - \bar{x} \right) ^2 +
   \dots +
   \left( x_n - \bar{x} \right) ^2
   }{n}$$
Where $\sigma^2$ is the variance; $x_1,\ x_2,\ \dots,\ x_n$ are the statistical data, and $n$ is the number of data.
My question is: how can I expand that formula to get this equivalent one:
$$ \sigma^2 = \frac{x_1^2 + x_2^2 + \dots + x^2_n}{n} -\bar{x}^2$$
?
 [/INST] Each of the $(x_i - \bar x)^2$ terms expands into $x_i^2 - 2x_i\bar x + \bar x^2$.
Since the sum of all $x_i$ is also equal to $n \bar x$ (by definition), we get that the sum of all the $2x_i\bar x$ is actually $2n\bar x^2$.
Then, the equation becomes: $\displaystyle \sigma^2 = \frac{x_1^2 + x_2^2 + \cdots + x_n^2 - 2n\bar x^2 + n\bar x^2}{n}$
which is $\displaystyle \frac{x_1^2 + x_2^2 + \cdots + x_n^2 - n\bar x^2}{n}$ or $\displaystyle \frac{x_1^2 + x_2^2 + \cdots + x_n^2}{n} - \bar x^2$, as required
</s>