NAG FL Interface
g02kbf (ridge)

Settings help

FL Name Style:


FL Specification Language:


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 <nag.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)
The routine may be called by the names g02kbf or nagf_correg_ridge.

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~TX~+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 (DTD+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~TX~+hI)-1 X~T X~ (X~TX~+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 .  
Given a value of h, any or all of the following prediction criteria are available:
  1. (a)Generalized cross-validation (GCV):
    ns (n-γ) 2 ;  
  2. (b)Unbiased estimate of variance (UEV):
    s n-γ ;  
  3. (c)Future prediction error (FPE):
    1n (s+ 2γs n-γ ) ;  
  4. (d)Bayesian information criterion (BIC):
    1n (s+ log(n)γs n-γ ) ;  
  5. (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 Integer Input
On entry: n, the number of observations.
Constraint: n1.
2: m Integer Input
On entry: the number of independent variables available in the data matrix X.
Constraint: mn.
3: x(ldx,m) Real (Kind=nag_wp) array Input
On entry: the values of independent variables in the data matrix X.
4: ldx Integer Input
On entry: the first dimension of the array x as declared in the (sub)program from which g02kbf is called.
Constraint: ldxn.
5: isx(m) Integer array Input
On entry: indicates which m independent variables are included in the model.
isx(j)=1
The jth variable in x will be included in the model.
isx(j)=0
Variable j is excluded.
Constraint: isx(j)=0 or 1, for j=1,2,,m.
6: ip Integer Input
On entry: m, the number of independent variables in the model.
Constraints:
  • 1ipm;
  • Exactly ip elements of isx must be equal to 1.
7: y(n) Real (Kind=nag_wp) array Input
On entry: the n values of the dependent variable y.
8: lh Integer Input
On entry: the number of supplied ridge parameters.
Constraint: lh>0.
9: h(lh) Real (Kind=nag_wp) array Input
On entry: h(j) is the value of the jth ridge parameter h.
Constraint: h(j)0.0, for j=1,2,,lh.
10: nep(lh) Real (Kind=nag_wp) array Output
On exit: nep(j) is the number of effective parameters, γ, in the jth model, for j=1,2,,lh.
11: wantb Integer Input
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: b(ldb,*) Real (Kind=nag_wp) array Output
Note: the second dimension of the array b must be at least lh if wantb0.
On exit: if wantb0, b contains the intercept and parameter estimates for the fitted ridge regression model in the order indicated by isx. b(1,j), for j=1,2,,lh, contains the estimate for the intercept; b(i+1,j) contains the parameter estimate for the ith independent variable in the model fitted with ridge parameter h(j), for i=1,2,,ip.
13: ldb Integer Input
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 Integer Input
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: vf(ldvf,*) Real (Kind=nag_wp) array Output
Note: the second dimension of the array vf must be at least lh if wantvf0.
On exit: if wantvf=1, the variance inflation factors. For the ith independent variable in a model fitted with ridge parameter h(j), vf(i,j) is the value of vi, for i=1,2,,ip.
16: ldvf Integer Input
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 Integer Input
On entry: the number of prediction error statistics to return; set lpec0 for no prediction error estimates.
18: pec(lpec) Character(1) array Input
On entry: if lpec>0, pec(j) defines the jth prediction error, for j=1,2,,lpec; otherwise pec is not referenced.
pec(j)='B'
Bayesian information criterion (BIC).
pec(j)='F'
Future prediction error (FPE).
pec(j)='G'
Generalized cross-validation (GCV).
pec(j)='L'
Leave-one-out cross-validation (LOOCV).
pec(j)='U'
Unbiased estimate of variance (UEV).
Constraint: if lpec>0, pec(j)='B', 'F', 'G', 'L' or 'U', for j=1,2,,lpec.
19: pe(ldpe,*) Real (Kind=nag_wp) array Output
Note: the second dimension of the array pe must be at least lh if lpec>0.
On exit: if lpec0, pe is not referenced; otherwise pe(i,j) contains the prediction error of criterion pec(i) for the model fitted with ridge parameter h(j), for i=1,2,,lpec and j=1,2,,lh.
20: ldpe Integer Input
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 Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. 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(j)<0 for at least one j.
Constraint: h(j)0.0, for all j.
On entry, lh=value.
Constraint: lh>0.
On entry, m=value and n=value.
Constraint: mn.
On entry, n=value.
Constraint: n1.
On entry, pec(j) is invalid for at least one j.
Constraint: if lpec>0, pec(j)='B', 'F', 'G', 'L' or 'U', for all j.
On entry, wantb=value.
Constraint: wantb=0, 1 or 2.
On entry, wantvf=value.
Constraint: wantvf=0 or 1.
ifail=2
On entry, ip is not equal to the sum of elements in isx.
Constraint: exactly ip elements of isx must be equal to 1.
On entry, isx(j)0 or 1 for at least one j.
Constraint: isx(j)=0 or 1, for all j.
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.
Constraint: wantb=0, wantvf=1.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface 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 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 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)