Skip to content

cov, scov

Covariance

cov

x cov y    cov[x;y]

Where x and y are conforming numeric lists returns their covariance as a floating-point number. Applies to all numeric data types and signals an error with temporal types, char and sym.

q)2 3 5 7 cov 3 3 5 9
4.5
q)2 3 5 7 cov 4 3 0 2
-1.8125
q)select price cov size by sym from trade

cov is an aggregate function.

The function cov is equivalent to {avg[x*y]-avg[x]*avg y}.

scov

Sample covariance

x scov y    scov[x;y]

Where x and y are conforming numeric lists returns their sample covariance as a float atom.

scov(x,y)=\frac{n}{n-1}cov(x,y)

Applies to all numeric data types and signals an error with temporal types, char and sym.

q)2 3 5 7 scov 3 3 5 9
8
q)2 3 5 7 scov 4 3 0 2
-2.416667
q)select price scov size by sym from trade

scov is an aggregate function.

The function scov is equivalent to {cov[x;y]*count[x]%-1+count x}.


var, svar
Mathematics
Covariance