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..::..Int32
On entry: n, the number of observations.
Constraint: n1.
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.
y
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: the n values of the dependent variable y.
lh
Type: System..::..Int32
On entry: the number of supplied ridge parameters.
Constraint: lh>0.
h
Type: array<System..::..Double>[]()[][]
An array of size [lh]
On entry: h[j-1] is the value of the jth ridge parameter h.
Constraint: h[j-1]0.0, for j=1,2,,lh.
nep
Type: array<System..::..Double>[]()[][]
An array of size [lh]
On exit: nep[j-1] is the number of effective parameters, γ, in the jth model, for j=1,2,,lh.
wantb
Type: System..::..Int32
On entry: defines the options for parameter estimates.
wantb=0
Parameter estimates are not calculated and b is not referenced.
wantb=1
Parameter estimates b are calculated for the original data.
wantb=2
Parameter estimates b~ are calculated for the standardized data.
Constraint: wantb=0, 1 or 2.
b
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, _tdb]
Note: dim1 must satisfy the constraint:
  • if wantb0, dim1ip+1;
  • otherwise dim11.
Note: the second dimension of the array b must be at least lh if wantb0, and at least 1 otherwise.
On exit: if wantb0, b contains the intercept and parameter estimates for the fitted ridge regression model in the order indicated by isx. b[0,j-1], for j=1,2,,lh, contains the estimate for the intercept; b[i,j-1] contains the parameter estimate for the ith independent variable in the model fitted with ridge parameter h[j-1], for i=1,2,,ip.
wantvf
Type: System..::..Int32
On entry: defines the options for variance inflation factors.
wantvf=0
Variance inflation factors are not calculated and the array vf is not referenced.
wantvf=1
Variance inflation factors are calculated.
Constraints:
  • wantvf=0 or 1;
  • if wantb=0, wantvf=1.
vf
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, _tdv]
Note: dim1 must satisfy the constraint:
  • if wantvf0, dim1ip;
  • otherwise dim11.
Note: the second dimension of the array vf must be at least lh if wantvf0, and at least 1 otherwise.
On exit: if wantvf=1, the variance inflation factors. For the ith independent variable in a model fitted with ridge parameter h[j-1], vf[i-1,j-1] is the value of vi, for i=1,2,,ip.
lpec
Type: System..::..Int32
On entry: the number of prediction error statistics to return; set lpec0 for no prediction error estimates.
pec
Type: array<System..::..String>[]()[][]
An array of size [lpec]
On entry: if lpec>0, pec[j-1] defines the jth prediction error, for j=1,2,,lpec; otherwise pec is not referenced.
pec[j-1]="B"
Bayesian information criterion (BIC).
pec[j-1]="F"
Future prediction error (FPE).
pec[j-1]="G"
Generalized cross-validation (GCV).
pec[j-1]="L"
Leave-one-out cross-validation (LOOCV).
pec[j-1]="U"
Unbiased estimate of variance (UEV).
Constraint: if lpec>0, pec[j-1]="B", "F", "G", "L" or "U", for j=1,2,,lpec.
pe
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, _tdpe]
Note: dim1 must satisfy the constraint:
  • if lpec>0, dim1lpec;
  • otherwise dim11.
Note: the second dimension of the array pe must be at least lh if lpec>0, and at least 1 otherwise.
On exit: if lpec0, pe is not referenced; otherwise pe[i-1,j-1] contains the prediction error of criterion pec[i-1] for the model fitted with ridge parameter h[j-1], for i=1,2,,lpec and j=1,2,,lh.
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 a 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 parameters 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, g02kb 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.
Given a value of h, any or all of the following prediction criteria are available:
(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-γ;
(e) Leave-one-out cross-validation (LOOCV),
where s is the sum of squares of residuals.
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.

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.
ifail=1
On entry,n<1,
orh[j-1]<0.0,
orlh0,
orwantb0, 1 or 2,
orwantvf0 or 1,
oran element of pec is not defined.
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
Both wantb and wantvf are zero.
ifail=4
Internal error. Check all array sizes and calls to g02kb. Please contact NAG.
ifail=-999
Internal memory allocation failed.
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

The accuracy of g02kb is closely related to that of the singular value decomposition.

Parallelism and Performance

None.

Further Comments

g02kb 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 selection of ridge regression models are calculated.

Example program (C#): g02kbe.cs

Example program data: g02kbe.d

Example program results: g02kbe.r

See Also