NAG Library Routine Document

g02kaf  (ridge_opt)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

g02kaf calculates a ridge regression, optimizing the ridge parameter according to one of four prediction error criteria.

2
Specification

Fortran Interface
Subroutine g02kaf ( n, m, x, ldx, isx, ip, tau, y, h, opt, niter, tol, nep, orig, b, vif, res, rss, df, optloo, perr, ifail)
Integer, Intent (In):: n, m, ldx, isx(m), ip, opt, orig, optloo
Integer, Intent (Inout):: niter, ifail
Integer, Intent (Out):: df
Real (Kind=nag_wp), Intent (In):: x(ldx,m), tau, y(n), tol
Real (Kind=nag_wp), Intent (Inout):: h
Real (Kind=nag_wp), Intent (Out):: nep, b(ip+1), vif(ip), res(n), rss, perr(5)
C Header Interface
#include nagmk26.h
void  g02kaf_ ( const Integer *n, const Integer *m, const double x[], const Integer *ldx, const Integer isx[], const Integer *ip, const double *tau, const double y[], double *h, const Integer *opt, Integer *niter, const double *tol, double *nep, const Integer *orig, double b[], double vif[], double res[], double *rss, Integer *df, const Integer *optloo, double perr[], Integer *ifail)

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 parameter 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, g02kaf 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 D UT 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 DTD+hI -1 DT D DTD+hI -1 VT .  
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):
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-γ ;  
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.

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
Arguments

1:     n – IntegerInput
On entry: n, the number of observations.
Constraint: n>1.
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 g02kaf 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:     tau – Real (Kind=nag_wp)Input
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.
8:     yn – Real (Kind=nag_wp) arrayInput
On entry: the n values of the dependent variable y.
9:     h – Real (Kind=nag_wp)Input/Output
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.
10:   opt – IntegerInput
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.
11:   niter – IntegerInput/Output
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.
12:   tol – Real (Kind=nag_wp)Input
On entry: iterations of the ridge regression parameter h will halt when consecutive values of h lie within tol.
Constraint: tol>0.0.
13:   nep – Real (Kind=nag_wp)Output
On exit: the number of effective parameters, γ, in the model.
14:   orig – IntegerInput
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.
15:   bip+1 – Real (Kind=nag_wp) arrayOutput
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; bj+1 contains the parameter estimate for the jth independent variable in the model, for j=1,2,,ip.
16:   vifip – Real (Kind=nag_wp) arrayOutput
On exit: the variance inflation factors in the order indicated by isx. For the jth independent variable in the model, vifj is the value of vj, for j=1,2,,ip.
17:   resn – Real (Kind=nag_wp) arrayOutput
On exit: resi is the value of the ith residual for the fitted ridge regression model, for i=1,2,,n.
18:   rss – Real (Kind=nag_wp)Output
On exit: the sum of squares of residual values.
19:   df – IntegerOutput
On exit: the degrees of freedom for the residual sum of squares rss.
20:   optloo – IntegerInput
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.
21:   perr5 – Real (Kind=nag_wp) arrayOutput
On exit: the first four elements contain, in this order, the measures of prediction error: GCV, UEV, FPE and BIC.
If optloo=2, perr5 is the LOOCV estimate of prediction error; otherwise perr5 is not referenced.
22:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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, h=value.
Constraint: h>0.0.
On entry, n=value.
Constraint: n>1.
On entry, niter=value.
Constraint: niter1.
On entry, opt=value.
Constraint: opt=1, 2, 3 or 4.
On entry, optloo=value.
Constraint: optloo=1 or 2.
On entry, orig=value.
Constraint: orig=1 or 2.
On entry, tau=value.
Constraint: tau0.0.
On entry, tol=value.
Constraint: tol>0.0.
ifail=2
On entry, ip=value; m=value.
Constraint: 1ipm.
On entry, ip=value.
Constraint: sumisx=ip.
On entry, isxvalue=value.
Constraint: isxj=0 or 1.
On entry, ldx=value; n=value.
Constraint: ldxn.
On entry, m=value and n=value.
Constraint: mn.
ifail=3
SVD failed to converge.
ifail=-1
Maximum number of iterations used.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

Not applicable.

8
Parallelism and Performance

g02kaf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g02kaf 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

g02kaf allocates internally max 5 × 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 ridge regression is calculated that optimizes GCV prediction error.

10.1
Program Text

Program Text (g02kafe.f90)

10.2
Program Data

Program Data (g02kafe.d)

10.3
Program Results

Program Results (g02kafe.r)

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