g02kb calculates a ridge regression, with ridge parameters supplied by you.
Syntax
C# |
---|
public static void g02kb( int n, int m, double[,] x, int[] isx, int ip, double[] y, int lh, double[] h, double[] nep, int wantb, double[,] b, int wantvf, double[,] vf, int lpec, string[] pec, double[,] pe, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g02kb ( _ n As Integer, _ m As Integer, _ x As Double(,), _ isx As Integer(), _ ip As Integer, _ y As Double(), _ lh As Integer, _ h As Double(), _ nep As Double(), _ wantb As Integer, _ b As Double(,), _ wantvf As Integer, _ vf As Double(,), _ lpec As Integer, _ pec As String(), _ pe As Double(,), _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g02kb( int n, int m, array<double,2>^ x, array<int>^ isx, int ip, array<double>^ y, int lh, array<double>^ h, array<double>^ nep, int wantb, array<double,2>^ b, int wantvf, array<double,2>^ vf, int lpec, array<String^>^ pec, array<double,2>^ pe, [OutAttribute] int% ifail ) |
F# |
---|
static member g02kb : n : int * m : int * x : float[,] * isx : int[] * ip : int * y : float[] * lh : int * h : float[] * nep : float[] * wantb : int * b : float[,] * wantvf : int * vf : float[,] * lpec : int * pec : string[] * pe : float[,] * ifail : int byref -> unit |
Parameters
- n
- Type: System..::..Int32On entry: , the number of observations.Constraint: .
- m
- Type: System..::..Int32On entry: the number of independent variables available in the data matrix .Constraint: .
- x
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, m]Note: dim1 must satisfy the constraint:On entry: the values of independent variables in the data matrix .
- isx
- Type: array<System..::..Int32>[]()[][]An array of size [m]On entry: indicates which independent variables are included in the model.
- The th variable in x will be included in the model.
- Variable is excluded.
Constraint: , for .
- ip
- Type: System..::..Int32On entry: , the number of independent variables in the model.
- y
- Type: array<System..::..Double>[]()[][]An array of size [n]On entry: the values of the dependent variable .
- lh
- Type: System..::..Int32On entry: the number of supplied ridge parameters.Constraint: .
- h
- Type: array<System..::..Double>[]()[][]An array of size [lh]On entry: is the value of the th ridge parameter .Constraint: , for .
- nep
- Type: array<System..::..Double>[]()[][]An array of size [lh]On exit: is the number of effective parameters, , in the th model, for .
- wantb
- Type: System..::..Int32On entry: defines the options for parameter estimates.
- Parameter estimates are not calculated and b is not referenced.
- Parameter estimates are calculated for the original data.
- Parameter estimates are calculated for the standardized data.
Constraint: , or .
- b
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, _tdb]Note: dim1 must satisfy the constraint:
- if , ;
- otherwise .
Note: the second dimension of the array b must be at least if , and at least otherwise.
- wantvf
- Type: System..::..Int32On entry: defines the options for variance inflation factors.
- Variance inflation factors are not calculated and the array vf is not referenced.
- Variance inflation factors are calculated.
Constraints:- or ;
- if , .
- vf
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, _tdv]Note: dim1 must satisfy the constraint:
- if , ;
- otherwise .
Note: the second dimension of the array vf must be at least if , and at least otherwise.On exit: if , the variance inflation factors. For the th independent variable in a model fitted with ridge parameter , is the value of , for .
- lpec
- Type: System..::..Int32On entry: the number of prediction error statistics to return; set for no prediction error estimates.
- pec
- Type: array<System..::..String>[]()[][]An array of size [lpec]On entry: if , defines the th prediction error, for ; otherwise pec is not referenced.
- Bayesian information criterion (BIC).
- Future prediction error (FPE).
- Generalized cross-validation (GCV).
- Leave-one-out cross-validation (LOOCV).
- Unbiased estimate of variance (UEV).
Constraint: if , , , , or , for .
- pe
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, _tdpe]Note: dim1 must satisfy the constraint:
- if , ;
- otherwise .
Note: the second dimension of the array pe must be at least if , and at least otherwise.On exit: if , pe is not referenced; otherwise contains the prediction error of criterion for the model fitted with ridge parameter , for and .
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
A linear model has the form:
where
- is an by matrix of values of a dependent variable;
- is a scalar intercept term;
- is an by matrix of values of independent variables;
- is a by matrix of unknown values of parameters;
- is an by matrix of unknown random errors such that variance of .
Let be the mean-centred and the mean-centred . Furthermore, is scaled such that the diagonal elements of the cross product matrix are one. The linear model now takes the form:
Ridge regression estimates the parameters in a penalised least squares sense by finding the that minimizes
where denotes the -norm and is a scalar regularization or ridge parameter. For a given value of , the parameters estimates are found by evaluating
Note that if the ridge regression solution is equivalent to the ordinary least squares solution.
Rather than calculate the inverse of () directly, g02kb uses the singular value decomposition (SVD) of . After decomposing into where and are orthogonal matrices and is a diagonal matrix, the parameter estimates become
A consequence of introducing the ridge parameter is that the effective number of parameters, , in the model is given by the sum of diagonal elements of
see Moody (1992) for details.
Any multi-collinearity in the design matrix may be highlighted by calculating the variance inflation factors for the fitted model. The th variance inflation factor, , is a scaled version of the multiple correlation coefficient between independent variable and the other independent variables, , and is given by
The variance inflation factors are calculated as the diagonal elements of the matrix:
which, using the SVD of , is equivalent to the diagonal elements of the matrix:
Given a value of , any or all of the following prediction criteria are available:
(a) | Generalized cross-validation (GCV):
|
||
(b) | Unbiased estimate of variance (UEV):
|
||
(c) | Future prediction error (FPE):
|
||
(d) | Bayesian information criterion (BIC):
|
||
(e) | Leave-one-out cross-validation (LOOCV), |
where is the sum of squares of residuals.
Although parameter estimates are calculated by using , it is usual to report the parameter estimates associated with . These are calculated from , and the means and scalings of . Optionally, either or may be calculated.
References
Hastie T, Tibshirani R and Friedman J (2003) The Elements of Statistical Learning: Data Mining, Inference and Prediction Springer Series in Statistics
Moody J.E. (1992) The effective number of parameters: An analysis of generalisation and regularisation in nonlinear learning systems In: Neural Information Processing Systems (eds J E Moody, S J Hanson, and R P Lippmann) 4 847–854 Morgan Kaufmann San Mateo CA
Error Indicators and Warnings
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface
(LDX, LDB, LDVF, LDPE) In these
cases, an error in another parameter has usually caused an incorrect value to be inferred.
On entry, , or , or , or , or , or or , or an element of pec is not defined.
- Internal memory allocation failed.
Accuracy
The accuracy of g02kb is closely related to that of the singular value decomposition.
Parallelism and Performance
None.
Further Comments
g02kb allocates internally elements of double precision storage.
Example
This example reads in data from an experiment to model body fat, and a selection of ridge regression models are calculated.
Example program (C#): g02kbe.cs