> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> The `contingency` function calculates the contingency coefficient, a value that measures the association between two columns in a table. The computation is similar to the `cramersV` function but with a different denominator in the square root.

# contingency

<h2 id="contingency">
  contingency
</h2>

Introduced in: v22.1.0

The `contingency` function calculates the [contingency coefficient](https://en.wikipedia.org/wiki/Contingency_table#Cram%C3%A9r's_V_and_the_contingency_coefficient_C), a value that measures the association between two columns in a table.
The computation is similar to the [`cramersV`](/reference/functions/aggregate-functions/cramersV) function but with a different denominator in the square root.

**Syntax**

```sql theme={null}
contingency(column1, column2)
```

**Arguments**

* `column1` — First column to compare. [`Any`](/reference/data-types)
* `column2` — Second column to compare. [`Any`](/reference/data-types)

**Returned value**

Returns a value between 0 and 1. The larger the result, the closer the association of the two columns. [`Float64`](/reference/data-types/float)

**Examples**

**Comparison with cramersV**

```sql title=Query theme={null}
SELECT
    cramersV(a, b),
    contingency(a, b)
FROM
(
    SELECT
        number % 10 AS a,
        number % 4 AS b
    FROM
        numbers(150)
);
```

```response title=Response theme={null}
┌─────cramersV(a, b)─┬──contingency(a, b)─┐
│ 0.5798088336225178 │ 0.708607540104077  │
└────────────────────┴────────────────────┘
```
