Variance and standard deviation
Standard deviation is used to measure how much on average the individual values of a variable change from the mean.
The variance of a variable X is the average of squared deviations from each individual value X_i from its mean:
Var(X)=\frac{1}{N}\sum_{i=1}^{N}\left(X_{i}-\bar{X}\right)^{2}=\sigma_{X}^{2}
Where:
X_i = Value i of the variable X
\overline{X}=\frac{1}{n}\sum_{i=1}^{n}X_{i} = Arithmetic average of X
Why the variance is the average of squared deviations? The reason is because if we do not square the deviations, then they will cancel out each other since some deviations are positive and other negative. Then, the squaring is just a trick to avoid canceling the positive with the negative deviations.
The result of the variance will be a number that our brain cannot easily interpret. To have a more reasonable measure of linear deviation, then we just take the square root of the variance, and then, we will be able to interpret that number as the average deviations of all points from their mean. This measure is called standard devation:
SD(X)=\sqrt{Var(X)}= \sqrt{\frac{1}{N}\sum_{i=1}^{N}\left(X_{i}-\bar{X}\right)^{2}}=\sigma_{X}
The variance can also be expressed as the expected value of squared deviations:
Var(X)=E[(X-\bar{X})^2]
Doing the multiplication of the squared term:
Var(X)=E[(X^2-X\bar{X}-\bar{X}X+\bar{X}^2)]
Since \bar{X} and \bar{Y} are constants, I can take them out of the expectation:
Var(X)=E[X^2]-\bar{X}E[X]-\bar{X}E[X]+\bar{X}^2
Since E[X]=\bar{X}, then:
Var(X)=E[X^2]-\bar{X}^2
Then, the variance can be defined as the expected value of X squared minus its squared mean.
Also, we can express the variance of X as:
Var(X)=\frac{1}{N}\sum_{i=1}^{N}\left(X_{i}\right)^2-\bar{X}^2
Most Statistics books and Statistics software use (N-1) instead of N as the denominator of the variance formula to get a more conservative value of the variance. This measure is called sample variance. When we divide by N in the variance formula, we are calculating the population variance. Both formulas provide very similar results, but the sample variance will be a bit bigger than the population variance, so it is a more conservative value.
In Statistics, the sample variance is an unbiased measure of the underlying (real) variance.
Then, we can re-write the formula for sample variance of X as:
Var(X)=\frac{1}{\left(N-1\right)}\sum_{i=1}^{n}\left(X_{i}-\bar{X}\right)^{2}=\sigma_{X}^{2}
And the sample standard deviation of X can be written as:
SD(X)=\sqrt[2]{Var(X)}=\sqrt{\frac{1}{(n-1)}\sum_{i=1}^{n}(X_{i}-\bar{X})^{2}}
SD(X)=\frac{\sqrt{\sum_{i=1}^{n}(X_{i}-\bar{X})^{2}}}{\sqrt{(n-1)}}=\sigma_{X}