REGR_R2() GROUP BY ...

All functions > GROUP BY > REGR_R2() GROUP BY ...

Returns the coefficient of determination (R²) of the linear regression.

Syntax

REGR_R2(expr_y, expr_x)
 [ FILTER (WHERE condition) ]
  [ GROUP BY feature [, feature ...] ]

Notes

  • Equivalent to POWER(CORR(y, x), 2)
  • Returns a value between 0 (no fit) and 1 (perfect fit)
  • NULL values in either expression are excluded from the calculation
  • Returns NULL if fewer than 2 non-NULL pairs exist

Examples

FeatureQL
SELECT
    f1 := ZIP(ARRAY[1, 2, 3] AS x, ARRAY[2, 4, 6] AS y).TRANSFORM(SELECT REGR_R2(y, x)).UNWRAP_ONE() -- Coefficient of determination for a perfect linear fit
;
Result
f1 VARCHAR
1.0

Last update at: 2026/05/26 17:22:09