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 (g02kb)

Purpose

nag_correg_ridge (g02kb) calculates a ridge regression, with ridge parameters supplied by you.

Syntax

[nep, b, vf, pe, ifail] = g02kb(x, isx, ip, y, h, wantb, wantvf, pec, 'n', n, 'm', m, 'lh', lh, 'lpec', lpec)
[nep, b, vf, pe, ifail] = nag_correg_ridge(x, isx, ip, y, h, wantb, wantvf, pec, 'n', n, 'm', m, 'lh', lh, 'lpec', lpec)

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 parameters 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 (g02kb) 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 DUT .
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 ,
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 ( DT D+hI )-1 DT D ( DT D+hI )-1 VT .
Given a value of hh, any or all of the following prediction criteria are available:
(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-γ ) ;
(e) Leave-one-out cross-validation (LOOCV),
where ss is the sum of squares of residuals.
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.

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 n1n1.
The nn values of the dependent variable yy.
5:     h(lh) – double array
lh, the dimension of the array, must satisfy the constraint lh > 0lh>0.
h(j)hj is the value of the jjth ridge parameter hh.
Constraint: h(j)0.0hj0.0, for j = 1,2,,lhj=1,2,,lh.
6:     wantb – int64int32nag_int scalar
Defines the options for parameter estimates.
wantb = 0wantb=0
Parameter estimates are not calculated and b is not referenced.
wantb = 1wantb=1
Parameter estimates bb are calculated for the original data.
wantb = 2wantb=2
Parameter estimates b~ are calculated for the standardized data.
Constraint: wantb = 0wantb=0, 11 or 22.
7:     wantvf – int64int32nag_int scalar
Defines the options for variance inflation factors.
wantvf = 0wantvf=0
Variance inflation factors are not calculated and the array vf is not referenced.
wantvf = 1wantvf=1
Variance inflation factors are calculated.
Constraints:
8:     pec(lpec) – cell array of strings
If lpec > 0lpec>0, pec(j)pecj defines the jjth prediction error, for j = 1,2,,lpecj=1,2,,lpec; otherwise pec is not referenced.
pec(j) = 'B'pecj='B'
Bayesian information criterion (BIC).
pec(j) = 'F'pecj='F'
Future prediction error (FPE).
pec(j) = 'G'pecj='G'
Generalized cross-validation (GCV).
pec(j) = 'L'pecj='L'
Leave-one-out cross-validation (LOOCV).
pec(j) = 'U'pecj='U'
Unbiased estimate of variance (UEV).
Constraint: if lpec > 0lpec>0, pec(j) = 'B'pecj='B', 'F''F', 'G''G', 'L''L' or 'U''U', for j = 1,2,,lpecj=1,2,,lpec.

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: n1n1.
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:     lh – int64int32nag_int scalar
Default: The dimension of the array h.
The number of supplied ridge parameters.
Constraint: lh > 0lh>0.
4:     lpec – int64int32nag_int scalar
Default: The dimension of the array pec.
The number of prediction error statistics to return; set lpec0lpec0 for no prediction error estimates.

Input Parameters Omitted from the MATLAB Interface

ldx ldb ldvf ldpe

Output Parameters

1:     nep(lh) – double array
nep(j)nepj is the number of effective parameters, γγ, in the jjth model, for j = 1,2,,lhj=1,2,,lh.
2:     b(ldb, : :) – double array
The first dimension, ldb, of the array b will be
  • if wantb0wantb0, ldbip + 1ldbip+1;
  • otherwise ldb1ldb1.
The second dimension of the array will be lhlh if wantb0wantb0, and at least 11 otherwise
If wantb0wantb0, b contains the intercept and parameter estimates for the fitted ridge regression model in the order indicated by isx. b(1,j)b1j, for j = 1,2,,lhj=1,2,,lh, contains the estimate for the intercept; b(i + 1,j)bi+1j contains the parameter estimate for the iith independent variable in the model fitted with ridge parameter h(j)hj, for i = 1,2,,ipi=1,2,,ip.
3:     vf(ldvf, : :) – double array
The first dimension, ldvf, of the array vf will be
  • if wantvf0wantvf0, ldvfipldvfip;
  • otherwise ldvf1ldvf1.
