covariance, correlation

Prev Next

Function Names

covariance, correlation

Description

Calculates the covariance resp. correlation of two vectors (= sets containing numerals). Zero is returned if number of parameter elements is 0 or 1.

Call as: function

Parameter count

2

Parameters

No.TypeDescription
1
input
set of numerals 1st vector

2
input
set of numerals 2nd vector

Return value

TypeDescription
numeral Result

Calculated covariance resp. correlation

Exceptions

Vectors have different lengths
sets provided contain non-numeric elements

Examples

               echo( covariance( {},{} ) ); // Returns 0
               echo( covariance( {10,20,30}, {10,30,20} ) ); //   50
               echo( covariance( {10,20,30}, {30,20,10} ) ); // -100

               echo( correlation( {1},{1} ) ); // 0
               echo( correlation( {10,20,30}, {10,30,20} ) ); //  0.5
               echo( correlation( {10,20,30}, {30,20,10} ) ); //  -1

Output

0
50
-100
0
0.5
-1
Try it yourself: Open LIB_Function_covariance.b4p in B4P_Examples.zip. Decompress before use.

See also

variance
deviation