NAG Library Routine Document
G02MBF
1 Purpose
G02MBF performs Least Angle Regression (LARS), forward stagewise linear regression or Least Absolute Shrinkage and Selection Operator (LASSO) using cross-product matrices.
2 Specification
SUBROUTINE G02MBF ( |
MTYPE, PRED, INTCPT, N, M, DTD, LDDTD, ISX, LISX, DTY, YTY, MNSTEP, IP, NSTEP, B, LDB, FITSUM, ROPT, LROPT, IFAIL) |
INTEGER |
MTYPE, PRED, INTCPT, N, M, LDDTD, ISX(LISX), LISX, MNSTEP, IP, NSTEP, LDB, LROPT, IFAIL |
REAL (KIND=nag_wp) |
DTD(LDDTD,*), DTY(M), YTY, B(LDB,*), FITSUM(6,MNSTEP+1), ROPT(LROPT) |
|
3 Description
G02MBF implements the LARS algorithm of
Efron et al. (2004) as well as the modifications needed to perform forward stagewise linear regression and fit LASSO and positive LASSO models.
Given a vector of
observed values,
and an
design matrix
, where the
th column of
, denoted
, is a vector of length
representing the
th independent variable
, standardized such that
, and
and a set of model parameters
to be estimated from the observed values, the LARS algorithm can be summarised as:
1. |
Set and all coefficients to zero, that is . |
2. |
Find the variable most correlated with , say . Add to the ‘most correlated’ set . If go to 8. |
3. |
Take the largest possible step in the direction of (i.e., increase the magnitude of ) until some other variable, say , has the same correlation with the current residual, . |
4. |
Increment and add to . |
5. |
If go to 8. |
6. |
Proceed in the ‘least angle direction’, that is, the direction which is equiangular between all variables in , altering the magnitude of the parameter estimates of those variables in , until the th variable, , has the same correlation with the current residual. |
7. |
Go to 4. |
8. |
Let . |
As well as being a model selection process in its own right, with a small number of modifications the LARS algorithm can be used to fit the LASSO model of
Tibshirani (1996), a positive LASSO model, where the independent variables enter the model in their defined direction, forward stagewise linear regression (
Hastie et al. (2001)) and forward selection (
Weisberg (1985)). Details of the required modifications in each of these cases are given in
Efron et al. (2004).
The LASSO model of
Tibshirani (1996) is given by
for all values of
, where
. The positive LASSO model is the same as the standard LASSO model, given above, with the added constraint that
Unlike the standard LARS algorithm, when fitting either of the LASSO models, variables can be dropped as well as added to the set . Therefore the total number of steps is no longer bounded by .
Forward stagewise linear regression is an iterative procedure of the form:
1. |
Initialize and the vector of residuals . |
2. |
For each calculate . The value is therefore proportional to the correlation between the th independent variable and the vector of previous residual values, . |
3. |
Calculate , the value of with the largest absolute value of . |
4. |
If then go to 7. |
5. |
Update the residual values, with
where is a small constant and when and otherwise. |
6. |
Increment and go to 2. |
7. |
Set . |
If the largest possible step were to be taken, that is
then forward stagewise linear regression reverts to the standard forward selection method as implemented in
G02EEF.
The LARS procedure results in
models, one for each step of the fitting process. In order to aid in choosing which is the most suitable
Efron et al. (2004) introduced a
-type statistic given by
where
is the approximate degrees of freedom for the
th step and
One way of choosing a model is therefore to take the one with the smallest value of .
4 References
Efron B, Hastie T, Johnstone I and Tibshirani R (2004) Least Angle Regression The Annals of Statistics (Volume 32) 2 407–499
Hastie T, Tibshirani R and Friedman J (2001) The Elements of Statistical Learning: Data Mining, Inference and Prediction Springer (New York)
Tibshirani R (1996) Regression Shrinkage and Selection via the Lasso Journal of the Royal Statistics Society, Series B (Methodological) (Volume 58) 1 267–288
Weisberg S (1985) Applied Linear Regression Wiley
5 Parameters
- 1: – INTEGERInput
-
On entry: indicates the type of model to fit.
- LARS is performed.
- Forward linear stagewise regression is performed.
- LASSO model is fit.
- A positive LASSO model is fit.
Constraint:
, , or .
- 2: – INTEGERInput
-
On entry: indicates the type of preprocessing to perform on the cross-products involving the independent variables, i.e., those supplied in
DTD and
DTY.
- No preprocessing is performed.
- Each independent variable is normalized, with the th variable scaled by . The scaling factor used by variable is returned in .
Constraint:
or .
- 3: – INTEGERInput
-
On entry: indicates the type of data preprocessing that was perform on the dependent variable,
, prior to calling this routine.
- No preprocessing was performed.
- The dependent variable, , was mean centered.
Constraint:
or .
- 4: – INTEGERInput
-
On entry: , the number of observations.
Constraint:
.
- 5: – INTEGERInput
-
On entry: , the total number of independent variables.
Constraint:
.
- 6: – REAL (KIND=nag_wp) arrayInput
-
Note: the second dimension of the array
DTD
must be at least
if
, and at least
otherwise.
On entry:
, the cross-product matrix, which along with
ISX, defines the design matrix cross-product
.
If
,
must contain the cross-product of the
th and
th variable, for
and
. That is the cross-product stacked by columns as returned by
G02BUF, for example.
Otherwise
must contain the cross-product of the th and th variable, for and . It should be noted that, even though is symmetric, the full matrix must be supplied.
The matrix specified in
DTD must be a valid cross-products matrix.
- 7: – INTEGERInput
-
On entry: the first dimension of the array
DTD as declared in the (sub)program from which G02MBF is called.
Constraint:
.
- 8: – INTEGER arrayInput
-
On entry: indicates which independent variables from
DTD will be included in the design matrix,
.
If
, all variables are included in the design matrix and
ISX is not referenced.
If
,, for
when
must be set as follows:
- To indicate that the th variable, as supplied in DTD, is included in the design matrix;
- To indicate that the th variable, as supplied in DTD, is not included in the design matrix;
and
.
Constraint:
if , or and at least one value of , for .
- 9: – INTEGERInput
-
On entry: length of the
ISX array.
Constraint:
or .
- 10: – REAL (KIND=nag_wp) arrayInput
-
On entry: , the cross-product between the dependent variable, , and the independent variables .
- 11: – REAL (KIND=nag_wp)Input
-
On entry: , the sums of squares of the dependent variable.
Constraint:
.
- 12: – INTEGERInput
-
On entry: the maximum number of steps to carry out in the model fitting process.
If , i.e., a LARS is being performed, the maximum number of steps the algorithm will take is if , otherwise .
If , i.e., a forward linear stagewise regression is being performed, the maximum number of steps the algorithm will take is likely to be several orders of magnitude more and is no longer bound by or .
If or , i.e., a LASSO or positive LASSO model is being fit, the maximum number of steps the algorithm will take lies somewhere between that of the LARS and forward linear stagewise regression, again it is no longer bound by or .
Constraint:
.
- 13: – INTEGEROutput
-
On exit:
, number of parameter estimates.
If
,
, i.e., the number of variables in
DTD.
Otherwise
is the number of nonzero values in
ISX.
- 14: – INTEGEROutput
-
On exit: , the actual number of steps carried out in the model fitting process.
- 15: – REAL (KIND=nag_wp) arrayOutput
-
Note: the second dimension of the array
B
must be at least
.
On exit:
the parameter estimates, with
, the parameter estimate for the
th variable,
at the
th step of the model fitting process,
.
By default, when
the parameter estimates are rescaled prior to being returned. If the parameter estimates are required on the normalized scale, then this can be overridden via
ROPT.
The values held in the remaining part of
B depend on the type of preprocessing performed.
for .
- 16: – INTEGERInput
-
On entry: the first dimension of the array
B as declared in the (sub)program from which G02MBF is called.
Constraint:
, where
is the number of parameter estimates as described in
IP.
- 17: – REAL (KIND=nag_wp) arrayOutput
-
On exit: summaries of the model fitting process. When
- , the sum of the absolute values of the parameter estimates for the th step of the modelling fitting process. If , the scaled parameter estimates are used in the summation.
- , the residual sums of squares for the th step, where .
- , approximate degrees of freedom for the th step.
- , a -type statistic for the th step, where .
- , correlation between the residual at step and the most correlated variable not yet in the active set , where the residual at step is .
- , the step size used at step .
In addition
- .
- , the residual sums of squares for the null model, where .
- , the degrees of freedom for the null model, where if and otherwise.
- , a -type statistic for the null model, where .
- , where and .
Although the statistics described above are returned when they may not be meaningful due to the estimate not being based on the saturated model.
- 18: – REAL (KIND=nag_wp) arrayInput
-
On entry: optional parameters to control various aspects of the LARS algorithm.
The default value will be used for
if
, therefore setting
will use the default values for all optional arguments and
ROPT need not be set. The default value will also be used if an invalid value is supplied for a particular argument, for example, setting
will use the default value for argument
.
- The minimum step size that will be taken.
Default is
is used, where
is the
machine precision returned by
X02AJF.
- General tolerance, used amongst other things, for comparing correlations.
Default is .
- If set to then parameter estimates are rescaled before being returned. If set to then no rescaling is performed. This argument has no effect when .
Default is for the parameter estimates to be rescaled.
Constraints:
- ;
- .
- 19: – INTEGERInput
-
On entry: length of the options array
ROPT.
Constraint:
.
- 20: – 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, because for this routine the values of the output parameters may be useful even if
on exit, 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).
Note: G02MBF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
-
On entry, .
Constraint: , , or .
-
On entry, .
Constraint: or .
-
On entry, .
Constraint: or .
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
The cross-product matrix supplied in
DTD is not symmetric.
-
On entry, .
Constraint: diagonal elements of must be positive.
On entry, and .
Constraint: diagonal elements of must be positive.
-
On entry, and
Constraint: .
-
On entry, .
Constraint: or for all .
-
On entry, all values of
ISX are zero.
Constraint: at least one value of
ISX must be nonzero.
-
On entry, and .
Constraint: or .
-
On entry, .
Constraint: .
-
A negative value for the residual sums of squares was obtained. Check the values of
DTD,
DTY and
YTY.
-
On entry, .
Constraint: .
-
Fitting process did not finished in
MNSTEP steps. Try increasing the size of
MNSTEP and supplying larger output arrays.
All output is returned as documented, up to step
MNSTEP, however,
and the
statistics may not be meaningful.
-
On entry, and .
Constraint: if then .
-
On entry, and .
Constraint: if , .
-
is approximately zero and hence the -type criterion cannot be calculated. All other output is returned as documented.
-
, therefore sigma has been set to a large value. Output is returned as documented.
-
Degenerate model, no variables added and . Output is returned as documented.
-
On entry, .
Constraint: .
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
Not applicable.
8 Parallelism and Performance
G02MBF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02MBF 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.
The solution path to the LARS, LASSO and stagewise regression analysis is a continuous, piecewise linear. G02MBF returns the parameter estimates at various points along this path.
G02MCF can be used to obtain estimates at different points along the path.
If you have the raw data values, that is
and
, then
G02MAF can be used instead of G02MBF.
10 Example
This example performs a LARS on a simulated dataset with observations and independent variables.
The example uses
G02BUF to get the cross-products of the augmented matrix
. The first
elements of the (column packed) cross-products matrix returned therefore contain the elements of
, the next
elements contain
and the last element
.
10.1 Program Text
Program Text (g02mbfe.f90)
10.2 Program Data
Program Data (g02mbfe.d)
10.3 Program Results
Program Results (g02mbfe.r)
This example plot shows the regression coefficients () plotted against the scaled absolute sum of the parameter estimates ().