ReferenceSQL ReferenceAggregate Functions

contingency

The contingency function calculates the [contingency coefficient](https://en.

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.

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.

Syntax

contingency(column1, column2)

Arguments

  • column1 — First column to compare. Any
  • column2 — Second column to compare. Any

Returned value

Returns a value between 0 and 1. The larger the result, the closer the association of the two columns. Float64

Examples

Comparison with cramersV

SELECT
    cramersV(a, b),
    contingency(a, b)
FROM
(
    SELECT
        number % 10 AS a,
        number % 4 AS b
    FROM
        numbers(150)
);
┌─────cramersV(a, b)─┬──contingency(a, b)─┐
│ 0.5798088336225178 │ 0.708607540104077  │
└────────────────────┴────────────────────┘

Introduced in version 22.1.0.