The second dimension of the array will be lhlh if wantvf0wantvf0, and at least 11 otherwise
If wantvf = 1wantvf=1, the variance inflation factors. For the iith independent variable in a model fitted with ridge parameter h(j)hj, vf(i,j)vfij is the value of vivi, for i = 1,2,,ipi=1,2,,ip.
4:     pe(ldpe, : :) – double array
The first dimension, ldpe, of the array pe will be
  • if lpec > 0lpec>0, ldpelpecldpelpec;
  • otherwise ldpe1ldpe1.
The second dimension of the array will be lhlh if lpec > 0lpec>0, and at least 11 otherwise
If lpec0lpec0, pe is not referenced; otherwise pe(i,j)peij contains the prediction error of criterion pec(i)peci for the model fitted with ridge parameter h(j)hj, for i = 1,2,,lpeci=1,2,,lpec and j = 1,2,,lhj=1,2,,lh.
5:     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
On entry,n < 1n<1,
orh(j) < 0.0hj<0.0,
orlh0lh0,
orwantb0wantb0, 11 or 22,
orwantb0wantb0 and ldb < ip + 1ldb<ip+1,
orwantvf0wantvf0 or 11,
oran element of pec is not defined.
  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,
orwantvf0wantvf0 and ldvf < ipldvf<ip,
orldpe < lpecldpe<lpec.
  ifail = 3ifail=3
Both wantb and wantvf are zero.
  ifail = 4ifail=4
Internal error. Check all array sizes and calls to nag_correg_ridge (g02kb). Please contact NAG.
  ifail = 999ifail=-999
Internal memory allocation failed.

Accuracy

The accuracy of nag_correg_ridge (g02kb) is closely related to that of the singular value decomposition.

Further Comments

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

Example

function nag_correg_ridge_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;
     0.002;
     0.004;
     0.006;
     0.008;
     0.01;
     0.012;
     0.014;
     0.016;
     0.018;
     0.02;
     0.022;
     0.024;
     0.026;
     0.028;
     0.03];
wantb = int64(1);
wantvf = int64(1);
pec = {'L'; 'G'; 'U'; 'F'; 'B'};
[nep, b, vf, pe, ifail] = nag_correg_ridge(x, isx, ip, y, h, wantb, wantvf, pec)
 

nep =

    4.0000
    3.2634
    3.1475
    3.0987
    3.0709
    3.0523
    3.0386
    3.0278
    3.0189
    3.0112
    3.0045
    2.9984
    2.9928
    2.9876
    2.9828
    2.9782


b =

  Columns 1 through 9

  117.0847   22.2748    7.7209    1.8363   -1.3396   -3.3219   -4.6734   -5.6511   -6.3891
    4.3341    1.4644    1.0229    0.8437    0.7465    0.6853    0.6432    0.6125    0.5890
   -2.8568   -0.4012   -0.0242    0.1282    0.2105    0.2618    0.2968    0.3222    0.3413
   -2.1861   -0.6738   -0.4408   -0.3460   -0.2944   -0.2619   -0.2393   -0.2228   -0.2100

  Columns 10 through 16

   -6.9642   -7.4236   -7.7978   -8.1075   -8.3673   -8.5874   -8.7758
    0.5704    0.5554    0.5429    0.5323    0.5233    0.5155    0.5086
    0.3562    0.3681    0.3779    0.3859    0.3926    0.3984    0.4033
   -0.1999   -0.1916   -0.1847   -0.1788   -0.1737   -0.1693   -0.1653


vf =

  Columns 1 through 9

  708.8429   50.5592   16.9816    8.5033    5.1472    3.4855    2.5434    1.9581    1.5698
  564.3434   40.4483   13.7247    6.9764    4.3046    2.9813    2.2306    1.7640    1.4541
  104.6060    8.2797    3.3628    2.1185    1.6238    1.3770    1.2356    1.1463    1.0859

  Columns 10 through 16

    1.2990    1.1026    0.9556    0.8427    0.7541    0.6832    0.6257
    1.2377    1.0805    0.9627    0.8721    0.8007    0.7435    0.6969
    1.0428    1.0105    0.9855    0.9655    0.9491    0.9353    0.9235


