g02ka calculates a ridge regression, optimizing the ridge parameter according to one of four prediction error criteria.
Syntax
C# |
---|
public static void g02ka( int n, int m, double[,] x, int[] isx, int ip, double tau, double[] y, ref double h, int opt, ref int niter, double tol, out double nep, int orig, double[] b, double[] vif, double[] res, out double rss, out int df, int optloo, double[] perr, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g02ka ( _ n As Integer, _ m As Integer, _ x As Double(,), _ isx As Integer(), _ ip As Integer, _ tau As Double, _ y As Double(), _ ByRef h As Double, _ opt As Integer, _ ByRef niter As Integer, _ tol As Double, _ <OutAttribute> ByRef nep As Double, _ orig As Integer, _ b As Double(), _ vif As Double(), _ res As Double(), _ <OutAttribute> ByRef rss As Double, _ <OutAttribute> ByRef df As Integer, _ optloo As Integer, _ perr As Double(), _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g02ka( int n, int m, array<double,2>^ x, array<int>^ isx, int ip, double tau, array<double>^ y, double% h, int opt, int% niter, double tol, [OutAttribute] double% nep, int orig, array<double>^ b, array<double>^ vif, array<double>^ res, [OutAttribute] double% rss, [OutAttribute] int% df, int optloo, array<double>^ perr, [OutAttribute] int% ifail ) |
F# |
---|
static member g02ka : n : int * m : int * x : float[,] * isx : int[] * ip : int * tau : float * y : float[] * h : float byref * opt : int * niter : int byref * tol : float * nep : float byref * orig : int * b : float[] * vif : float[] * res : float[] * rss : float byref * df : int byref * optloo : int * perr : 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.
- tau
- Type: System..::..DoubleOn entry: singular values less than tau of the SVD of the data matrix will be set equal to zero.Suggested value:Constraint: .
- y
- Type: array<System..::..Double>[]()[][]An array of size [n]On entry: the values of the dependent variable .
- h
- Type: System..::..Double%On entry: an initial value for the ridge regression parameter ; used as a starting point for the optimization.Constraint: .On exit: h is the optimized value of the ridge regression parameter .
- opt
- Type: System..::..Int32On entry: the measure of prediction error used to optimize the ridge regression parameter . The value of opt must be set equal to one of:
- Generalized cross-validation (GCV);
- Unbiased estimate of variance (UEV)
- Future prediction error (FPE)
- Bayesian information criteron (BIC).
Constraint: , , or .
- niter
- Type: System..::..Int32%On entry: the maximum number of iterations allowed to optimize the ridge regression parameter .Constraint: .On exit: the number of iterations used to optimize the ridge regression parameter within tol.
- tol
- Type: System..::..DoubleOn entry: iterations of the ridge regression parameter will halt when consecutive values of lie within tol.Constraint: .
- nep
- Type: System..::..Double%On exit: the number of effective parameters, , in the model.
- orig
- Type: System..::..Int32On entry: if , the parameter estimates are calculated for the original data; otherwise and the parameter estimates are calculated for the standardized data.Constraint: or .
- b
- Type: array<System..::..Double>[]()[][]An array of size []
- vif
- Type: array<System..::..Double>[]()[][]An array of size [ip]On exit: the variance inflation factors in the order indicated by isx. For the th independent variable in the model, is the value of , for .
- res
- Type: array<System..::..Double>[]()[][]An array of size [n]On exit: is the value of the th residual for the fitted ridge regression model, for .
- rss
- Type: System..::..Double%On exit: the sum of squares of residual values.
- df
- Type: System..::..Int32%On exit: the degrees of freedom for the residual sum of squares rss.
- optloo
- Type: System..::..Int32On entry: if , the leave-one-out cross-validation estimate of prediction error is calculated; otherwise no such estimate is calculated and .Constraint: or .
- perr
- Type: array<System..::..Double>[]()[][]An array of size []On exit: the first four elements contain, in this order, the measures of prediction error: GCV, UEV, FPE and BIC.If , is the LOOCV estimate of prediction error; otherwise is not referenced.
- 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 an 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 parameter 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, g02ka 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:
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.
The method can adopt one of four criteria to minimize while calculating a suitable value for :
where is the sum of squares of residuals. However, the function returns all four of the above prediction errors regardless of the one selected to minimize the ridge parameter, . Furthermore, the function will optionally return the leave-one-out cross-validation (LOOCV) prediction error.
(a) | Generalized cross-validation (GCV):
|
||
(b) | Unbiased estimate of variance (UEV):
|
||
(c) | Future prediction error (FPE):
|
||
(d) | Bayesian information criterion (BIC):
|
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) In these
cases, an error in another parameter has usually caused an incorrect value to be inferred.
- Maximum number of iterations used.
On entry, ; or ; or , , or ; or ; or or ; or ; or ; or or
- SVD failed to converge.
Accuracy
Not applicable.
Parallelism and Performance
None.
Further Comments
g02ka allocates internally elements of double precision storage.
Example
This example reads in data from an experiment to model body fat, and a ridge regression is calculated that optimizes GCV prediction error.
Example program (C#): g02kae.cs