ClickHouse/docs/zh/sql-reference/aggregate-functions/reference/rankCorr.md

53 lines
1.9 KiB
Markdown
Raw Normal View History

2021-02-02 12:00:41 +00:00
## rankCorr {#agg_function-rankcorr}
2021-03-08 10:28:52 +00:00
计算等级相关系数。
2021-02-02 12:00:41 +00:00
2021-03-08 10:28:52 +00:00
**语法**
2021-02-02 12:00:41 +00:00
``` sql
rankCorr(x, y)
```
2021-03-08 10:28:52 +00:00
**参数**
2021-02-02 12:00:41 +00:00
2021-03-08 10:28:52 +00:00
- `x` — 任意值。[Float32](../../../sql-reference/data-types/float.md#float32-float64) 或 [Float64](../../../sql-reference/data-types/float.md#float32-float64)。
- `y` — 任意值。[Float32](../../../sql-reference/data-types/float.md#float32-float64) 或 [Float64](../../../sql-reference/data-types/float.md#float32-float64)。
2021-02-02 12:00:41 +00:00
2021-03-08 10:28:52 +00:00
**返回值**
2021-02-02 12:00:41 +00:00
- 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.
2021-07-29 15:27:50 +00:00
类型: [Float64](../../../sql-reference/data-types/float.md#float32-float64)。
2021-02-02 12:00:41 +00:00
2021-03-08 10:28:52 +00:00
**示例**
2021-02-02 12:00:41 +00:00
2021-03-08 10:28:52 +00:00
查询:
2021-02-02 12:00:41 +00:00
``` sql
SELECT rankCorr(number, number) FROM numbers(100);
```
2021-03-08 10:28:52 +00:00
结果:
2021-02-02 12:00:41 +00:00
``` text
┌─rankCorr(number, number)─┐
│ 1 │
└──────────────────────────┘
```
2021-03-08 10:28:52 +00:00
查询:
2021-02-02 12:00:41 +00:00
``` sql
SELECT roundBankers(rankCorr(exp(number), sin(number)), 3) FROM numbers(100);
```
2021-03-08 10:28:52 +00:00
结果:
2021-02-02 12:00:41 +00:00
``` text
┌─roundBankers(rankCorr(exp(number), sin(number)), 3)─┐
│ -0.037 │
└─────────────────────────────────────────────────────┘
```
2021-03-08 10:28:52 +00:00
**参见**
2021-02-02 12:00:41 +00:00
2021-03-08 10:28:52 +00:00
- 斯皮尔曼等级相关系数[Spearman's rank correlation coefficient](https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient)