8.1.2 Variance: 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 don’t 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
-
Input:
variance([1,2,3,4])
Output:
- Input:
variance([[1,2,3],[5,6,7]])
Output:
- Input:
variance([2,4,6,8],[2,2,3,3])
Output:
- Input:
variance([[1,2],[3,4]],[[1,2],[2,1]])
Output: