covariance()

covariance(
    summary StatsSummary2D,
    method TEXT 
) RETURNS DOUBLE PRECISION

The covariance of the least squares fit line computed from a two-dimensional statistical aggregate.

The method determines whether you calculate a 'population' or 'sample' covariance. These values can be provided as their full names, or you can abbreviate them as pop or samp. These are the only four accepted values for the method argument. The default is sample.

For more information about statistical aggregate functions, see the hyperfunctions documentation.

Required arguments

NameTypeDescription
summaryStatsSummary2DThe input StatsSummary from a stats_agg call

Optional Arguments

NameTypeDescription
methodTEXTThe method for the calculation 'population' or 'sample' (default)

Returns

NameTypeDescription
covarianceDOUBLE PRECISIONThe x intercept of the least squares fit line.

Sample usage

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

Found an issue on this page?

Report an issue!

Related Content