Reference/cor

From Kx Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
Line 22: Line 22:
  
 
q)select price cor size by sym from trade
 
q)select price cor size by sym from trade
 +
</pre>
 +
 +
N.b. don't forget to fill null values
 +
<pre>
 +
q)(0n 0n 1 2 3) cor 1 0n 1 2 3
 +
1.723281
 +
q)(0.0^0n 0n 1 2 3) cor 0.0^1 0n 1 2 3
 +
0.9417419
 
</pre>
 
</pre>
  

Revision as of 10:28, 21 November 2011

Contents

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.

Syntax

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

N.b. don't forget to fill null values

q)(0n 0n 1 2 3) cor 1 0n 1 2 3
1.723281
q)(0.0^0n 0n 1 2 3) cor 0.0^1 0n 1 2 3
0.9417419

See also


For a complete list of functions, see the kdb+ Function Reference.

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox