bnlcas 0db42306ec Extend std var for variable dimensions request 999 (#1444)
* initial implementation of multidimensional std and var

* consolidated std function into var, cleaned up the interface for var, fixed bias correction

* added documentation of variable axis for std and var

* updated documentation for std and var

* changed the order of normalization and dimension for a three parameter input in the functions

* updated documentation for var and std

* add transform expressions for std and var with variable axis

* added test coverage for std and var with a variable axis

* update to documentation

* change n dim std to use apply function

* fixed tests, removed unnecessary code, updated docs

* fixed typo in docs

* update docs to remove a type

* changed location of apply function

* updated tests to use deepStrictEqual to pass linter

* adding test coverage for var.transform and std.transform
2019-03-20 15:21:55 +01:00

2.2 KiB

Function std

Compute the standard deviation of a matrix or a list with values. The standard deviations is defined as the square root of the variance: std(A) = sqrt(var(A)). In case of a (multi dimensional) array or matrix, the standard deviation over all elements will be calculated by default, unless an axis is specified in which case the standard deviation will be computed along that axis.

Additionally, it is possible to compute the standard deviation along the rows or columns of a matrix by specifying the dimension as the second argument.

Optionally, the type of normalization can be specified as the final parameter. The parameter normalization can be one of the following values:

  • 'unbiased' (default) The sum of squared errors is divided by (n - 1)
  • 'uncorrected' The sum of squared errors is divided by n
  • 'biased' The sum of squared errors is divided by (n + 1)

Syntax

math.std(a, b, c, ...)
math.std(A)
math.std(A, normalization)
math.std(A, dimension)
math.std(A, dimension, normalization)

Parameters

Parameter Type Description
array Array | Matrix A single matrix or or multiple scalar values
normalization string Determines how to normalize the variance. Choose 'unbiased' (default), 'uncorrected', or 'biased'. Default value: 'unbiased'.

Returns

Type Description
  • | The standard deviation

Examples

math.std(2, 4, 6)                     // returns 2
math.std([2, 4, 6, 8])                // returns 2.581988897471611
math.std([2, 4, 6, 8], 'uncorrected') // returns 2.23606797749979
math.std([2, 4, 6, 8], 'biased')      // returns 2

math.std([[1, 2, 3], [4, 5, 6]])      // returns 1.8708286933869707
math.std([[1, 2, 3], [4, 6, 8]], 0)    // returns [2.1213203435596424, 2.8284271247461903, 3.5355339059327378]
math.std([[1, 2, 3], [4, 6, 8]], 1)    // returns [1, 2]
math.std([[1, 2, 3], [4, 6, 8]], 1, 'biased') // returns [0.7071067811865476, 1.4142135623730951]

See also

mean, median, max, min, prod, sum, var