naginterfaces.library.correg.ridge

naginterfaces.library.correg.ridge(x, isx, y, h, wantb, wantvf, pec=None)[source]

ridge calculates a ridge regression, with ridge parameters supplied by you.

For full information please refer to the NAG Library document for g02kb

https://www.nag.com/numeric/nl/nagdoc_27.1/flhtml/g02/g02kbf.html

Parameters
xfloat, array-like, shape

The values of independent variables in the data matrix .

isxint, array-like, shape

Indicates which independent variables are included in the model.

The th variable in will be included in the model.

Variable is excluded.

yfloat, array-like, shape

The values of the dependent variable .

hfloat, array-like, shape

is the value of the th ridge parameter .

wantbint

Defines the options for parameter estimates.

Parameter estimates are not calculated and is not referenced.

Parameter estimates are calculated for the original data.

Parameter estimates are calculated for the standardized data.

wantvfint

Defines the options for variance inflation factors.

Variance inflation factors are not calculated and the array is not referenced.

Variance inflation factors are calculated.

pecNone or str, length 1, array-like, shape , optional

If is not None, defines the th prediction error, for ; otherwise 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).

Returns
nepfloat, ndarray, shape

is the number of effective parameters, , in the th model, for .

bfloat, ndarray, shape

If , contains the intercept and parameter estimates for the fitted ridge regression model in the order indicated by . , for , contains the estimate for the intercept; contains the parameter estimate for the th independent variable in the model fitted with ridge parameter , for .

vffloat, ndarray, shape

If , the variance inflation factors. For the th independent variable in a model fitted with ridge parameter , is the value of , for .

peNone or float, ndarray, shape

If is None on entry, is None; otherwise contains the prediction error of criterion for the model fitted with ridge parameter , for , for .

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, for at least one .

Constraint: , for all .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: , or .

(errno )

On entry, .

Constraint: or .

(errno )

On entry, is invalid for at least one .

Constraint: if is not None, , , , or , for all .

(errno )

On entry, or for at least one .

Constraint: or , for all .

(errno )

On entry, is not equal to the sum of elements in .

Constraint: exactly elements of must be equal to .

(errno )

On entry, and .

Constraint: if , .

(errno )

On entry, and .

Constraint: if , .

(errno )

On entry, and .

Constraint: , .

Notes

A linear model has the form:

where

is an matrix of values of a dependent variable;

is a scalar intercept term;

is an matrix of values of independent variables;

is an matrix of unknown values of parameters;

is an 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, ridge 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:

  1. Generalized cross-validation (GCV):

  2. Unbiased estimate of variance (UEV):

  3. Future prediction error (FPE):

  4. Bayesian information criterion (BIC):

  5. 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