User Documentation
 All Files Functions Groups
linear.sql_in File Reference

SQL functions for linear regression. More...

Go to the source code of this file.

Functions

aggregate
heteroskedasticity_test_result 
heteroskedasticity_test_linregr (float8 dependentVariable, float8[] independentVariables, float8[] olsCoefficients)
 Compute studentized Breuch-Pagan heteroskedasticity test for linear regression. More...
 
aggregate linregr_result linregr (float8 dependentVariable, float8[] independentVariables)
 Compute linear regression coefficients and diagnostic statistics. More...
 

Detailed Description

Date
January 2011
See Also
For a brief introduction to linear regression, see the module description Linear Regression.

Definition in file linear.sql_in.

Function Documentation

aggregate heteroskedasticity_test_result heteroskedasticity_test_linregr ( float8  dependentVariable,
float8[]  independentVariables,
float8[]  olsCoefficients 
)
Parameters
dependentVariableColumn containing the dependent variable
independentVariablesColumn containing the array of independent variables
olsCoefficientsColumn containing the array of the OLS coefficients (as obtained by linregr)
To include an intercept in the model, set one coordinate in the independentVariables array to 1.
Returns
A composite value:
  • test_statistic FLOAT8[] - Prob > test_statistc
  • p_value FLOAT8[] - Prob > test_statistc
Usage:
 SELECT (heteoskedasticity_test_linregr(dependentVariable,
 independentVariables, coef)).*
 FROM (
   SELECT linregr(dependentVariable, independentVariables).coef
 ) AS ols_coef, sourceName as src;

Definition at line 455 of file linear.sql_in.

aggregate linregr_result linregr ( float8  dependentVariable,
float8[]  independentVariables 
)
Parameters
dependentVariableColumn containing the dependent variable
independentVariablesColumn containing the array of independent variables
To include an intercept in the model, set one coordinate in the independentVariables array to 1.
Returns
A composite value:
  • coef FLOAT8[] - Array of coefficients, \( \boldsymbol c \)
  • r2 FLOAT8 - Coefficient of determination, \( R^2 \)
  • std_err FLOAT8[] - Array of standard errors, \( \mathit{se}(c_1), \dots, \mathit{se}(c_k) \)
  • t_stats FLOAT8[] - Array of t-statistics, \( \boldsymbol t \)
  • p_values FLOAT8[] - Array of p-values, \( \boldsymbol p \)
  • condition_no FLOAT8 - The condition number of matrix \( X^T X \).
Usage:
  • Get vector of coefficients \( \boldsymbol c \) and all diagnostic statistics:
    SELECT (linregr(dependentVariable,
            independentVariables)).*
    FROM sourceName;
  • Get vector of coefficients \( \boldsymbol c \):
    SELECT (linregr(dependentVariable,
            independentVariables)).coef
    FROM sourceName;
  • Get a subset of the output columns, e.g., only the array of coefficients \( \boldsymbol c \), the coefficient of determination \( R^2 \), and the array of p-values \( \boldsymbol p \):
    SELECT (lr).coef, (lr).r2, (lr).p_values
    FROM (
        SELECT linregr( dependentVariable,
                        independentVariables) AS lr
        FROM sourceName
    ) AS subq;

Definition at line 508 of file linear.sql_in.