UNPKG

2.16 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function variance
4
5Compute the variance of a matrix or a list with values.
6In case of a (multi dimensional) array or matrix, the variance over all
7elements will be calculated.
8
9Additionally, it is possible to compute the variance along the rows
10or columns of a matrix by specifying the dimension as the second argument.
11
12Optionally, the type of normalization can be specified as the final
13parameter. 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
20Note that older browser may not like the variable name `var`. In that
21case, the function can be called as `math['var'](...)` instead of
22`math.var(...)`.
23
24
25## Syntax
26
27```js
28math.variance(a, b, c, ...)
29math.variance(A)
30math.variance(A, normalization)
31math.variance(A, dimension)
32math.variance(A, dimension, normalization)
33```
34
35### Parameters
36
37Parameter | Type | Description
38--------- | ---- | -----------
39`array` | Array &#124; 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
44Type | Description
45---- | -----------
46* | The variance
47
48
49## Examples
50
51```js
52math.variance(2, 4, 6) // returns 4
53math.variance([2, 4, 6, 8]) // returns 6.666666666666667
54math.variance([2, 4, 6, 8], 'uncorrected') // returns 5
55math.variance([2, 4, 6, 8], 'biased') // returns 4
56
57math.variance([[1, 2, 3], [4, 5, 6]]) // returns 3.5
58math.variance([[1, 2, 3], [4, 6, 8]], 0) // returns [4.5, 8, 12.5]
59math.variance([[1, 2, 3], [4, 6, 8]], 1) // returns [1, 4]
60math.variance([[1, 2, 3], [4, 6, 8]], 1, 'biased') // returns [0.5, 2]
61```
62
63
64## See also
65
66[mean](mean.md),
67[median](median.md),
68[max](max.md),
69[min](min.md),
70[prod](prod.md),
71[std](std.md),
72[sum](sum.md)