Variance and standard deviation: variance stdev

### 8.1.2 Variance and standard deviation: variance stdev

The variance of a list of numbers measures how close the numbers are to their mean by finding the average of the squares of the differences between the numbers and the mean; specifically, given a list of numbers [x1,…,xn] with mean µ = (x1 + ⋯ + xn)/n, the variance is

(x1 − µ)2 + … + (xn − µ)2
n
| .

The squares help ensure that the numbers above the mean and those below the mean don’t cancel out. The variance can be computed with the command variance,

A potentially better way to measure how close numbers are to their mean is the standard deviation, which is the square root of the variance;. Note that if the list of numbers have units, then the standard deviation will have the same unit. The stddev function will compute the standard deviation of a list of numbers. For example, the list [1,2,3,4] has mean 5/2, and so stddev([1,2,3,4]) will return

2*sqrt(5)/4

since

√
(1−5/2)2 + (2−5/2)2 + (3−5/2)2 + (4−5/2)2
4
| = |
2 | √ |
5
4

Like the mean, given a matrix, stddev will compute the standard deviation of each column separately;

stddev([[1,2],[3,6]])

will compute

[1,2]

Also, a second list (or matrix) as an argument will provide weights when finding the standard deviation;

stddev([1,2,3],[2,1,1])

will return

4*sqrt(11)/16