FirebirdSQL logo

Linear Regression Aggregate Functions

Linear regression functions are useful for trend line continuation.The trend or regression line is usually a pattern followed by a set of values.Linear regression is useful to predict future values.To continue the regression line, you need to know the slope and the point of intersection with the y-axis.As set of linear functions can be used for calculating these values.

In the function syntax, y is interpreted as an x-dependent variable.

The linear regression aggregate functions take a pair of arguments, the dependent variable expression (y) and the independent variable expression (x), which are both numeric value expressions.Any row in which either argument evaluates to NULL is removed from the rows that qualify.If there are no rows that qualify, then the result of REGR_COUNT is 0 (zero), and the other linear regression aggregate functions result in NULL.

REGR_AVGX()

Average of the independent variable of the regression line

Result type

DOUBLE PRECISION

Syntax
REGR_AVGX ( <y>, <x> )
Table 1. REGR_AVGX Function Parameters
Parameter Description

y

Dependent variable of the regression line.It may contain a table column, a constant, a variable, an expression, a non-aggregate function or a UDF.Aggregate functions are not allowed as expressions.

x

Independent variable of the regression line.It may contain a table column, a constant, a variable, an expression, a non-aggregate function or a UDF.Aggregate functions are not allowed as expressions.

The function REGR_AVGX calculates the average of the independent variable (x) of the regression line.

The function REGR_AVGX(<y>, <x>) is equivalent to

SUM(<exprX>) / REGR_COUNT(<y>, <x>)

<exprX> :==
  CASE WHEN <x> IS NOT NULL AND <y> IS NOT NULL THEN <x> END