We are talking about moments which are measurements that describes some aspect of the shape, for a given set of points or values.
Last week we talked about the mean which is known as the first moment.
Lets now carry on to the second moment, which is known as the variance. We will continue to focus on the normal distribution
Variance
The mean shows us the central point for a distribution of values. The variance of the distribution gives us a measure of how far the values are spread out or dispersed, around the mean.
Calculating
Here is the formula to calculate the variance for a sample of values:
One way to think about variance, is as an “average difference” for the values around the mean, which we could calculate like this:
- First thing we do, is subtract the mean from all the values, this gives us a difference from the mean for each value.
- Then sum all these differences
- Finally divide by n-1 to get this “average difference”.
Differences can be negative
However there is a problem doing this. When we subtract the mean from a value, if the value is less than the mean – we get a negative number for the difference.
Now, when we sum the differences, all the negative ones will just be cancelling out the other positive differences.
To get around this, after we calculate each difference, we square (raise to power 2) the difference (just multiply it by itself). Now if the difference is negative, after we square it we get a positive value … as a negative times a negative gives a positive number. So now, when we do the sum, none of the differences are cancelling each other out.
One other thing, is why do we use n-1 and not n? This is discussed here. Essentially the mean we calculate is for a sample from the entire population of all values. This mean will be a bit smaller than the mean of the population as the sample will not have the same range of values as the population. To adjust for this we use n-1 in the calculation, which makes a bigger adjustment as n gets smaller for a smaller samples.
Another fly in the ointment
There is a problem with the variance, We had to square each difference before we took their sum, in order to get rid of negative differences. We can undo the taking of the square when calculating the variance, by taking the square root of the final calculated variance.
This square root gives a new value which is called the standard deviation, and here is its formula:
R programming example
I am still very much a newbie to R, but here is some R programming language code, I used to plot the histogram of some values, and overlay the standard deviation, to the left and to the right of the mean:
# Generate a random set of 10000 points from the Normal distribution
values <- rnorm(10000, mean=5, sd=2)
# Plot the histogram of the points
hist(values, breaks=100, main=”Mean with standard deviation to left and right”, xlab=”math4uandme.com”)
the.mean = mean(values)
the.sd = sd(values)
# Overlay the mean
abline(v=the.mean, col=”blue”,lwd=3)
# Overlay the sd to the left of the mean
abline(v=(the.mean – the.sd), col=”brown3″,lwd=5)
# Overlay the sd to the right of the mean
abline(v=(the.mean + the.sd), col=”brown3″,lwd=5)
Links
Covers population and then sample variance …





