REGR_R2() OVER ...
All functions > WINDOW FUNCTION > REGR_R2() OVER ...
Returns the coefficient of determination (R²) over the window frame.
Syntax
REGR_R2(expr_y, expr_x) OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])
Notes
- Equivalent to POWER(CORR(y, x), 2) over the window
- Returns a value between 0 (no fit) and 1 (perfect fit)
See also
Examples
FeatureQL
SELECT
f1 := ZIP(ARRAY[1,2,3] AS id, ARRAY[3.0E0,5.0E0,7.0E0] AS y, ARRAY[1.0E0,2.0E0,3.0E0] AS x).TRANSFORM(SELECT REGR_R2(y, x) OVER (ORDER BY id ASC)).UNWRAP() -- R² is 1 for a perfect linear fit
;Result
| f1 ARRAY |
|---|
| [null, 1.00, 1.00] |