Skip to content

slope()

Calculate the slope from a two-dimensional statistical aggregate

Since 1.3.0

Calculate the slope of the linear fitting line from a two-dimensional statistical aggregate. The calculation uses the standard least-squares fitting for linear regression.

Calculate the slope from independent variable y and dependent variable x for each 15-minute time bucket:

SELECT
id,
time_bucket('15 min'::interval, ts) AS bucket,
slope(stats_agg(y, x)) AS summary
FROM foo
GROUP BY id, time_bucket('15 min'::interval, ts)

The syntax is:

slope(
summary StatsSummary2D
) RETURNS DOUBLE PRECISION
NameTypeDefaultRequiredDescription
summaryStatsSummary2D-The statistical aggregate produced by a stats_agg call
ColumnTypeDescription
slopeDOUBLE PRECISIONThe slope of the least-squares fit line