REGR_SLOPE() OVER ...

All functions > WINDOW FUNCTION > REGR_SLOPE() OVER ...

Returns the slope of the linear regression line over the window frame.

Syntax

REGR_SLOPE(expr_y, expr_x) [FILTER (WHERE condition) | WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])

Notes

  • Equivalent to COVAR_POP(y, x) / VAR_POP(x) over the window
  • NULL values in either expression are excluded

See also

Examples

FeatureQL
-- Regression slope for y = 2x over the whole frame
RETURN
    f1 := ZIP(
        ARRAY(1, 2, 3) AS id,
        ARRAY(1.0e0, 2.0e0, 3.0e0) AS x,
        ARRAY(2.0e0, 4.0e0, 6.0e0) AS y
    ).TRANSFORM(RETURN REGR_SLOPE(y, x) OVER ().ROUND(2)).UNWRAP()
;
Result
f1 ARRAY<DOUBLE>
[2.00, 2.00, 2.00]