2023-01-10 06:42:39 +00:00
---
slug: /en/sql-reference/aggregate-functions/reference/cramersv
2024-06-24 11:52:30 +00:00
sidebar_position: 127
2023-01-10 06:42:39 +00:00
---
# cramersV
2023-06-02 11:30:05 +00:00
[Cramer's V ](https://en.wikipedia.org/wiki/Cram%C3%A9r%27s_V ) (sometimes referred to as Cramer's phi) is a measure of association between two columns in a table. The result of the `cramersV` function ranges from 0 (corresponding to no association between the variables) to 1 and can reach 1 only when each value is completely determined by the other. It may be viewed as the association between two variables as a percentage of their maximum possible variation.
2023-01-10 06:42:39 +00:00
2024-04-03 09:17:57 +00:00
:::note
For a bias corrected version of Cramer's V see: [cramersVBiasCorrected ](./cramersvbiascorrected.md )
:::
2023-01-10 06:42:39 +00:00
**Syntax**
``` sql
cramersV(column1, column2)
```
2024-04-03 09:17:57 +00:00
**Parameters**
2023-01-10 06:42:39 +00:00
2024-04-03 09:17:57 +00:00
- `column1` : first column to be compared.
- `column2` : second column to be compared.
2023-01-10 06:42:39 +00:00
**Returned value**
2023-04-19 16:10:51 +00:00
- a value between 0 (corresponding to no association between the columns' values) to 1 (complete association).
2023-01-10 06:42:39 +00:00
2024-04-03 09:17:57 +00:00
Type: always [Float64 ](../../../sql-reference/data-types/float.md ).
2023-01-10 06:42:39 +00:00
**Example**
The following two columns being compared below have no association with each other, so the result of `cramersV` is 0:
2024-04-03 09:23:42 +00:00
Query:
2023-01-10 06:42:39 +00:00
``` sql
SELECT
cramersV(a, b)
FROM
(
SELECT
number % 3 AS a,
number % 5 AS b
FROM
numbers(150)
);
```
Result:
```response
┌─cramersV(a, b)─┐
│ 0 │
└────────────────┘
```
The following two columns below have a fairly close association, so the result of `cramersV` is a high value:
```sql
SELECT
cramersV(a, b)
FROM
(
SELECT
number % 10 AS a,
number % 5 AS b
FROM
numbers(150)
);
```
Result:
```response
┌─────cramersV(a, b)─┐
│ 0.8944271909999159 │
└────────────────────┘
2023-06-02 11:30:05 +00:00
```