Skip to content
ClickHouse Docs

regr_slope

Autogenerated from ClickHouse system tables

Introduced in: v26.9.0

Returns the slope of the least-squares fit of y on x:

Σ(x−xˉ)(y−yˉ)Σ(x−xˉ)2\frac{\Sigma{(x - \bar{x})(y - \bar{y})}}{\Sigma{(x - \bar{x})^2}}

Returns nan when x is constant, because the fitted line is vertical.

Syntax

regr_slope(y, x)

Arguments

Returned value

Returns the slope of the regression line. Float64

Examples

Basic usage

SELECT regr_slope(y, x)
FROM VALUES('x Float64, y Float64', (1, 2), (2, 4), (3, 6), (4, 8))
┌─regr_slope(y, x)─┐
│                2 │
└──────────────────┘