var

Syntax

var(X)

Details

If X is a vector, return the the (unbiased) sample standard variance of X.

If X is a matrix, calculate the the (unbiased) sample standard variance of each column of X and return a vector.

As with all aggregate functions, null values are not included in the calculation.

Note:

DolphinDB var and numpy.var are both used to calculate variance. The differences are as follows:

  • DolphinDB var returns the unbiased sample variance, while numpy.var returns the population variance by default. To obtain results consistent with DolphinDB var, you should specify ddof=1 in NumPy.
  • DolphinDB var automatically ignores NULL values, whereas numpy.var does not automatically skip NaN values, so the result may be NaN.
  • Regarding computation dimensions, DolphinDB var calculates the variance column by column for matrices, while numpy.var flattens the array and calculates the variance over all elements by default. You can also specify the computation dimension using the axis parameter.

Parameters

X is a scalar/vector/matrix.

Returns

A DOUBLE scalar/vector/table.

Examples

var(1 1 1);
// output: 0

var(1 2 3);
// output: 1

m=matrix(1 3 5 7 9, 1 4 7 10 13);
m;
#0 #1
1 1
3 4
5 7
7 10
9 13
var(m);
// output: [10,22.5]

Related functions: covar and corr