ReferenceSQL ReferenceAggregate Functions

rankCorr

Computes a rank correlation coefficient.

This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See SQL interface scope.

Computes a rank correlation coefficient.

Returns a rank correlation coefficient of the ranks of x and y. The value of the correlation coefficient ranges from -1 to +1. If less than two arguments are passed, the function will return an exception. The value close to +1 denotes a high linear relationship, and with an increase of one random variable, the second random variable also increases. The value close to -1 denotes a high linear relationship, and with an increase of one random variable, the second random variable decreases. The value close or equal to 0 denotes no relationship between the two random variables.

See Also

Syntax

rankCorr(x, y)

Arguments

  • x — Arbitrary value. Float*
  • y — Arbitrary value. Float*

Returned value

Returns a rank correlation coefficient of the ranks of x and y. The value ranges from -1 to +1. Float64

Examples

Perfect correlation

SELECT rankCorr(number, number) FROM numbers(100);
┌─rankCorr(number, number)─┐
│                        1 │
└──────────────────────────┘

Non-linear relationship

SELECT roundBankers(rankCorr(exp(number), sin(number)), 3) FROM numbers(100);
┌─roundBankers(rankCorr(exp(number), sin(number)), 3)─┐
│                                              -0.037 │
└─────────────────────────────────────────────────────┘

Introduced in version 20.9.0.