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)

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:
Mark 24: tau optional
.

Description

A linear model has the form:
y = c + Xβ + ε ,
y = c+Xβ+ε ,
where
Let X~ be the mean-centred XX and y~ the mean-centred yy. Furthermore, X~ is scaled such that the diagonal elements of the cross product matrix TX~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
2 + h 2 , h > 0 ,
X~ b~ - y~ 2 + h b~ 2 , h>0 ,
where · · denotes the 22-norm and hh is a scalar regularization or ridge parameter. For a given value of hh, the parameter estimates b~ are found by evaluating
= (T + hI)1 T .
b~ = ( X~T X~+hI )-1 X~T y~ .
Note that if h = 0h=0 the ridge regression solution is equivalent to the ordinary least squares solution.
Rather than calculate the inverse of (T + hIX~TX~+hI) directly, nag_correg_ridge_opt (g02ka) uses the singular value decomposition (SVD) of X~. After decomposing X~ into UDVTUDVT where UU and VV are orthogonal matrices and DD is a diagonal matrix, the parameter estimates become
= V (DTD + hI)1 D UT .
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 (DTD + hI)1 ,
DT D ( DT D+hI)-1 ,
see Moody (1992) for details.
Any multi-collinearity in the design matrix XX may be highlighted by calculating the variance inflation factors for the fitted model. The jjth variance inflation factor, vjvj, is a scaled version of the multiple correlation coefficient between independent variable jj and the other independent variables, RjRj, and is given by
vj = 1/(1Rj) , j = 1,2,,m .
vj = 1 1-Rj , j=1,2,,m .
The mm variance inflation factors are calculated as the diagonal elements of the matrix:
(T + hI)1 T (T + hI)1 ,
( 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 .
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 bb associated with XX. These are calculated from b~, and the means and scalings of XX. Optionally, either b~ or bb may be calculated.
The method can adopt one of four criteria to minimize while calculating a suitable value for hh:
(a) Generalized cross-validation (GCV):
(ns)/((nγ)2) ;
ns (n-γ) 2 ;
(b) Unbiased estimate of variance (UEV):
s/(nγ) ;
s n-γ ;
(c) Future prediction error (FPE):
1/n (s + (2γs)/(nγ)) ;
1n ( s+ 2γs n-γ ) ;
(d) Bayesian information criterion (BIC):
1/n (s + (log(n)γs)/(nγ)) ;
1n ( s + log(n)γs n-γ ) ;
where ss 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, hh. 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:     x(ldx,m) – double array
ldx, the first dimension of the array, must satisfy the constraint ldxnldxn.
The values of independent variables in the data matrix XX.
2:     isx(m) – int64int32nag_int array
m, the dimension of the array, must satisfy the constraint mnmn.
Indicates which mm independent variables are included in the model.
isx(j) = 1isxj=1
The jjth variable in x will be included in the model.
isx(j) = 0isxj=0
Variable jj is excluded.
Constraint: isx(j) = 0 ​ or ​ 1isxj=0 ​ or ​ 1, for j = 1,2,,mj=1,2,,m.
3:     ip – int64int32nag_int scalar
mm, the number of independent variables in the model.
Constraints:
  • 1ipm1ipm;
  • Exactly ip elements of isx must be equal to 11.
4:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n > 1n>1.
The nn values of the dependent variable yy.
5:     h – double scalar
An initial value for the ridge regression parameter hh; used as a starting point for the optimization.
Constraint: h > 0.0h>0.0.
6:     opt – int64int32nag_int scalar
The measure of prediction error used to optimize the ridge regression parameter hh. The value of opt must be set equal to one of:
opt = 1opt=1
Generalized cross-validation (GCV);
opt = 2opt=2
Unbiased estimate of variance (UEV)
opt = 3opt=3
Future prediction error (FPE)
opt = 4opt=4
Bayesian information criteron (BIC).
Constraint: opt = 1opt=1, 22, 33 or 44.
7:     niter – int64int32nag_int scalar
The maximum number of iterations allowed to optimize the ridge regression parameter hh.
Constraint: niter1niter1.
8:     tol – double scalar
Iterations of the ridge regression parameter hh will halt when consecutive values of hh lie within tol.
Constraint: tol > 0.0tol>0.0.
9:     orig – int64int32nag_int scalar
If orig = 1orig=1, the parameter estimates bb are calculated for the original data; otherwise orig = 2orig=2 and the parameter estimates b~ are calculated for the standardized data.
Constraint: orig = 1orig=1 or 22.
10:   optloo – int64int32nag_int scalar
If optloo = 2optloo=2, the leave-one-out cross-validation estimate of prediction error is calculated; otherwise no such estimate is calculated and optloo = 1optloo=1.
Constraint: optloo = 1optloo=1 or 22.

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.)
nn, the number of observations.
Constraint: n > 1n>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 XX.
Constraint: mnmn.
3:     tau – double scalar
Singular values less than tau of the SVD of the data matrix XX will be set equal to zero.
Default: tau = 0.0tau=0.0
Constraint: tau0.0tau0.0.

