G02KBF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G02KBF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G02KBF calculates a ridge regression, with ridge parameters supplied by you.

2  Specification

SUBROUTINE G02KBF ( N, M, X, LDX, ISX, IP, Y, LH, H, NEP, WANTB, B, LDB, WANTVF, VF, LDVF, LPEC, PEC, PE, LDPE, IFAIL)
INTEGER  N, M, LDX, ISX(M), IP, LH, WANTB, LDB, WANTVF, LDVF, LPEC, LDPE, IFAIL
REAL (KIND=nag_wp)  X(LDX,M), Y(N), H(LH), NEP(LH), B(LDB,*), VF(LDVF,*), PE(LDPE,*)
CHARACTER(1)  PEC(LPEC)

3  Description

A linear model has the form:
y = c+Xβ+ε ,  
where
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 + h b~ 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~T X~+hI -1 X~T y~ .  
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, G02KBF 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~ = V DTD+hI -1 DUT y~ .  
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
DT D DT D+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 = 1 1-Rj ,j=1,2,,m .  
The m variance inflation factors are calculated as the diagonal elements of the matrix:
X~T X~+hI -1 X~T X~ X~T X~+hI-1 ,  
which, using the SVD of X~, is equivalent to the diagonal elements of the matrix:
V DT D+hI -1 DT D DT D+hI -1 VT .  
Given a value of h, any or all of the following prediction criteria are available:
(a) Generalized cross-validation (GCV):
ns n-γ 2 ;  
(b) Unbiased estimate of variance (UEV):
s n-γ ;  
(c) Future prediction error (FPE):
1n s+ 2γs n-γ ;  
(d) Bayesian information criterion (BIC):
1n s+ lognγs n-γ ;  
(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.

4  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

5  Parameters

1:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N1.
2:     M – INTEGERInput
On entry: the number of independent variables available in the data matrix X.
Constraint: MN.
3:     XLDXM – REAL (KIND=nag_wp) arrayInput
On entry: the values of independent variables in the data matrix X.
4:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G02KBF is called.
Constraint: LDXN.
5:     ISXM – INTEGER arrayInput
On entry: indicates which m independent variables are included in the model.
ISXj=1
The jth variable in X will be included in the model.
ISXj=0
Variable j is excluded.
Constraint: ISXj=0 ​ or ​ 1, for j=1,2,,M.
6:     IP – INTEGERInput
On entry: m, the number of independent variables in the model.
Constraints:
  • 1IPM;
  • Exactly IP elements of ISX must be equal to 1.
7:     YN – REAL (KIND=nag_wp) arrayInput
On entry: the n values of the dependent variable y.
8:     LH – INTEGERInput
On entry: the number of supplied ridge parameters.
Constraint: LH>0.
9:     HLH – REAL (KIND=nag_wp) arrayInput
On entry: Hj is the value of the jth ridge parameter h.
Constraint: Hj0.0, for j=1,2,,LH.
10:   NEPLH – REAL (KIND=nag_wp) arrayOutput
On exit: NEPj is the number of effective parameters, γ, in the jth model, for j=1,2,,LH.
11:   WANTB – INTEGERInput
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.
12:   BLDB* – REAL (KIND=nag_wp) arrayOutput
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. B1j, for j=1,2,,LH, contains the estimate for the intercept; Bi+1j contains the parameter estimate for the ith independent variable in the model fitted with ridge parameter Hj, for i=1,2,,IP.
13:   LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which G02KBF is called.
Constraints:
  • if WANTB0, LDBIP+1;
  • otherwise LDB1.
14:   WANTVF – INTEGERInput
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.
15:   VFLDVF* – REAL (KIND=nag_wp) arrayOutput
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 Hj, VFij is the value of vi, for i=1,2,,IP.
16:   LDVF – INTEGERInput
On entry: the first dimension of the array VF as declared in the (sub)program from which G02KBF is called.
Constraints:
  • if WANTVF0, LDVFIP;
  • otherwise LDVF1.
17:   LPEC – INTEGERInput
On entry: the number of prediction error statistics to return; set LPEC0 for no prediction error estimates.
18:   PECLPEC – CHARACTER(1) arrayInput
On entry: if LPEC>0, PECj defines the jth prediction error, for j=1,2,,LPEC; otherwise PEC is not referenced.
PECj='B'
Bayesian information criterion (BIC).
PECj='F'
Future prediction error (FPE).
PECj='G'
Generalized cross-validation (GCV).
PECj='L'
Leave-one-out cross-validation (LOOCV).
PECj='U'
Unbiased estimate of variance (UEV).
Constraint: if LPEC>0, PECj='B', 'F', 'G', 'L' or 'U', for j=1,2,,LPEC.
19:   PELDPE* – REAL (KIND=nag_wp) arrayOutput
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 PEij contains the prediction error of criterion PECi for the model fitted with ridge parameter Hj, for i=1,2,,LPEC and j=1,2,,LH.
20:   LDPE – INTEGERInput
On entry: the first dimension of the array PE as declared in the (sub)program from which G02KBF is called.
Constraints:
  • if LPEC>0, LDPELPEC;
  • otherwise LDPE1.
21:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry, Hi<0 for at least one i.
On entry, LH=value.
Constraint: LH>0.
On entry, M=value and N=value.
Constraint: MN.
On entry, N=value.
Constraint: N1.
On entry, PECi is invalid for at least one i.
On entry, WANTB=value.
Constraint: WANTB=0, 1 or 2.
On entry, WANTVF=value.
Constraint: WANTVF=0 or 1.
IFAIL=2
IP does not equal the sum of elements in ISX.
On entry, ISXi0 or 1 for at least one i.
On entry, LDB=value and IP=value.
Constraint: if WANTB0, LDBIP+1.
On entry, LDPE=value and LPEC=value.
Constraint: LDPELPEC.
On entry, LDVF=value and IP=value.
Constraint: if WANTVF0, LDVFIP.
On entry, LDX=value and N=value.
Constraint: LDXN.
IFAIL=3
On entry, WANTB=0 and WANTVF=0.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

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

8  Parallelism and Performance

G02KBF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02KBF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

G02KBF allocates internally max5×N-1,2×IP×IP+N+3×IP+N elements of double precision storage.

10  Example

This example reads in data from an experiment to model body fat, and a selection of ridge regression models are calculated.

10.1  Program Text

Program Text (g02kbfe.f90)

10.2  Program Data

Program Data (g02kbfe.d)

10.3  Program Results

Program Results (g02kbfe.r)


G02KBF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015