Variance

### 20.1.2 Variance

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 do not cancel out. The variance command computes the variance.

- variance takes one mandatory argument and one optional argument:
  - L, a list or matrix of numbers.
  - W, a list or matrix of weights, the same size as L.
- variance(L ⟨,W⟩) returns the variance of the list or a list with the variances of the columns of the matrix.

#### Examples

variance([1,2,3,4])

5
4

variance([[1,2,3],[5,6,7]])

| ⎡ ⎣ | 4,4,4 | ⎤ ⎦

variance([2,4,6,8],[2,2,3,3])

121
25

variance([[1,2],[3,4]],[[1,2],[2,1]])

| ⎡ ⎢ ⎢ ⎣ |
8
9
| , |
8
9
| ⎤ ⎥ ⎥ ⎦