CORR Function
Description
The CORR function computes the Pearson correlation coefficient between two numeric columns. The correlation coefficient measures the degree of linear relationship between two variables, with values ranging from -1 to 1.
Parameters
y: A numeric expression serving as the dependent variable. Must be a numeric type that can be cast toDOUBLE.x: A numeric expression serving as the independent variable. Must be a numeric type that can be cast toDOUBLE.
Return Type
- Returns a
DOUBLEvalue representing the Pearson correlation coefficient, in the range [-1, 1].1: Perfect positive correlation (as x increases, y increases)-1: Perfect negative correlation (as x increases, y decreases)0: No linear correlation- Close to
1or-1: Strong correlation - Close to
0: Weak or no correlation
Notes
- During computation,
NULLvalues are ignored and excluded from the calculation. - If all x values are identical or all y values are identical (standard deviation is 0), returns
NULL. - If there are fewer than 2 valid data points, returns
NULL. - Formula:
corr(y, x) = covar_pop(y, x) / (stddev_pop(y) * stddev_pop(x)), i.e., the covariance divided by the product of the standard deviations of the two variables.
Examples
- Basic usage: compute the correlation coefficient
- Perfect positive correlation (y = x)
- Perfect negative correlation (y = -x)
- No correlation (x and y are independent)
- Compute correlation coefficient by group
