Investment Studio > Expressions > Functions > Statistical > COVAR

float covar(float array[rows][cols] a, float array[rows][cols] b, boolean nonbiased = FALSE)

Returns the covariance of arrays a and b.

Arrays with different dimensions are allowed as long as they all have the same number of elements (e.g. 2 x 3 and 3 x 2 arrays). Corresponding elements are determined by order of appearance (reading from left to right, top to bottom).

All array elements are converted to float and excluded if conversion fails.

If nonbiased = TRUE, arrays a and b are assumed to contain samples of larger populations, causing their sample covariance to be returned. If nonbiased = FALSE, arrays a and b are assumed to contain entire populations, causing their population covariance to be returned.

If nonbiased is omitted, it defaults to FALSE.

The covariance is the average of the products of the deviations from the mean for each pair of data points. Mathematically, given sequences a[n] and b[n] containing N points each, their population covariance is computed as

 

N

 

Cov(a, b) = 

1

å

(a[k] - <a>) (b[k] - <b>)

¾
N
 

k = 1

 

where <a> and <b> denote the arithmetic means of sequences a[n] and b[n], respectively. The sample covariance is computed using a divisor = N - 1 instead of N, but is otherwise identical with the population covariance.

The main use of the covariance is as a building block for other statistical measures of the relationship between data sets, such as the correlation coefficient (correl).

Examples

=covar({1, 2, 3, 4}, {10, 11, 12, 13})

= 1.25;

=covar({1, 2, 3, 4}, {10, 9, 8, 7})

= -1.25;

=covar({1, 2, 3, 4}, {3, 1, 10, 0})

= 0.

See also correl, stdev, stdevp, fisher, fisherinv.