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..::..Int32
On entry: n, the number of observations.
Constraint: n>1.
m
Type: System..::..Int32
On entry: the number of independent variables available in the data matrix X.
Constraint: mn.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, m]
Note: dim1 must satisfy the constraint: dim1n
On entry: the values of independent variables in the data matrix X.
isx
Type: array<System..::..Int32>[]()[][]
An array of size [m]
On entry: indicates which m independent variables are included in the model.
isx[j-1]=1
The jth variable in x will be included in the model.
isx[j-1]=0
Variable j is excluded.
Constraint: isx[j-1]=0​ or ​1, for j=1,2,,m.
ip
Type: System..::..Int32
On entry: m, the number of independent variables in the model.
Constraints:
  • 1ipm;
  • Exactly ip elements of isx must be equal to 1.
tau
Type: System..::..Double
On entry: singular values less than tau of the SVD of the data matrix X will be set equal to zero.
Suggested value: tau=0.0 
Constraint: tau0.0.
y
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: the n values of the dependent variable y.
h
Type: System..::..Double%
On entry: an initial value for the ridge regression parameter h; used as a starting point for the optimization.
Constraint: h>0.0.
On exit: h is the optimized value of the ridge regression parameter h.
opt
Type: System..::..Int32
On entry: the measure of prediction error used to optimize the ridge regression parameter h. The value of opt must be set equal to one of:
opt=1
Generalized cross-validation (GCV);
opt=2
Unbiased estimate of variance (UEV)
opt=3
Future prediction error (FPE)
opt=4
Bayesian information criteron (BIC).
Constraint: opt=1, 2, 3 or 4.
niter
Type: System..::..Int32%
On entry: the maximum number of iterations allowed to optimize the ridge regression parameter h.
Constraint: niter1.
On exit: the number of iterations used to optimize the ridge regression parameter h within tol.
tol
Type: System..::..Double
On entry: iterations of the ridge regression parameter h will halt when consecutive values of h lie within tol.
Constraint: tol>0.0.
nep
Type: System..::..Double%
On exit: the number of effective parameters, γ, in the model.
orig
Type: System..::..Int32
On entry: if orig=1, the parameter estimates b are calculated for the original data; otherwise orig=2 and the parameter estimates b~ are calculated for the standardized data.
Constraint: orig=1 or 2.
b
Type: array<System..::..Double>[]()[][]
An array of size [ip+1]
On exit: contains the intercept and parameter estimates for the fitted ridge regression model in the order indicated by isx. The first element of b contains the estimate for the intercept; b[j] contains the parameter estimate for the jth independent variable in the model, for j=1,2,,ip.
vif
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On exit: the variance inflation factors in the order indicated by isx. For the jth independent variable in the model, vif[j-1] is the value of vj, for j=1,2,,ip.
res
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: res[i-1] is the value of the ith residual for the fitted ridge regression model, for i=1,2,,n.
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..::..Int32
On entry: if optloo=2, the leave-one-out cross-validation estimate of prediction error is calculated; otherwise no such estimate is calculated and optloo=1.
Constraint: optloo=1 or 2.
perr
Type: array<System..::..Double>[]()[][]
An array of size [5]
On exit: the first four elements contain, in this order, the measures of prediction error: GCV, UEV, FPE and BIC.
If optloo=2, perr[4] is the LOOCV estimate of prediction error; otherwise perr[4] is not referenced.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

A linear model has the form:
y=c+Xβ+ε,
where
  • y is an n by 1 matrix of values of a dependent variable;
  • c is a scalar intercept term;
  • X is an n by m matrix of values of independent variables;
  • β is an m by 1 matrix of unknown values of parameters;
  • ε is an n by 1 matrix of unknown random errors such that variance of ε=σ2I.
Let X~ be the mean-centred X and y~ the mean-centred y. Furthermore, X~ is scaled such that the diagonal elements of the cross product matrix X~TX~ are one. The linear model now takes the form:
y~=X~β~+ε.
Ridge regression estimates the parameters β~ in a penalised least squares sense by finding the b~ that minimizes
X~b~-y~2+hb~2,h>0,
where · denotes the 2-norm and h is a scalar regularization or ridge parameter. For a given value of h, the parameter estimates b~ are found by evaluating
b~=X~TX~+hI-1X~Ty~.
Note that if h=0 the ridge regression solution is equivalent to the ordinary least squares solution.
Rather than calculate the inverse of (X~TX~+hI) directly, g02ka uses the singular value decomposition (SVD) of X~. After decomposing X~ into UDVT where U and V are orthogonal matrices and D is a diagonal matrix, the parameter estimates become
b~=VDTD+hI-1DUTy~.
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
DTDDTD+hI-1,
see Moody (1992) for details.
Any multi-collinearity in the design matrix X may be highlighted by calculating the variance inflation factors for the fitted model. The jth variance inflation factor, vj, is a scaled version of the multiple correlation coefficient between independent variable j and the other independent variables, Rj, and is given by
vj=11-Rj,j=1,2,,m.
The m variance inflation factors are calculated as the diagonal elements of the matrix:
X~TX~+hI-1X~TX~X~TX~+hI-1,
which, using the SVD of X~, is equivalent to the diagonal elements of the matrix:
VDTD+hI-1DTDDTD+hI-1VT.
Although parameter estimates b~ are calculated by using X~, it is usual to report the parameter estimates b associated with X. These are calculated from b~, and the means and scalings of X. Optionally, either b~ or b may be calculated.
The method can adopt one of four criteria to minimize while calculating a suitable value for h:
(a) Generalized cross-validation (GCV):
nsn-γ2;
(b) Unbiased estimate of variance (UEV):
sn-γ;
(c) Future prediction error (FPE):
1ns+2γsn-γ;
(d) Bayesian information criterion (BIC):
1ns+lognγsn-γ;
where s 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, h. Furthermore, the function will optionally return the leave-one-out cross-validation (LOOCV) prediction error.

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.
ifail=-1
Maximum number of iterations used.
ifail=1
On entry,n1;
ortau<0.0;
oropt1, 2, 3 or 4;
orh0.0;
oroptloo1 or 2;
ortol0.0;
orniter<1;
ororig1 or 2
ifail=2
On entry,m>n;
orip<1 or ip>m;
orAn element of isx0 or 1;
orip does not equal the sum of elements in isx.
ifail=3
SVD failed to converge.
ifail=4
Internal error. Check all array sizes and calls to g02ka. Please contact NAG.
ifail=-9000
An error occured, see message report.
ifail=-6000
Invalid Parameters value
ifail=-4000
Invalid dimension for array value
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

Not applicable.

Parallelism and Performance

None.

Further Comments

g02ka allocates internally max5×n-1,2×ip×ip+n+3×ip+n 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

Example program data: g02kae.d

Example program results: g02kae.r

See Also