PDF version (NAG web site
, 64-bit version, 64-bit version)
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:
At Mark 24: |
tau was made optional |
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 an 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 parameter 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_opt (g02ka) 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:
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.
The method can adopt one of four criteria to minimize while calculating a suitable value for
:
(a) |
Generalized cross-validation (GCV):
|
(b) |
Unbiased estimate of variance (UEV):
|
(c) |
Future prediction error (FPE):
|
(d) |
Bayesian information criterion (BIC):
|
where
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,
. 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:
– 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 scalar
-
An initial value for the ridge regression parameter ; used as a starting point for the optimization.
Constraint:
.
- 6:
– int64int32nag_int scalar
-
The measure of prediction error used to optimize the ridge regression parameter
. The value of
opt must be set equal to one of:
- Generalized cross-validation (GCV);
- Unbiased estimate of variance (UEV)
- Future prediction error (FPE)
- Bayesian information criteron (BIC).
Constraint:
, , or .
- 7:
– int64int32nag_int scalar
-
The maximum number of iterations allowed to optimize the ridge regression parameter .
Constraint:
.
- 8:
– double scalar
-
Iterations of the ridge regression parameter
will halt when consecutive values of
lie within
tol.
Constraint:
.
- 9:
– int64int32nag_int scalar
-
If , the parameter estimates are calculated for the original data; otherwise and the parameter estimates are calculated for the standardized data.
Constraint:
or .
- 10:
– int64int32nag_int scalar
-
If , the leave-one-out cross-validation estimate of prediction error is calculated; otherwise no such estimate is calculated and .
Constraint:
or .
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:
– double scalar
Default:
Singular values less than
tau of the SVD of the data matrix
will be set equal to zero.
Constraint:
.
Output Parameters
- 1:
– double scalar
-
h is the optimized value of the ridge regression parameter
.
- 2:
– int64int32nag_int scalar
-
The number of iterations used to optimize the ridge regression parameter
within
tol.
- 3:
– double scalar
-
The number of effective parameters, , in the model.
- 4:
– 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;
contains the parameter estimate for the
th independent variable in the model, for
.
- 5:
– double array
-
The variance inflation factors in the order indicated by
isx. For the
th independent variable in the model,
is the value of
, for
.
- 6:
– double array
-
is the value of the th residual for the fitted ridge regression model, for .
-
The sum of squares of residual values.
- 8:
– int64int32nag_int scalar
-
The degrees of freedom for the residual sum of squares
rss.
- 9:
– double array
-
The first four elements contain, in this order, the measures of prediction error: GCV, UEV, FPE and BIC.
If , is the LOOCV estimate of prediction error; otherwise is not referenced.
- 10:
– 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 .
Constraint: or .
Constraint: .
Constraint: .
-
-
Constraint: .
Constraint: or .
Constraint: .
Constraint: .
Constraint: .
-
-
SVD failed to converge.
-
-
Maximum number of iterations used.
-
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
Not applicable.
Further Comments
nag_correg_ridge_opt (g02ka) allocates internally 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.
Open in the MATLAB editor:
g02ka_example
function g02ka_example
fprintf('g02ka 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.5;
opt = int64(1);
niter = int64(25);
tol = 0.0001;
orig = int64(2);
optloo = int64(2);
[h, niter, nep, b, vif, res, rss, df, perr, ifail] = ...
g02ka( ...
x, isx, ip, y, h, opt, niter, tol, orig, optloo);
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)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015