Previous Up Next

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.

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



          

Previous Up Next