NAG Library Routine Document

g02kbf  (ridge)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

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

2
Specification

Fortran Interface
Subroutine g02kbf ( n, m, x, ldx, isx, ip, y, lh, h, nep, wantb, b, ldb, wantvf, vf, ldvf, lpec, pec, pe, ldpe, ifail)
Integer, Intent (In):: n, m, ldx, isx(m), ip, lh, wantb, ldb, wantvf, ldvf, lpec, ldpe
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: x(ldx,m), y(n), h(lh)
Real (Kind=nag_wp), Intent (Inout):: b(ldb,*), vf(ldvf,*), pe(ldpe,*)
Real (Kind=nag_wp), Intent (Out):: nep(lh)
Character (1), Intent (In):: pec(lpec)
C Header Interface
#include nagmk26.h
void  g02kbf_ ( const Integer *n, const Integer *m, const double x[], const Integer *ldx, const Integer isx[], const Integer *ip, const double y[], const Integer *lh, const double h[], double nep[], const Integer *wantb, double b[], const Integer *ldb, const Integer *wantvf, double vf[], const Integer *ldvf, const Integer *lpec, const char pec[], double pe[], const Integer *ldpe, Integer *ifail, const Charlen length_pec)

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
Arguments

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 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, 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.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

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)

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