variance.md (2215B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 2 3 # Function variance 4 5 Compute the variance of a matrix or a list with values. 6 In case of a (multi dimensional) array or matrix, the variance over all 7 elements will be calculated. 8 9 Additionally, it is possible to compute the variance along the rows 10 or columns of a matrix by specifying the dimension as the second argument. 11 12 Optionally, the type of normalization can be specified as the final 13 parameter. The parameter `normalization` can be one of the following values: 14 15 - 'unbiased' (default) The sum of squared errors is divided by (n - 1) 16 - 'uncorrected' The sum of squared errors is divided by n 17 - 'biased' The sum of squared errors is divided by (n + 1) 18 19 20 Note that older browser may not like the variable name `var`. In that 21 case, the function can be called as `math['var'](...)` instead of 22 `math.var(...)`. 23 24 25 ## Syntax 26 27 ```js 28 math.variance(a, b, c, ...) 29 math.variance(A) 30 math.variance(A, normalization) 31 math.variance(A, dimension) 32 math.variance(A, dimension, normalization) 33 ``` 34 35 ### Parameters 36 37 Parameter | Type | Description 38 --------- | ---- | ----------- 39 `array` | Array | Matrix | A single matrix or or multiple scalar values 40 `normalization` | string | Determines how to normalize the variance. Choose 'unbiased' (default), 'uncorrected', or 'biased'. Default value: 'unbiased'. 41 42 ### Returns 43 44 Type | Description 45 ---- | ----------- 46 * | The variance 47 48 49 ### Throws 50 51 Type | Description 52 ---- | ----------- 53 54 55 ## Examples 56 57 ```js 58 math.variance(2, 4, 6) // returns 4 59 math.variance([2, 4, 6, 8]) // returns 6.666666666666667 60 math.variance([2, 4, 6, 8], 'uncorrected') // returns 5 61 math.variance([2, 4, 6, 8], 'biased') // returns 4 62 63 math.variance([[1, 2, 3], [4, 5, 6]]) // returns 3.5 64 math.variance([[1, 2, 3], [4, 6, 8]], 0) // returns [4.5, 8, 12.5] 65 math.variance([[1, 2, 3], [4, 6, 8]], 1) // returns [1, 4] 66 math.variance([[1, 2, 3], [4, 6, 8]], 1, 'biased') // returns [0.5, 2] 67 ``` 68 69 70 ## See also 71 72 [mean](mean.md), 73 [median](median.md), 74 [max](max.md), 75 [min](min.md), 76 [prod](prod.md), 77 [std](std.md), 78 [sum](sum.md)