g02ka Method
関数リスト一覧   NagLibrary Namespaceへ  ライブラリイントロダクション  本ヘルプドキュメントのchm形式版

g02ka calculates a ridge regression, optimizing the ridge parameter according to one of four prediction error criteria.

Syntax

C#
public static void g02ka(
	int n,
	int m,
	double[,] x,
	int[] isx,
	int ip,
	double tau,
	double[] y,
	ref double h,
	int opt,
	ref int niter,
	double tol,
	out double nep,
	int orig,
	double[] b,
	double[] vif,
	double[] res,
	out double rss,
	out int df,
	int optloo,
	double[] perr,
	out int ifail
)
Visual Basic (Declaration)
Public Shared Sub g02ka ( _
	n As Integer, _
	m As Integer, _
	x As Double(,), _
	isx As Integer(), _
	ip As Integer, _
	tau As Double, _
	y As Double(), _
	ByRef h As Double, _
	opt As Integer, _
	ByRef niter As Integer, _
	tol As Double, _
	<OutAttribute> ByRef nep As Double, _
	orig As Integer, _
	b As Double(), _
	vif As Double(), _
	res As Double(), _
	<OutAttribute> ByRef rss As Double, _
	<OutAttribute> ByRef df As Integer, _
	optloo As Integer, _
	perr As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g02ka(
	int n, 
	int m, 
	array<double,2>^ x, 
	array<int>^ isx, 
	int ip, 
	double tau, 
	array<double>^ y, 
	double% h, 
	int opt, 
	int% niter, 
	double tol, 
	[OutAttribute] double% nep, 
	int orig, 
	array<double>^ b, 
	array<double>^ vif, 
	array<double>^ res, 
	[OutAttribute] double% rss, 
	[OutAttribute] int% df, 
	int optloo, 
	array<double>^ perr, 
	[OutAttribute] int% ifail
)
F#
static member g02ka : 
        n:int * 
        m:int * 
        x:float[,] * 
        isx:int[] * 
        ip:int * 
        tau:float * 
        y:float[] * 
        h:float byref * 
        opt:int * 
        niter:int byref * 
        tol:float * 
        nep:float byref * 
        orig:int * 
        b:float[] * 
        vif:float[] * 
        res:float[] * 
        rss:float byref * 
        df:int byref * 
        optloo:int * 
        perr:float[] * 
        ifail:int byref -> unit 

Parameters

n
Type: System..::.Int32
On entry: n, the number of observations.
Constraint: n>1.
m
Type: System..::.Int32
On entry: the number of independent variables available in the data matrix X.
Constraint: mn.
x
Type: array< System..::.Double ,2>[,](,)[,]
An array of size [ldx, m]
Note: ldx must satisfy the constraint: ldxn
On entry: the values of independent variables in the data matrix X.
isx
Type: array< System..::.Int32 >[]()[]
An array of size [m]
On entry: indicates which of m independent variables are included in the model. If isx[j-1] is 1, then the jth variable in x will be included in the model; otherwise variable j is excluded and isx[j-1] must be 0, for j=1,2,,m.
Constraint: isx[j-1]=0 or 1, for j=1,2,,m.
ip
Type: System..::.Int32
On entry: m, the number of independent variables in the model.
Constraints:
  • 1ipm;
  • Exactly ip elements of isx must be equal to 1.
tau
Type: System..::.Double
On entry: singular values less than tau of the SVD of the data matrix X will be set equal to zero.
Constraint: tau0.0.
Suggested value: tau=0.0 
y
Type: array< System..::.Double >[]()[]
An array of size [n]
On entry: the n values of the dependent variable y.
h
Type: System..::.Double %
On entry: an initial value for the ridge regression parameter h; used as a starting point for the optimization.
Constraint: h>0.0.
On exit: h is the optimized value of the ridge regression parameter h.
opt
Type: System..::.Int32
On entry: the measure of prediction error used to optimize the ridge regression parameter h. The value of opt must be set equal to one of:
opt=1
Generalised cross-validation (GCV);
opt=2
Unbiased estimate of variance (UEV)
opt=3
Future prediction error (FPE)
opt=4
Bayesian information criteron (BIC).
Constraint: opt=1, 2, 3 or 4.
niter
Type: System..::.Int32 %
On entry: the maximum number of iterations allowed to optimize the ridge regression parameter h.
Constraint: niter1.
On exit: the number of iterations used to optimize the ridge regression parameter h within tol.
tol
Type: System..::.Double
On entry: iterations of the ridge regression parameter h will halt when consecutive values of h lie within tol.
Constraint: tol>0.0.
nep
Type: System..::.Double %
On exit: the number of effective parameters, γ, in the model.
orig
Type: System..::.Int32
On entry: if orig=1, the parameter estimates b are calculated for the original data; otherwise orig=2 and the parameter estimates b~ are calculated for the standardized data.
Constraint: orig=1 or 2.
b
Type: array< System..::.Double >[]()[]
An array of size [ip+1]
On exit: 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; b[j] contains the parameter estimate for the jth independent variable in the model, for j=1,2,,ip.
vif
Type: array< System..::.Double >[]()[]
An array of size [ip]
On exit: the variance inflation factors in the order indicated by isx. For the jth independent variable in the model, vif[j-1] is the value of vj, for j=1,2,,ip.
res
Type: array< System..::.Double >[]()[]
An array of size [n]
On exit: res[i-1] is the value of the ith residual for the fitted ridge regression model, for i=1,2,,n.
rss
Type: System..::.Double %
On exit: the sum of squares of residual values.
df
Type: System..::.Int32 %
On exit: the degrees of freedom for the residual sum of squares rss.
optloo
Type: System..::.Int32
On entry: if optloo=2, the leave-one-out cross-validation estimate of prediction error is calculated; otherwise no such estimate is calculated and optloo=1.
Constraint: optloo=1 or 2.
perr
Type: array< System..::.Double >[]()[]
An array of size [5]
On exit: the first four elements contain, in this order, the measures of prediction error: GCV, UEV, FPE and BIC.
If optloo=2, perr[4] is the LOOCV estimate of prediction error; otherwise perr[4] is not referenced.
ifail
Type: System..::.Int32 %
On exit: ifail=0 unless the method detects an error (see [Error Indicators and Warnings]).

Description

A linear model has the form:
y = c+Xβ+ε ,
where
  • y is an n by 1 matrix of values of a dependent variable;
  • c is a scalar intercept term;
  • X is an n by m matrix of values of independent variables;
  • β is an m by 1 matrix of unknown values of parameters;
  • ε is an n by 1 matrix of unknown random errors such that variance of ε=σ2I.
Let X~ be the mean-centred X and y~ the mean-centred y. Furthermore, X~ is scaled such that the diagonal elements of the cross product matrix X~TX~ are one. The linear model now takes the form:
y~ = X~ β~ + ε .
Ridge regression estimates the parameters β~ in a penalised least squares sense by finding the b~ that minimizes
X~ b~ - y~ 2 + h b~ 2 , h>0 ,
where · denotes the 2-norm and h is a scalar regularisation or ridge parameter. For a given value of h, the parameter estimates b~ are found by evaluating
b~ = X~T X~+hI -1 X~T y~ .
Note that if h=0 the ridge regression solution is equivalent to the ordinary least squares solution.
Rather than calculate the inverse of (X~TX~+hI) directly, g02ka uses the singular value decomposition (SVD) of X~. After decomposing X~ into UDVT where U and V are orthogonal matrices and D is a diagonal matrix, the parameter estimates become
b~ = V DTD+hI -1 D UT y~ .
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
DT D DT D+hI-1 ,
see Moody (1992) for details.
Any multi-collinearity in the design matrix X may be highlighted by calculating the variance inflation factors for the fitted model. The jth variance inflation factor, vj, is a scaled version of the multiple correlation coefficient between independent variable j and the other independent variables, Rj, and is given by
vj = 1 1-Rj , j=1,2,,m .
The m variance inflation factors are calculated as the diagonal elements of the matrix:
X~T X~+hI -1 X~T X~ X~T X~+hI -1 ,
which, using the SVD of X~, is equivalent to the diagonal elements of the matrix:
V DTD+hI -1 DT D DTD+hI -1 VT .
Although parameter estimates b~ are calculated by using X~, it is usual to report the parameter estimates b associated with X. These are calculated from b~, and the means and scalings of X. Optionally, either b~ or b may be calculated.
The method can adopt one of four criteria to minimize while calculating a suitable value for h:
(a) Generalised cross-validation (GCV):
ns n-γ 2 ;
(b) Unbiased estimate of variance (UEV):
s n-γ ;
(c) Future prediction error (FPE):
1n s+ 2γs n-γ ;
(d) Bayesian information criterion (BIC):
1n s + lognγs n-γ ;
where s 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, h. Furthermore, the function will optionally return the leave-one-out cross-validation (LOOCV) prediction error.

References

Error Indicators and Warnings

Accuracy

Further Comments

g02ka allocates internally max 5 × n-1 , 2×ip×ip +n+3 × ip+n  elements of double precision storage.

Example

See Also