REGR_R2 Function [Aggregate]

Computes the coefficient of determination (also referred to as R-squared or the goodness-of-fit statistic) for the regression line.

Syntax 1

REGR_R2(dependent-expression, independent-expression)

Syntax 2

REGR_R2(dependent-expression, independent-expression)
OVER (window-spec)

Parameters

Parameter

Description

dependent-expression

The variable that is affected by the independent variable.

independent-expression

The variable that influences the outcome.

Returns

DOUBLE

Usage

This function converts its arguments to DOUBLE, performs the computation in double-precision floating-point, and returns a DOUBLE as the result. If applied to an empty set, then REGR_R2 returns NULL.

REGR_R2 is applied to the set of (dependent-expression and independent-expression) pairs after eliminating all pairs for which either dependent-expression or independent-expression is NULL. Sybase IQ then applies the following algorithm:

  • REGR_R2 calculates VAR_POP(x) and returns NULL if VAR_POP(x) = 0; otherwise, it calculates VAR_POP(y) and returns the value 1 if VAR_POP(y) = 0.

  • If neither VAR_POP(x) or VAR_POP(y) is zero, the return value is POWER(CORR(y,x),2)

where y represents the dependent-expression and x represents the independent-expression.

See SQL Anywhere Server - SQL Usage > Querying and modifying data > OLAP support > Window functions in SQL Anywhere > Row numbering functions > Mathematical formulas for the aggregate functions.

Note: ROLLUP and CUBE are not supported in the GROUP BY clause with Syntax 1. DISTINCT is not supported.

Syntax 2 represents usage as a window function in a SELECT statement. As such, you can specify elements of window-spec either in the function syntax (inline), or with a WINDOW clause in the SELECT statement.

Example

The following example returns the value 0.19379959710325653:
SELECT REGR_R2( Salary, ( YEAR( NOW() ) - YEAR( BirthDate ) ) )FROM Employees;

Standards and Compatibility

  • SQL—ISO/ANSI SQL compliant. SQL/OLAP feature T612.

  • Sybase—Compatible with SQL Anywhere.

Related concepts
Windowing Aggregate Function Usage