hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_ridge_opt (g02ka)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_correg_ridge_opt (g02ka) calculates a ridge regression, optimizing the ridge parameter according to one of four prediction error criteria.

Syntax

[h, niter, nep, b, vif, res, rss, df, perr, ifail] = g02ka(x, isx, ip, y, h, opt, niter, tol, orig, optloo, 'n', n, 'm', m, 'tau', tau)
[h, niter, nep, b, vif, res, rss, df, perr, ifail] = nag_correg_ridge_opt(x, isx, ip, y, h, opt, niter, tol, orig, optloo, 'n', n, 'm', m, 'tau', tau)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 24: tau was made optional

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, nag_correg_ridge_opt (g02ka) 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.

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

Parameters

Compulsory Input Parameters

1:     xldxm – double array
ldx, the first dimension of the array, must satisfy the constraint ldxn.
The values of independent variables in the data matrix X.
2:     isxm int64int32nag_int array
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.
3:     ip int64int32nag_int scalar
m, the number of independent variables in the model.
Constraints:
  • 1ipm;
  • Exactly ip elements of isx must be equal to 1.
4:     yn – double array
The n values of the dependent variable y.
5:     h – double scalar
An initial value for the ridge regression parameter h; used as a starting point for the optimization.
Constraint: h>0.0.
6:     opt int64int32nag_int scalar
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.
7:     niter int64int32nag_int scalar
The maximum number of iterations allowed to optimize the ridge regression parameter h.
Constraint: niter1.
8:     tol – double scalar
Iterations of the ridge regression parameter h will halt when consecutive values of h lie within tol.
Constraint: tol>0.0.
9:     orig int64int32nag_int scalar
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.
10:   optloo int64int32nag_int scalar
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.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the array y and the first dimension of the array x. (An error is raised if these dimensions are not equal.)
n, the number of observations.
Constraint: n>1.
2:     m int64int32nag_int scalar
Default: the dimension of the array isx and the second dimension of the array x. (An error is raised if these dimensions are not equal.)
The number of independent variables available in the data matrix X.
Constraint: mn.
3:     tau – double scalar
Default: tau=0.0
Singular values less than tau of the SVD of the data matrix X will be set equal to zero.
Constraint: tau0.0.

Output Parameters

1:     h – double scalar
h is the optimized value of the ridge regression parameter h.
2:     niter int64int32nag_int scalar
The number of iterations used to optimize the ridge regression parameter h within tol.
3:     nep – double scalar
The number of effective parameters, γ, in the model.
4:     bip+1 – double array
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.
5:     vifip – double array
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.
6:     resn – double array
resi is the value of the ith residual for the fitted ridge regression model, for i=1,2,,n.
7:     rss – double scalar
The sum of squares of residual values.
8:     df int64int32nag_int scalar
The degrees of freedom for the residual sum of squares rss.
9:     perr5 – double array
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.
10:   ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
Constraint: h>0.0.
Constraint: n>1.
Constraint: niter1.
Constraint: opt=1, 2, 3 or 4.
Constraint: optloo=1 or 2.
Constraint: orig=1 or 2.
Constraint: tau0.0.
Constraint: tol>0.0.
   ifail=2
Constraint: 1ipm.
Constraint: isxj=0 or 1.
Constraint: ldxn.
Constraint: mn.
Constraint: sumisx=ip.
   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.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

nag_correg_ridge_opt (g02ka) allocates internally max 5 × 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 ridge regression is calculated that optimizes GCV prediction error.
function g02ka_example


fprintf('g02ka example results\n\n');

% Data
x = [19.5, 43.1, 29.1;
     24.7, 49.8, 28.2;
     30.7, 51.9, 37.0;
     29.8, 54.3, 31.1;
     19.1, 42.2, 30.9;
     25.6, 53.9, 23.7;
     31.4, 58.5, 27.6;
     27.9, 52.1, 30.6;
     22.1, 49.9, 23.2;
     25.5, 53.5, 24.8;
     31.1, 56.6, 30.0;
     30.4, 56.7, 28.3;
     18.7, 46.5, 23.0;
     19.7, 44.2, 28.6;
     14.6, 42.7, 21.3;
     29.5, 54.4, 30.1;
     27.7, 55.3, 25.7;
     30.2, 58.6, 24.6;
     22.7, 48.2, 27.1;
     25.2, 51.0, 27.5];

[n,m] = size(x);
isx   = ones(m,1,'int64');
ip    = int64(m);
y = [11.9; 22.8; 18.7; 20.1; 12.9; 21.7; 27.1; 25.4; 21.3; 19.3;
     25.4; 27.2; 11.7; 17.8; 12.8; 23.9; 22.6; 25.4; 14.8; 21.1];

% Parameters
h      = 0.5;
opt    = int64(1);
niter  = int64(25);
tol    = 0.0001;
orig   = int64(2);
optloo = int64(2);

% Fit ridge regression model
[h, niter, nep, b, vif, res, rss, df, perr, ifail] = ...
  g02ka( ...
         x, isx, ip, y, h, opt, niter, tol, orig, optloo);

% Display results
fprintf('Value of ridge parameter      : %10.4f\n\n', h);
fprintf('Sum of squares of residuals   : %14.4e\n', rss);
fprintf('Degrees of freedom            : %5d\n', df);
fprintf('Number of effective parameters: %10.4f\n', nep);
fprintf('\nParameter estimates\n');
ivar = double([1:ip+1]);
fprintf('%4d%11.4f\n',[ivar; b(ivar)']);
fprintf('\nNumber of iterations: %15d\n\n', niter);
if opt==1
  fprintf('Ridge parameter minimises GCV\n');
elseif opt==2
  fprintf('Ridge parameter minimises UEV\n');
elseif opt==3
  fprintf('Ridge parameter minimises FPE\n');
elseif opt==4
  fprintf('Ridge parameter minimises BIC\n');
end
fprintf('\nEstimated prediction errors:\n');
fprintf('GCV    = %10.4f\n', perr(1));
fprintf('UEV    = %10.4f\n', perr(2));
fprintf('FPE    = %10.4f\n', perr(3));
fprintf('BIC    = %10.4f\n', perr(4));
if optloo==2
  fprintf('LOO CV = %10.4f\n', perr(5));
end
fprintf('\nResiduals\n');
ivar = [1:n];
fprintf('%4d%11.4f\n',[ivar; res(ivar)']);
fprintf('\nVariance inflation factors\n');
ivar = double([1:ip]);
fprintf('%4d%11.4f\n',[ivar; vif(ivar)']);


g02ka example results

Value of ridge parameter      :     0.0712

Sum of squares of residuals   :     1.0917e+02
Degrees of freedom            :    16
Number of effective parameters:     2.9059

Parameter estimates
   1    20.1950
   2     9.7934
   3     9.9576
   4    -2.0125

Number of iterations:               6

Ridge parameter minimises GCV

Estimated prediction errors:
GCV    =     7.4718
UEV    =     6.3862
FPE    =     7.3141
BIC    =     8.2380
LOO CV =     7.5495

Residuals
   1    -1.9894
   2     3.5469
   3    -3.0392
   4    -3.0309
   5    -0.1899
   6    -0.3146
   7     0.9775
   8     4.0157
   9     2.5332
  10    -2.3560
  11     0.5446
  12     2.3989
  13    -4.0876
  14     3.2778
  15     0.2894
  16     0.7330
  17    -0.7116
  18    -0.6092
  19    -2.9995
  20     1.0110

Variance inflation factors
   1     0.2928
   2     0.4162
   3     0.8089

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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