NAG Library Routine Document
G02KBF
1 Purpose
G02KBF calculates a ridge regression, with ridge parameters supplied by you.
2 Specification
SUBROUTINE G02KBF ( |
N, M, X, LDX, ISX, IP, Y, LH, H, NEP, WANTB, B, LDB, WANTVF, VF, LDVF, LPEC, PEC, PE, LDPE, IFAIL) |
INTEGER |
N, M, LDX, ISX(M), IP, LH, WANTB, LDB, WANTVF, LDVF, LPEC, LDPE, IFAIL |
REAL (KIND=nag_wp) |
X(LDX,M), Y(N), H(LH), NEP(LH), B(LDB,*), VF(LDVF,*), PE(LDPE,*) |
CHARACTER(1) |
PEC(LPEC) |
|
3 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, G02KBF 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.
4 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
5 Parameters
- 1: N – INTEGERInput
On entry: , the number of observations.
Constraint:
.
- 2: M – INTEGERInput
On entry: the number of independent variables available in the data matrix .
Constraint:
.
- 3: X(LDX,M) – REAL (KIND=nag_wp) arrayInput
On entry: the values of independent variables in the data matrix .
- 4: LDX – INTEGERInput
On entry: the first dimension of the array
X as declared in the (sub)program from which G02KBF is called.
Constraint:
.
- 5: ISX(M) – INTEGER arrayInput
On entry: 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 .
- 6: IP – INTEGERInput
On entry: , the number of independent variables in the model.
Constraints:
- ;
- Exactly IP elements of ISX must be equal to .
- 7: Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the values of the dependent variable .
- 8: LH – INTEGERInput
On entry: the number of supplied ridge parameters.
Constraint:
.
- 9: H(LH) – REAL (KIND=nag_wp) arrayInput
On entry: is the value of the th ridge parameter .
Constraint:
, for .
- 10: NEP(LH) – REAL (KIND=nag_wp) arrayOutput
On exit: is the number of effective parameters, , in the th model, for .
- 11: WANTB – INTEGERInput
On entry: 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 .
- 12: B(LDB,) – REAL (KIND=nag_wp) arrayOutput
-
Note: the second dimension of the array
B
must be at least
if
, and at least
otherwise.
On exit: 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
.
- 13: LDB – INTEGERInput
On entry: the first dimension of the array
B as declared in the (sub)program from which G02KBF is called.
Constraints:
- if , ;
- otherwise .
- 14: WANTVF – INTEGERInput
On entry: 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 , .
- 15: VF(LDVF,) – REAL (KIND=nag_wp) arrayOutput
-
Note: the second dimension of the array
VF
must be at least
if
, and at least
otherwise.
On exit: if , the variance inflation factors. For the
th independent variable in a model fitted with ridge parameter , is the value of , for .
- 16: LDVF – INTEGERInput
On entry: the first dimension of the array
VF as declared in the (sub)program from which G02KBF is called.
Constraints:
- if , ;
- otherwise .
- 17: LPEC – INTEGERInput
On entry: the number of prediction error statistics to return; set for no prediction error estimates.
- 18: PEC(LPEC) – CHARACTER(1) arrayInput
On entry: 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 .
- 19: PE(LDPE,) – REAL (KIND=nag_wp) arrayOutput
-
Note: the second dimension of the array
PE
must be at least
if
, and at least
otherwise.
On exit: if
,
PE is not referenced; otherwise
contains the prediction error of criterion
for the model fitted with ridge parameter
, for
and
.
- 20: LDPE – INTEGERInput
On entry: the first dimension of the array
PE as declared in the (sub)program from which G02KBF is called.
Constraints:
- if , ;
- otherwise .
- 21: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
On entry, | , |
or | , |
or | , |
or | , or , |
or | and , |
or | or , |
or | an element of PEC is not defined. |
On entry, | , |
or | , |
or | or , |
or | an element of or , |
or | IP does not equal the sum of elements in ISX, |
or | and , |
or | . |
Both
WANTB and
WANTVF are zero.
Internal error. Check all array sizes and calls to G02KBF. Please contact
NAG.
-
Internal memory allocation failed.
7 Accuracy
The accuracy of G02KBF is closely related to that of the singular value decomposition.
G02KBF allocates internally elements of double precision storage.
9 Example
This example reads in data from an experiment to model body fat, and a selection of ridge regression models are calculated.
9.1 Program Text
Program Text (g02kbfe.f90)
9.2 Program Data
Program Data (g02kbfe.d)
9.3 Program Results
Program Results (g02kbfe.r)