Input Parameters Omitted from the MATLAB Interface

ldx

Output Parameters

1:     h – double scalar
h is the optimized value of the ridge regression parameter hh.
2:     niter – int64int32nag_int scalar
The number of iterations used to optimize the ridge regression parameter hh within tol.
3:     nep – double scalar
The number of effective parameters, γγ, in the model.
4:     b(ip + 1ip+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; b(j + 1)bj+1 contains the parameter estimate for the jjth independent variable in the model, for j = 1,2,,ipj=1,2,,ip.
5:     vif(ip) – double array
The variance inflation factors in the order indicated by isx. For the jjth independent variable in the model, vif(j)vifj is the value of vjvj, for j = 1,2,,ipj=1,2,,ip.
6:     res(n) – double array
res(i)resi is the value of the iith residual for the fitted ridge regression model, for i = 1,2,,ni=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:     perr(55) – double array
The first four elements contain, in this order, the measures of prediction error: GCV, UEV, FPE and BIC.
If optloo = 2optloo=2, perr(5)perr5 is the LOOCV estimate of prediction error; otherwise perr(5)perr5 is not referenced.
10:   ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=-1
Maximum number of iterations used.
  ifail = 1ifail=1
On entry,n1n1;
ortau < 0.0tau<0.0;
oropt1opt1, 22, 33 or 44;
orh0.0h0.0;
oroptloo1optloo1 or 22;
ortol0.0tol0.0;
orniter < 1niter<1;
ororig1orig1 or 22
  ifail = 2ifail=2
On entry,m > nm>n;
orldx < nldx<n;
orip < 1ip<1 or ip > mip>m;
orAn element of isx0isx0 or 11;
orip does not equal the sum of elements in isx.
  ifail = 3ifail=3
SVD failed to converge.
  ifail = 4ifail=4
Internal error. Check all array sizes and calls to nag_correg_ridge_opt (g02ka). Please contact NAG.

Accuracy

Not applicable.

Further Comments

nag_correg_ridge_opt (g02ka) allocates internally max (5 × (n1),2 × ip × ip) + (n + 3) × ip + n max( 5 × (n-1) , 2×ip×ip ) +(n+3) × ip+n  elements of double precision storage.

Example

function nag_correg_ridge_opt_example
x = [19.5, 43.1, 29.1;
     24.7, 49.8, 28.2;
     30.7, 51.9, 37;
     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;
     30.4, 56.7, 28.3;
     18.7, 46.5, 23;
     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, 27.5];
isx = [int64(1);1;1];
ip = int64(3);
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];
h = 0.5;
opt = int64(1);
niter = int64(25);
tol = 0.0001;
orig = int64(2);
optloo = int64(2);
[hOut, niterOut, nep, b, vif, res, rss, df, perr, ifail] = ...
    nag_correg_ridge_opt(x, isx, ip, y, h, opt, niter, tol, orig, optloo)
 

hOut =

    0.0712


niterOut =

                    6


nep =

    2.9059


b =

   20.1950
    9.7934
    9.9576
   -2.0125


vif =

    0.2928
    0.4162
    0.8089


res =

   -1.9894
    3.5469
   -3.0392
   -3.0309
   -0.1899
   -0.3146
    0.9775
    4.0157
    2.5332
   -2.3560
    0.5446
    2.3989
   -4.0876
    3.2778
    0.2894
    0.7330
   -0.7116
   -0.6092
   -2.9995
    1.0110


rss =

  109.1674


df =

                   16


perr =

    7.4718
    6.3862
    7.3141
    8.2380
    7.5495


ifail =

                    0


function g02ka_example
x = [19.5, 43.1, 29.1;
     24.7, 49.8, 28.2;
     30.7, 51.9, 37;
     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;
     30.4, 56.7, 28.3;
     18.7, 46.5, 23;
     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, 27.5];
isx = [int64(1);1;1];
ip = int64(3);
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];
h = 0.5;
opt = int64(1);
niter = int64(25);
tol = 0.0001;
orig = int64(2);
optloo = int64(2);
[hOut, niterOut, nep, b, vif, res, rss, df, perr, ifail] = ...
        g02ka(x, isx, ip, y, h, opt, niter, tol, orig, optloo)
 

hOut =

    0.0712


niterOut =

                    6


nep =

    2.9059


b =

   20.1950
    9.7934
    9.9576
   -2.0125


vif =

    0.2928
    0.4162
    0.8089


res =

   -1.9894
    3.5469
   -3.0392
   -3.0309
   -0.1899
   -0.3146
    0.9775
    4.0157
    2.5332
   -2.3560
    0.5446
    2.3989
   -4.0876
    3.2778
    0.2894
    0.7330
   -0.7116
   -0.6092
   -2.9995
    1.0110


rss =

  109.1674


df =

                   16


perr =

    7.4718
    6.3862
    7.3141
    8.2380
    7.5495


ifail =

                    0



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–2013