pe =

  Columns 1 through 9

    8.0368    7.5464    7.5575    7.5656    7.5701    7.5723    7.5732    7.5734    7.5731
    7.6879    7.4238    7.4520    7.4668    7.4749    7.4796    7.4823    7.4838    7.4845
    6.1503    6.2124    6.2793    6.3100    6.3272    6.3381    6.3455    6.3508    6.3548
    7.3804    7.2261    7.2675    7.2876    7.2987    7.3053    7.3095    7.3122    7.3140
    8.6052    8.2355    8.2515    8.2611    8.2661    8.2685    8.2695    8.2696    8.2691

  Columns 10 through 16

    7.5724    7.5715    7.5705    7.5694    7.5682    7.5669    7.5657
    7.4848    7.4847    7.4843    7.4838    7.4832    7.4825    7.4818
    6.3578    6.3603    6.3623    6.3639    6.3654    6.3666    6.3677
    7.3151    7.3158    7.3161    7.3162    7.3162    7.3161    7.3159
    8.2683    8.2671    8.2659    8.2645    8.2630    8.2615    8.2600


ifail =

                    0


function g02kb_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;
     0.002;
     0.004;
     0.006;
     0.008;
     0.01;
     0.012;
     0.014;
     0.016;
     0.018;
     0.02;
     0.022;
     0.024;
     0.026;
     0.028;
     0.03];
wantb = int64(1);
wantvf = int64(1);
pec = {'L'; 'G'; 'U'; 'F'; 'B'};
[nep, b, vf, pe, ifail] = g02kb(x, isx, ip, y, h, wantb, wantvf, pec)
 

nep =

    4.0000
    3.2634
    3.1475
    3.0987
    3.0709
    3.0523
    3.0386
    3.0278
    3.0189
    3.0112
    3.0045
    2.9984
    2.9928
    2.9876
    2.9828
    2.9782


b =

  Columns 1 through 9

  117.0847   22.2748    7.7209    1.8363   -1.3396   -3.3219   -4.6734   -5.6511   -6.3891
    4.3341    1.4644    1.0229    0.8437    0.7465    0.6853    0.6432    0.6125    0.5890
   -2.8568   -0.4012   -0.0242    0.1282    0.2105    0.2618    0.2968    0.3222    0.3413
   -2.1861   -0.6738   -0.4408   -0.3460   -0.2944   -0.2619   -0.2393   -0.2228   -0.2100

  Columns 10 through 16

   -6.9642   -7.4236   -7.7978   -8.1075   -8.3673   -8.5874   -8.7758
    0.5704    0.5554    0.5429    0.5323    0.5233    0.5155    0.5086
    0.3562    0.3681    0.3779    0.3859    0.3926    0.3984    0.4033
   -0.1999   -0.1916   -0.1847   -0.1788   -0.1737   -0.1693   -0.1653


vf =

  Columns 1 through 9

  708.8429   50.5592   16.9816    8.5033    5.1472    3.4855    2.5434    1.9581    1.5698
  564.3434   40.4483   13.7247    6.9764    4.3046    2.9813    2.2306    1.7640    1.4541
  104.6060    8.2797    3.3628    2.1185    1.6238    1.3770    1.2356    1.1463    1.0859

  Columns 10 through 16

    1.2990    1.1026    0.9556    0.8427    0.7541    0.6832    0.6257
    1.2377    1.0805    0.9627    0.8721    0.8007    0.7435    0.6969
    1.0428    1.0105    0.9855    0.9655    0.9491    0.9353    0.9235


pe =

  Columns 1 through 9

    8.0368    7.5464    7.5575    7.5656    7.5701    7.5723    7.5732    7.5734    7.5731
    7.6879    7.4238    7.4520    7.4668    7.4749    7.4796    7.4823    7.4838    7.4845
    6.1503    6.2124    6.2793    6.3100    6.3272    6.3381    6.3455    6.3508    6.3548
    7.3804    7.2261    7.2675    7.2876    7.2987    7.3053    7.3095    7.3122    7.3140
    8.6052    8.2355    8.2515    8.2611    8.2661    8.2685    8.2695    8.2696    8.2691

  Columns 10 through 16

    7.5724    7.5715    7.5705    7.5694    7.5682    7.5669    7.5657
    7.4848    7.4847    7.4843    7.4838    7.4832    7.4825    7.4818
    6.3578    6.3603    6.3623    6.3639    6.3654    6.3666    6.3677
    7.3151    7.3158    7.3161    7.3162    7.3162    7.3161    7.3159
    8.2683    8.2671    8.2659    8.2645    8.2630    8.2615    8.2600


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