corr()

The correlation coefficient of the least squares fit line of the adjusted counter value and epoch value of the time column. Given that the slope of a line for any counter value must be non-negative, this must also always be non-negative and in the range from 0.0 to 1.0. It measures how well the least squares fit the available data, where a value of 1.0 represents the strongest correlation between time and the counter increasing.

corr(
    summary CounterSummary
) RETURNS DOUBLE PRECISION

For more information about counter aggregation functions, see the hyperfunctions documentation.

Required arguments

NameTypeDescription
summaryCounterSummaryThe input CounterSummary from a counter_agg call

Returns

NameTypeDescription
corrDOUBLE PRECISIONThe correlation coefficient computed from the least squares fit of the adjusted counter values input to the CounterSummary

Sample usage

SELECT
    id,
    bucket,
    corr(summary)
FROM (
    SELECT
        id,
        time_bucket('15 min'::interval, ts) AS bucket,
        counter_agg(ts, val) AS summary
    FROM foo
    GROUP BY id, time_bucket('15 min'::interval, ts)
) t

Found an issue on this page?

Report an issue!

Related Content