NAG FL Interface
g02kbf (ridge)
1
Purpose
g02kbf calculates a ridge regression, with ridge parameters supplied by you.
2
Specification
Fortran Interface
Subroutine g02kbf ( |
n, m, x, ldx, isx, ip, y, lh, h, nep, wantb, b, ldb, wantvf, vf, ldvf, lpec, pec, pe, ldpe, ifail) |
Integer, Intent (In) |
:: |
n, m, ldx, isx(m), ip, lh, wantb, ldb, wantvf, ldvf, lpec, ldpe |
Integer, Intent (Inout) |
:: |
ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
x(ldx,m), y(n), h(lh) |
Real (Kind=nag_wp), Intent (Inout) |
:: |
b(ldb,*), vf(ldvf,*), pe(ldpe,*) |
Real (Kind=nag_wp), Intent (Out) |
:: |
nep(lh) |
Character (1), Intent (In) |
:: |
pec(lpec) |
|
C Header Interface
#include <nag.h>
void |
g02kbf_ (const Integer *n, const Integer *m, const double x[], const Integer *ldx, const Integer isx[], const Integer *ip, const double y[], const Integer *lh, const double h[], double nep[], const Integer *wantb, double b[], const Integer *ldb, const Integer *wantvf, double vf[], const Integer *ldvf, const Integer *lpec, const char pec[], double pe[], const Integer *ldpe, Integer *ifail, const Charlen length_pec) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
g02kbf_ (const Integer &n, const Integer &m, const double x[], const Integer &ldx, const Integer isx[], const Integer &ip, const double y[], const Integer &lh, const double h[], double nep[], const Integer &wantb, double b[], const Integer &ldb, const Integer &wantvf, double vf[], const Integer &ldvf, const Integer &lpec, const char pec[], double pe[], const Integer &ldpe, Integer &ifail, const Charlen length_pec) |
}
|
The routine may be called by the names g02kbf or nagf_correg_ridge.
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 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 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
Arguments
-
1:
– Integer
Input
-
On entry: , the number of observations.
Constraint:
.
-
2:
– Integer
Input
-
On entry: the number of independent variables available in the data matrix .
Constraint:
.
-
3:
– Real (Kind=nag_wp) array
Input
-
On entry: the values of independent variables in the data matrix .
-
4:
– Integer
Input
-
On entry: the first dimension of the array
x as declared in the (sub)program from which
g02kbf is called.
Constraint:
.
-
5:
– Integer array
Input
-
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:
or , for .
-
6:
– Integer
Input
-
On entry: , the number of independent variables in the model.
Constraints:
- ;
- Exactly ip elements of isx must be equal to .
-
7:
– Real (Kind=nag_wp) array
Input
-
On entry: the values of the dependent variable .
-
8:
– Integer
Input
-
On entry: the number of supplied ridge parameters.
Constraint:
.
-
9:
– Real (Kind=nag_wp) array
Input
-
On entry: is the value of the th ridge parameter .
Constraint:
, for .
-
10:
– Real (Kind=nag_wp) array
Output
-
On exit: is the number of effective parameters, , in the th model, for .
-
11:
– Integer
Input
-
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:
– Real (Kind=nag_wp) array
Output
Note: the second dimension of the array
b
must be at least
if
.
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:
– Integer
Input
-
On entry: the first dimension of the array
b as declared in the (sub)program from which
g02kbf is called.
Constraints:
- if , ;
- otherwise .
-
14:
– Integer
Input
-
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:
– Real (Kind=nag_wp) array
Output
Note: the second dimension of the array
vf
must be at least
if
.
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:
– Integer
Input
-
On entry: the first dimension of the array
vf as declared in the (sub)program from which
g02kbf is called.
Constraints:
- if , ;
- otherwise .
-
17:
– Integer
Input
-
On entry: the number of prediction error statistics to return; set for no prediction error estimates.
-
18:
– Character(1) array
Input
-
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:
– Real (Kind=nag_wp) array
Output
Note: the second dimension of the array
pe
must be at least
if
.
On exit: if
,
pe is not referenced; otherwise
contains the prediction error of criterion
for the model fitted with ridge parameter
, for
and
.
-
20:
– Integer
Input
-
On entry: the first dimension of the array
pe as declared in the (sub)program from which
g02kbf is called.
Constraints:
- if , ;
- otherwise .
-
21:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or 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, for at least one .
Constraint: , for all .
On entry, .
Constraint: .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, is invalid for at least one .
Constraint: if , , , , or , for all .
On entry, .
Constraint: , or .
On entry, .
Constraint: or .
-
On entry,
ip is not equal to the sum of elements in
isx.
Constraint: exactly
ip elements of
isx must be equal to
.
On entry, or for at least one .
Constraint: or , for all .
On entry, and .
Constraint: if , .
On entry, and .
Constraint: .
On entry, and .
Constraint: if , .
On entry, and .
Constraint: .
-
On entry, and .
Constraint: , .
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
The accuracy of g02kbf is closely related to that of the singular value decomposition.
8
Parallelism and Performance
g02kbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g02kbf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
g02kbf allocates internally elements of double precision storage.
10
Example
This example reads in data from an experiment to model body fat, and a selection of ridge regression models are calculated.
10.1
Program Text
10.2
Program Data
10.3
Program Results