> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> Returns the coefficient of determination of the regression line.

# regr_r2

<h2 id="regr_r2">
  regr\_r2
</h2>

Introduced in: v26.9.0

Returns the coefficient of determination of the least-squares fit, that is, the square of the
correlation coefficient. Returns `nan` when `x` is constant, and `1` when `y` is constant.

**Syntax**

```sql theme={null}
regr_r2(y, x)
```

**Aliases**: `regrR2`

**Arguments**

* `y` — Dependent variable. [`(U)Int*`](/docs/reference/data-types/int-uint) or [`Float*`](/docs/reference/data-types/float)
* `x` — Independent variable. [`(U)Int*`](/docs/reference/data-types/int-uint) or [`Float*`](/docs/reference/data-types/float)

**Returned value**

Returns a value between 0 and 1. [`Float64`](/docs/reference/data-types/float)

**Examples**

**Basic usage**

```sql title=Query theme={null}
SELECT regr_r2(y, x)
FROM VALUES('x Float64, y Float64', (1, 2), (2, 4), (3, 6), (4, 8))
```

```response title=Response theme={null}
┌─regr_r2(y, x)─┐
│             1 │
└───────────────┘
```
