# Reference/cor

From Kx Wiki

(Difference between revisions)

(Fixed function reference link) |
Chris Burke (Talk | contribs) |
||

Line 1: | Line 1: | ||

− | + | {{refheader|cor|correlation verb}} | |

− | + | Returns the correlation of its arguments as a floating point number between <tt>-1f</tt> and <tt>1f</tt>. Perfectly correlated data results in a <tt>1</tt> or <tt>-1</tt>. 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 <tt>0f</tt>. Arguments must be of the same length. | |

+ | |||

+ | <tt>cor</tt> applies to all numeric data types and throws an error with temporal types, char and sym. | ||

== Syntax == | == Syntax == | ||

Line 7: | Line 9: | ||

<pre> | <pre> | ||

q)r:X cor Y | q)r:X cor Y | ||

− | |||

</pre> | </pre> | ||

Line 13: | Line 14: | ||

<pre> | <pre> | ||

− | q) | + | q)29 10 54 cor 1 3 9 |

− | 0. | + | 0.7727746 |

− | q)select price cor size by sym from trade | + | 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 | ||

</pre> | </pre> | ||

+ | |||

+ | == 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]]. |

## Revision as of 09:35, 12 October 2009

## 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

## See also

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