corr()

Aggregate. Returns the correlation coefficient of a set of number pairs to determine the relationship between the two properties.

Syntax

corr ( dependent-expression, independent-expression )

Parameters

dependent-expression The variable that is affected by the independent variable. The expression accepts all numeric datatypes except timestamp, bigdatetime, and interval. Will normally reference one or more columns in the group of records to be aggregated.
independent-expression The variable that influences the outcome. The expression accepts all numeric datatypes except timestamp, bigdatetime, and interval. Will normally reference one or more columns in the group of records to be aggregated.

Usage

Returns the correlation coefficient of a set of number pairs. The function converts its arguments to FLOAT, performs the computation in double-precision floating point, and returns a float as the result. If the function is applied to an empty set, then it returns NULL.

Both dependent-expression and independent-expression are numeric. The function is applied to the set of (dependent-expression, independent-expression) after eliminating the pairs for which either dependent-expression or independent-expression is NULL.


image name

where x represents the independent-expression and y represents the dependent-expression. Running totals of row_count, sum_x, sum_y, sum_xx, sum_yy and sum_xy are required.

The correlation function could be used to analyze the relationship between two sets of stock variables to help benchmark against competitors.