PDF version (NAG web site
, 64-bit version, 64-bit version)
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:
where
- is an by matrix of values of a dependent variable;
- is a scalar intercept term;
- is an by matrix of values of independent variables;
- is a by matrix of unknown values of parameters;
- is an by matrix of unknown random errors such that variance of .
Let
be the mean-centred
and
the mean-centred
. Furthermore,
is scaled such that the diagonal elements of the cross product matrix
are one. The linear model now takes the form:
Ridge regression estimates the parameters
in a penalised least squares sense by finding the
that minimizes
where
denotes the
-norm and
is a scalar regularization or ridge parameter. For a given value of
, the parameters estimates
are found by evaluating
Note that if the ridge regression solution is equivalent to the ordinary least squares solution.
Rather than calculate the inverse of (
) directly,
nag_correg_ridge (g02kb) uses the singular value decomposition (SVD) of
. After decomposing
into
where
and
are orthogonal matrices and
is a diagonal matrix, the parameter estimates become
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
see
Moody (1992) for details.
Any multi-collinearity in the design matrix
may be highlighted by calculating the variance inflation factors for the fitted model. The
th variance inflation factor,
, is a scaled version of the multiple correlation coefficient between independent variable
and the other independent variables,
, and is given by
The
variance inflation factors are calculated as the diagonal elements of the matrix:
which, using the SVD of
, is equivalent to the diagonal elements of the matrix:
Given a value of
, any or all of the following prediction criteria are available:
(a) |
Generalized cross-validation (GCV):
|
(b) |
Unbiased estimate of variance (UEV):
|
(c) |
Future prediction error (FPE):
|
(d) |
Bayesian information criterion (BIC):
|
(e) |
Leave-one-out cross-validation (LOOCV), |
where is the sum of squares of residuals.
Although parameter estimates are calculated by using , it is usual to report the parameter estimates associated with . These are calculated from , and the means and scalings of . Optionally, either or 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:
– double array
-
ldx, the first dimension of the array, must satisfy the constraint
.
The values of independent variables in the data matrix .
- 2:
– int64int32nag_int array
-
Indicates which
independent variables are included in the model.
- The th variable in x will be included in the model.
- Variable is excluded.
Constraint:
, for .
- 3:
– int64int32nag_int scalar
-
, the number of independent variables in the model.
Constraints:
- ;
- Exactly ip elements of isx must be equal to .
- 4:
– double array
-
The values of the dependent variable .
- 5:
– double array
-
is the value of the th ridge parameter .
Constraint:
, for .
- 6:
– int64int32nag_int scalar
-
Defines the options for parameter estimates.
- Parameter estimates are not calculated and b is not referenced.
- Parameter estimates are calculated for the original data.
- Parameter estimates are calculated for the standardized data.
Constraint:
, or .
- 7:
– int64int32nag_int scalar
-
Defines the options for variance inflation factors.
- Variance inflation factors are not calculated and the array vf is not referenced.
- Variance inflation factors are calculated.
Constraints:
- or ;
- if , .
- 8:
– cell array of strings
-
If
,
defines the
th prediction error, for
; otherwise
pec is not referenced.
- Bayesian information criterion (BIC).
- Future prediction error (FPE).
- Generalized cross-validation (GCV).
- Leave-one-out cross-validation (LOOCV).
- Unbiased estimate of variance (UEV).
Constraint:
if , , , , or , for .
Optional Input Parameters
- 1:
– 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.)
, the number of observations.
Constraint:
.
- 2:
– 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 .
Constraint:
.
- 3:
– int64int32nag_int scalar
-
Default:
the dimension of the array
h.
The number of supplied ridge parameters.
Constraint:
.
- 4:
– int64int32nag_int scalar
-
Default:
the dimension of the array
pec.
The number of prediction error statistics to return; set for no prediction error estimates.
Output Parameters
- 1:
– double array
-
is the number of effective parameters, , in the th model, for .
- 2:
– double array
-
The first dimension,
, of the array
b will be
- if , ;
- otherwise .
The second dimension of the array
b will be
if
and
otherwise.
If
,
b contains the intercept and parameter estimates for the fitted ridge regression model in the order indicated by
isx.
, for
, contains the estimate for the intercept;
contains the parameter estimate for the
th independent variable in the model fitted with ridge parameter
, for
.
- 3:
– double array
-
The first dimension,
, of the array
vf will be
- if , ;
- otherwise .
The second dimension of the array
vf will be
if
and
otherwise.
If , the variance inflation factors. For the
th independent variable in a model fitted with ridge parameter , is the value of , for .
- 4:
– double array
-
The first dimension,
, of the array
pe will be
- if , ;
- otherwise .
The second dimension of the array
pe will be
if
and
otherwise.
If
,
pe is not referenced; otherwise
contains the prediction error of criterion
for the model fitted with ridge parameter
, for
and
.
- 5:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: .
Constraint: .
Constraint: .
Constraint: , or .
Constraint: or .
On entry, for at least one .
On entry, is invalid for at least one .
-
-
Constraint: if , .
Constraint: if , .
Constraint: .
Constraint: .
ip does not equal the sum of elements in
isx.
On entry, or for at least one .
-
-
On entry, and .
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic 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 elements of double precision storage.
Example
This example reads in data from an experiment to model body fat, and a selection of ridge regression models are calculated.
Open in the MATLAB editor:
g02kb_example
function g02kb_example
fprintf('g02kb example results\n\n');
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];
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.030];
lh = numel(h);
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);
fprintf('Number of parameters used : %5d\n', ip+1);
fprintf('Number of effective parameters (nep): \n');
fprintf(' Ridge coeff nep\n');
ivar = double([1:lh]);
fprintf(' %4d %10.4f\n',[ivar; nep(ivar)']);
fprintf('\nParameter estimates (original scalings)\n');
fprintf(' Ridge coef Intercept');
fprintf('%9d ',[1:ip]);
fprintf('\n');
for j = 1:lh
fprintf('%10.4f',h(j),b(1:ip+1,j));
fprintf('\n');
end
fprintf('\nVariance Inflation Factors\n');
fprintf(' Ridge coef');
fprintf('%9d ',[1:ip]);
fprintf('\n');
for j = 1:lh
fprintf('%10.4f',h(j),vf(1:ip,j));
fprintf('\n');
end
fprintf('\nPrediction error criterion\n');
pl = numel(pec);
fprintf(' Ridge coef');
fprintf('%9d ',[1:pl]);
fprintf('\n');
for j = 1:lh
fprintf('%10.4f',h(j),pe(1:pl,j));
fprintf('\n');
if pl<ip
fprintf('%10s',' ');
fprintf('%10.4f',pe(pl+1:ip,j));
fprintf('\n');
end
end
fprintf('\nKey:\n');
for i = 1:pl
switch pec{i}
case {'L'}
fprintf(' %5d %s\n', i, 'Leave one out cross-validation');
case {'G'}
fprintf(' %5d %s\n', i, 'Generalised cross-validation');
case {'U'}
fprintf(' %5d %s\n', i, 'Unbiased estimate of variance');
case {'F'}
fprintf(' %5d %s\n', i, 'Final prediction error');
case {'B'}
fprintf(' %5d %s\n', i, 'Bayesian information criterion');
end
end
g02kb example results
Number of parameters used : 4
Number of effective parameters (nep):
Ridge coeff nep
1 4.0000
2 3.2634
3 3.1475
4 3.0987
5 3.0709
6 3.0523
7 3.0386
8 3.0278
9 3.0189
10 3.0112
11 3.0045
12 2.9984
13 2.9928
14 2.9876
15 2.9828
16 2.9782
Parameter estimates (original scalings)
Ridge coef Intercept 1 2 3
0.0000 117.0847 4.3341 -2.8568 -2.1861
0.0020 22.2748 1.4644 -0.4012 -0.6738
0.0040 7.7209 1.0229 -0.0242 -0.4408
0.0060 1.8363 0.8437 0.1282 -0.3460
0.0080 -1.3396 0.7465 0.2105 -0.2944
0.0100 -3.3219 0.6853 0.2618 -0.2619
0.0120 -4.6734 0.6432 0.2968 -0.2393
0.0140 -5.6511 0.6125 0.3222 -0.2228
0.0160 -6.3891 0.5890 0.3413 -0.2100
0.0180 -6.9642 0.5704 0.3562 -0.1999
0.0200 -7.4236 0.5554 0.3681 -0.1916
0.0220 -7.7978 0.5429 0.3779 -0.1847
0.0240 -8.1075 0.5323 0.3859 -0.1788
0.0260 -8.3673 0.5233 0.3926 -0.1737
0.0280 -8.5874 0.5155 0.3984 -0.1693
0.0300 -8.7758 0.5086 0.4033 -0.1653
Variance Inflation Factors
Ridge coef 1 2 3
0.0000 708.8429 564.3434 104.6060
0.0020 50.5592 40.4483 8.2797
0.0040 16.9816 13.7247 3.3628
0.0060 8.5033 6.9764 2.1185
0.0080 5.1472 4.3046 1.6238
0.0100 3.4855 2.9813 1.3770
0.0120 2.5434 2.2306 1.2356
0.0140 1.9581 1.7640 1.1463
0.0160 1.5698 1.4541 1.0859
0.0180 1.2990 1.2377 1.0428
0.0200 1.1026 1.0805 1.0105
0.0220 0.9556 0.9627 0.9855
0.0240 0.8427 0.8721 0.9655
0.0260 0.7541 0.8007 0.9491
0.0280 0.6832 0.7435 0.9353
0.0300 0.6257 0.6969 0.9235
Prediction error criterion
Ridge coef 1 2 3 4 5
0.0000 8.0368 7.6879 6.1503 7.3804 8.6052
0.0020 7.5464 7.4238 6.2124 7.2261 8.2355
0.0040 7.5575 7.4520 6.2793 7.2675 8.2515
0.0060 7.5656 7.4668 6.3100 7.2876 8.2611
0.0080 7.5701 7.4749 6.3272 7.2987 8.2661
0.0100 7.5723 7.4796 6.3381 7.3053 8.2685
0.0120 7.5732 7.4823 6.3455 7.3095 8.2695
0.0140 7.5734 7.4838 6.3508 7.3122 8.2696
0.0160 7.5731 7.4845 6.3548 7.3140 8.2691
0.0180 7.5724 7.4848 6.3578 7.3151 8.2683
0.0200 7.5715 7.4847 6.3603 7.3158 8.2671
0.0220 7.5705 7.4843 6.3623 7.3161 8.2659
0.0240 7.5694 7.4838 6.3639 7.3162 8.2645
0.0260 7.5682 7.4832 6.3654 7.3162 8.2630
0.0280 7.5669 7.4825 6.3666 7.3161 8.2615
0.0300 7.5657 7.4818 6.3677 7.3159 8.2600
Key:
1 Leave one out cross-validation
2 Generalised cross-validation
3 Unbiased estimate of variance
4 Final prediction error
5 Bayesian information criterion
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015