## correlation_coefficient

correlation_coefficient — aggregate function to return the correlation coefficient of two ranges of values.

## DESCRIPTION

This function takes the name of two fields of type double in the aggregate window, or two predicate expressions that contain the names of two such fields, and returns a value between −1.0 and 1.0 that represents the correlation coefficient of the two ranges. For example, one field could represent a stock's price while the second represents a stock price index. The result is a number that encapsulates the quality of a linear least squares fit to the data. A correlation coefficient of −1.0 indicates perfect negative correlation; 1.0 indicates perfect positive correlation; and 0 means no correlation.

If the query returns no rows to the aggregate's window, the function returns `null`

. If the query returns a row count of 1 or −1, or if there is a sequence of identical values in the two fields, the result
is 1.0.

This function calculates its return value based on the *unbiased* or *n-1* method, and is usually used when the incoming data represents a random sample of data. See correlation_coefficientp for a similar function that calculates its return value using the *biased* or *n* method, which is used when the incoming data represents an entire population of data.

## SEE ALSO

This LiveView aggregate function is based on the correlation_coefficient aggregate function in the StreamBase expression language.