COVAR_POP() OVER ...
All functions > WINDOW FUNCTION > COVAR_POP() OVER ...
Returns the population covariance over the window frame.
Syntax
COVAR_POP(expr_y, expr_x) [FILTER (WHERE condition) | WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])
Notes
- Computes population covariance (divides by N) over a window
- NULL values in either expression are excluded
See also
Examples
FeatureQL
SELECT
-- Population covariance over the frame (id is only the sort key)
f1 := ZIP(
ARRAY(1, 2, 3, 4) AS id,
ARRAY(30, 10, 20, 5) AS v,
ARRAY(1.0e0, 2.0e0, 4.0e0, 8.0e0) AS x
).TRANSFORM(
SELECT COVAR_POP(CAST(v AS DOUBLE), x) OVER (ORDER BY id ASC).ROUND(2)
).UNWRAP(),
-- Population covariance counting only rows where v > 15 (10 and 5 excluded from the frame)
f2 := ZIP(
ARRAY(1, 2, 3, 4) AS id,
ARRAY(30, 10, 20, 5) AS v,
ARRAY(1.0e0, 2.0e0, 4.0e0, 8.0e0) AS x
).TRANSFORM(
SELECT COVAR_POP(CAST(v AS DOUBLE), x) FILTER (WHERE v > 15) OVER (
ORDER BY id ASC
).ROUND(
2
)
).UNWRAP()
;Result
| f1 ARRAY | f2 ARRAY |
|---|---|
| [0.00, -5.00, -3.33, -18.44] | [0.00, 0.00, -7.50, -7.50] |