MTX_LINEAR_REGRESSION

This procedure creates the linear regression model using data stored in a matrix.

Usage

The MTX_LINEAR_REGRESSION stored procedure has the following syntax:
MTX_LINEAR_REGRESSION(modelName,predictorsMatrixName,predictedMatrixName,includeIntercept,calculateDiagnostics,useSVDSolver)
Parameters
modelName
The name of the created model.
Type: NVARCHAR(ANY)
predictorsMatrixName
The name of the matrix containing the predictors.
Type: NVARCHAR(ANY)
predictedMatrixName
The name of the matrix containing predicted values.
Type: NVARCHAR(ANY)
includeIntercept
Specifies whether the intercept term should be included in the model.
Type: BOOLEAN
useSVDSolver
Specifies whether Singular Value Decomposition and matrix multiplication should be used for solving the matrix equation.
Type: BOOLEAN
Returns
BOOLEAN TRUE only if the diagnostic information has been generated, for example, in the case of calculateDiagnostics=TRUE and number of model parameters larger than number of observations.

Details

This procedure builds the linear regression model using the QR solver of a non-singular model matrix, or the Moore-Penrose pseudoinversion in the case of a near-singular or exactly singular model matrix. Input data should be provided as Database Matrix Objects with observations provided in rows, and predictors in columns. The matrix of predicted values may contain multiple columns, that is, multiple predicted values. The diagnostic information, if requested, is saved as a set of matrices of names starting with modelName_linearmodel prefix. The set consists of following matrices:
  • modelName_linearmodel_R2: row vector containing R^2 (being a fraction of variance explained by the model) of models created for each output attribute (when calculateDiagnostics is TRUE)
  • modelName_linearmodel_RSS: row vector containing Residual Sum of Squares of models created for each output attribute (when calculateDiagnostics is TRUE)
  • modelName_linearmodel_SDEV: the matrix of standard deviations of model coefficients (when calculateDiagnostics is TRUE, diagnostics is possible and model is overdetermined)
  • modelName_linearmodel_TVAL: the matrix of the test statistics for the models' coefficients (when calcu-lateDiagnostics is TRUE, diagnostics is possible and model is overdetermined)
  • modelName_linearmodel_PVAL: the matrix of the two-sided p-values for the models' coefficients (when calculateDiagnostics is TRUE, diagnostics is possible and model is overdetermined)
  • modelName_linearmodel_Y_VAR_EST: the row vector containing the estimators of a variance of error term for each predicted variable (when calculateDiagnostics is TRUE, diagnostics is possible and model is overdetermined)

Model coefficients are saved as the matrix named modelName_linearmodel.

The constructed model can be applied to the data using the MTX_LINEAR_REGRESSION_APPLY procedure. Note that use of the Singular Value Decomposition and matrix multiplication is slower than the standard calculation, but is more stable in the case of an ill-posed, that is, near colinear, regression model.

Examples

call nzm..shape('1,2,3,4,5,6,7,8,9',100,10,'LR_EXAMPLE');
call nzm..shape('9,8,7,6,5,4,3,2,1',10,1,'LR_EXAMPLE_TRUE_COEFFS');
call nzm..gemm('LR_EXAMPLE','LR_EXAMPLE_TRUE_COEFFS',
 'LR_EXAMPLE_PREDICTED');
call nzm..mtx_linear_regression('LR_EXAMPLE_MODEL','LR_EXAMPLE ',
 'LR_EXAMPLE_PREDICTED', FALSE, FALSE, FALSE);
--- result verification
call nzm..copy_submatrix('LR_EXAMPLE_MODEL_linearmodel', 
 'LR_EXAMPLE_MODEL_linearmodel_eff',1,10,1,1);
call nzm..subtract('LR_EXAMPLE_TRUE_COEFFS',
 'LR_EXAMPLE_MODEL_linearmodel_eff', 'LR_EXAMPLE_MODEL_verif1');
call nzm..red_max_abs('LR_EXAMPLE_MODEL_verif1'); 
call nzm..delete_all_matrices();

 SHAPE
-------
 t
(1 row)

 SHAPE
-------
 t
(1 row)

 GEMM
------
 t
(1 row)

 MTX_LINEAR_REGRESSION
-----------------------
 f
(1 row)

 COPY_SUBMATRIX
----------------
 t
(1 row)

 SUBTRACT
----------
 t
(1 row)

   RED_MAX_ABS
-----------------
 8.3857463735873
(1 row)

 DELETE_ALL_MATRICES
---------------------
 t
(1 row)