# Reference/cor

(Difference between revisions)
 Revision as of 17:29, 10 October 2006 (view source) (Fixed function reference link)← Older edit Latest revision as of 15:08, 21 November 2011 (view source)m (Undo revision 2436 by Charlie Skelton (talk)) (2 intermediate revisions by 2 users not shown) Line 1: Line 1: − = cor = + {{refheader|cor|correlation verb}} − Dyadic aggregation function. Returns the correlation of its arguments as floating point number between -1f and 1f. Applies to all numeric data types and throws error with temporal types, char and sym. Perfectly correlated data results in a 1 or a -1. When one variable increases as the other increases the correlation is positive; when one decreases as the other increases it is negative, completely uncorrelated gives a 0f. Arguments must be of the same length. + Returns the correlation of its arguments as a floating point number between -1f and 1f. Perfectly correlated data results in a 1 or -1. When one variable increases as the other increases the correlation is positive; when one decreases as the other increases it is negative. Completely uncorrelated arguments return 0f. Arguments must be of the same length. + + cor applies to all numeric data types and throws an error with temporal types, char and sym. == Syntax == == Syntax == Line 7: Line 9:

q)r:X cor Y                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  q)r:X cor Y
−                                                                                                q)r:cor[X;Y]

Line 13: Line 14:

−                                                                                                q)cor[10 23 54;3 1 9]                                                                                                                                                                                                                                                                                                                                                                                                                                                           +                                                                                                            q)29 10 54 cor 1 3 9
−                                                                                                0.8606638                                                                                                                                                                                                                                                                                                                                                                                                                                                                       +                                                                                                            0.7727746
−                                                                                                q)select price cor size by sym from trade where date=2001.10.12,sym in`SUNW`A                                                                                                                                                                                                                                                                                                                                                                                                   +                                                                                                            q)10 29 54 cor 1 3 9
+                                                                                                            0.9795734
+                                                                                                            q)1 3 9 cor neg 1 3 9
+                                                                                                            -1f
+
+                                                                                                            q)select price cor size by sym from trade

+ + == See also == + + *[[Reference/cov|covariance]] ---- ---- For a complete list of functions, see the [[Reference|kdb+ Function Reference]]. For a complete list of functions, see the [[Reference|kdb+ Function Reference]].

## cor (correlation verb)

Returns the correlation of its arguments as a floating point number between -1f and 1f. Perfectly correlated data results in a 1 or -1. When one variable increases as the other increases the correlation is positive; when one decreases as the other increases it is negative. Completely uncorrelated arguments return 0f. Arguments must be of the same length.

cor applies to all numeric data types and throws an error with temporal types, char and sym.

q)r:X cor Y

## Example

q)29 10 54 cor 1 3 9
0.7727746
q)10 29 54 cor 1 3 9
0.9795734
q)1 3 9 cor neg 1 3 9
-1f

q)select price cor size by sym from trade