Navigation

Operators and Keywords

Function List:

C++ API

: cov (x)
: cov (x, opt)
: cov (x, y)
: cov (x, y, opt)

Compute the covariance matrix.

If each row of x and y is an observation, and each column is a variable, then the (ij)-th entry of cov (x, y) is the covariance between the i-th variable in x and the j-th variable in y.

cov (x) = 1/N-1 * SUM_i (x(i) - mean(x)) * (y(i) - mean(y))

If called with one argument, compute cov (x, x), the covariance between the columns of x.

The argument opt determines the type of normalization to use. Valid values are

0:

normalize with N-1, provides the best unbiased estimator of the covariance [default]

1:

normalize with N, this provides the second moment around the mean

Compatibility Note:: Octave always treats rows of x and y as multivariate random variables. For two inputs, however, MATLAB treats x and y as two univariate distributions regardless of their shapes, and will calculate cov ([x(:), y(:)]) whenever the number of elements in x and y are equal. This will result in a 2x2 matrix. Code relying on MATLAB’s definition will need to be changed when running in Octave.

See also: corr.

Package: octave