G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02MAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G02MAF performs Least Angle Regression (LARS), forward stagewise linear regression or Least Absolute Shrinkage and Selection Operator (LASSO).

## 2  Specification

 SUBROUTINE G02MAF ( MTYPE, PRED, PREY, N, M, D, LDD, ISX, LISX, Y, MNSTEP, IP, NSTEP, B, LDB, FITSUM, ROPT, LROPT, IFAIL)
 INTEGER MTYPE, PRED, PREY, N, M, LDD, ISX(LISX), LISX, MNSTEP, IP, NSTEP, LDB, LROPT, IFAIL REAL (KIND=nag_wp) D(LDD,*), Y(N), B(LDB,*), FITSUM(6,MNSTEP+1), ROPT(LROPT)

## 3  Description

G02MAF 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 $n$ observed values, $y=\left\{{y}_{i}:i=1,2,\dots ,n\right\}$ and an $n×p$ design matrix $X$, where the $j$th column of $X$, denoted ${x}_{j}$, is a vector of length $n$ representing the $j$th independent variable ${x}_{j}$, standardized such that $\sum _{\mathit{i}=1}^{n}{x}_{ij}=0$, and $\sum _{\mathit{i}=1}^{n}{x}_{ij}^{2}=1$ and a set of model parameters $\beta$ to be estimated from the observed values, the LARS algorithm can be summarised as:
 1 Set $k=1$ and all coefficients to zero, that is $\beta =0$. 2 Find the variable most correlated with $y$, say ${x}_{{j}_{1}}$. Add ${x}_{{j}_{1}}$ to the ‘most correlated’ set $\mathcal{A}$. If $p=1$ go to 8. 3 Take the largest possible step in the direction of ${x}_{{j}_{1}}$ (i.e., increase the magnitude of ${\beta }_{{j}_{1}}$) until some other variable, say ${x}_{{j}_{2}}$, has the same correlation with the current residual, $y-{x}_{{j}_{1}}{\beta }_{{j}_{1}}$. 4 Increment $k$ and add ${x}_{{j}_{k}}$ to $\mathcal{A}$. 5 If $\left|\mathcal{A}\right|=p$ go to 8. 6 Proceed in the ‘least angle direction’, that is, the direction which is equiangular between all variables in $\mathcal{A}$, altering the magnitude of the parameter estimates of those variables in $\mathcal{A}$, until the $k$th variable, ${x}_{{j}_{k}}$, has the same correlation with the current residual. 7 Go to 4. 8 Let $K=k$.
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 (i.e., ${\beta }_{kj}\ge 0$), 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
 $minimize α , βk∈ ℝp y- α- XT βk 2 subject to βk1 ≤tk$
for all values of ${t}_{k}$, where $\alpha =\stackrel{-}{y}={n}^{-1}\sum _{\mathit{i}=1}^{n}{y}_{i}$. The positive LASSO model is the same as the standard LASSO model, given above, with the added constraint that
 $βkj ≥ 0 , j=1,2,…,p .$
Unlike the standard LARS algorithm, when fitting either of the LASSO models, variables can be dropped as well as added to the set $\mathcal{A}$. Therefore the total number of steps $K$ is no longer bounded by $p$.
Forward stagewise linear regression is an iterative procedure of the form:
1. Initialize $k=1$ and the vector of residuals ${r}_{0}=y-\alpha$.
2. For each $j=1,2,\dots ,p$ calculate ${c}_{j}={x}_{j}^{\mathrm{T}}{r}_{k-1}$. The value ${c}_{j}$ is therefore proportional to the correlation between the $j$th independent variable and the vector of previous residual values, ${r}_{k}$.
3. Calculate ${j}_{k}=\underset{j}{\mathrm{argmax}}\phantom{\rule{0.25em}{0ex}}\left|{c}_{j}\right|$, the value of $j$ with the largest absolute value of ${c}_{j}$.
4. If $\left|{c}_{{j}_{k}}\right|<\epsilon$ then go to 7.
5. Update the residual values, with
 $rk = rk-1 + δ ⁢ ​ ​ signcjk ⁢ xjk$
where $\delta$ is a small constant and $\mathrm{sign}\left({c}_{{j}_{k}}\right)=-1$ when ${c}_{{j}_{k}}<0$ and $1$ otherwise.
6. Increment $k$ and go to 2.
7. Set $K=k$.
If the largest possible step were to be taken, that is $\delta =\left|{c}_{{j}_{k}}\right|$ then forward stagewise linear regression reverts to the standard forward selection method as implemented in G02EEF.
The LARS procedure results in $K$ 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 ${C}_{p}$-type statistic given by
 $Cpk = y- XT βk 2 σ2 -n+2⁢νk,$
where ${\nu }_{k}$ is the approximate degrees of freedom for the $k$th step and
 $σ2 = n-yTyνK .$
One way of choosing a model is therefore to take the one with the smallest value of ${C}_{p}^{\left(k\right)}$.

## 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  Arguments

1:     $\mathrm{MTYPE}$ – INTEGERInput
On entry: indicates the type of model to fit.
${\mathbf{MTYPE}}=1$
LARS is performed.
${\mathbf{MTYPE}}=2$
Forward linear stagewise regression is performed.
${\mathbf{MTYPE}}=3$
LASSO model is fit.
${\mathbf{MTYPE}}=4$
A positive LASSO model is fit.
Constraint: ${\mathbf{MTYPE}}=1$, $2$, $3$ or $4$.
2:     $\mathrm{PRED}$ – INTEGERInput
On entry: indicates the type of data preprocessing to perform on the independent variables supplied in D to comply with the standardized form of the design matrix.
${\mathbf{PRED}}=0$
No preprocessing is performed.
${\mathbf{PRED}}=1$
Each of the independent variables, ${x}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,p$, are mean centred prior to fitting the model. The means of the independent variables, $\stackrel{-}{x}$, are returned in B, with ${\stackrel{-}{x}}_{\mathit{j}}={\mathbf{B}}\left(\mathit{j},{\mathbf{NSTEP}}+2\right)$, for $\mathit{j}=1,2,\dots ,p$.
${\mathbf{PRED}}=2$
Each independent variable is normalized, with the $j$th variable scaled by $1/\sqrt{{x}_{j}^{\mathrm{T}}{x}_{j}}$. The scaling factor used by variable $j$ is returned in ${\mathbf{B}}\left(\mathit{j},{\mathbf{NSTEP}}+1\right)$.
${\mathbf{PRED}}=3$
As ${\mathbf{PRED}}=1$ and $2$, all of the independent variables are mean centred prior to being normalized.
Suggested value: ${\mathbf{PRED}}=3$.
Constraint: ${\mathbf{PRED}}=0$, $1$, $2$ or $3$.
3:     $\mathrm{PREY}$ – INTEGERInput
On entry: indicates the type of data preprocessing to perform on the dependent variable supplied in Y.
${\mathbf{PREY}}=0$
No preprocessing is performed, this is equivalent to setting $\alpha =0$.
${\mathbf{PREY}}=1$
The dependent variable, $y$, is mean centred prior to fitting the model, so $\alpha =\stackrel{-}{y}$. Which is equivalent to fitting a non-penalized intercept to the model and the degrees of freedom etc. are adjusted accordingly.
The value of $\alpha$ used is returned in ${\mathbf{FITSUM}}\left(1,{\mathbf{NSTEP}}+1\right)$.
Suggested value: ${\mathbf{PREY}}=1$.
Constraint: ${\mathbf{PREY}}=0$ or $1$.
4:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{N}}\ge 1$.
5:     $\mathrm{M}$ – INTEGERInput
On entry: $m$, the total number of independent variables.
Constraint: ${\mathbf{M}}\ge 1$.
6:     $\mathrm{D}\left({\mathbf{LDD}},*\right)$ – REAL (KIND=nag_wp) arrayInput
Note: the second dimension of the array D must be at least ${\mathbf{M}}$.
On entry: $D$, the data, which along with PRED and ISX, defines the design matrix $X$. The $\mathit{i}$th observation for the $\mathit{j}$th variable must be supplied in ${\mathbf{D}}\left(\mathit{i},\mathit{j}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{M}}$.
7:     $\mathrm{LDD}$ – INTEGERInput
On entry: the first dimension of the array D as declared in the (sub)program from which G02MAF is called.
Constraint: ${\mathbf{LDD}}\ge {\mathbf{N}}$.
8:     $\mathrm{ISX}\left({\mathbf{LISX}}\right)$ – INTEGER arrayInput
On entry: indicates which independent variables from D will be included in the design matrix, $X$.
If ${\mathbf{LISX}}=0$, all variables are included in the design matrix and ISX is not referenced.
If ${\mathbf{LISX}}={\mathbf{M}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{M}}$ when ${\mathbf{ISX}}\left(j\right)$ must be set as follows:
${\mathbf{ISX}}\left(j\right)=1$
To indicate that the $j$th variable, as supplied in D, is included in the design matrix;
${\mathbf{ISX}}\left(j\right)=0$
To indicated that the $j$th variable, as supplied in D, is not included in the design matrix;
and $p=\sum _{\mathit{j}=1}^{m}{\mathbf{ISX}}\left(\mathit{j}\right)$.
Constraint: if ${\mathbf{LISX}}={\mathbf{M}}$, ${\mathbf{ISX}}\left(\mathit{j}\right)=0$ or $1$ and at least one value of ${\mathbf{ISX}}\left(\mathit{j}\right)\ne 0$, for $\mathit{j}=1,2,\dots ,{\mathbf{M}}$.
9:     $\mathrm{LISX}$ – INTEGERInput
On entry: length of the ISX array.
Constraint: ${\mathbf{LISX}}=0$ or ${\mathbf{M}}$.
10:   $\mathrm{Y}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: $y$, the observations on the dependent variable.
11:   $\mathrm{MNSTEP}$ – INTEGERInput
On entry: the maximum number of steps to carry out in the model fitting process.
If ${\mathbf{MTYPE}}=1$, i.e., a LARS is being performed, the maximum number of steps the algorithm will take is $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,n\right)$ if ${\mathbf{PREY}}=0$, otherwise $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,n-1\right)$.
If ${\mathbf{MTYPE}}=2$, 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 $p$ or $n$.
If ${\mathbf{MTYPE}}=3$ or $4$, 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 $p$ or $n$.
Constraint: ${\mathbf{MNSTEP}}\ge 1$.
12:   $\mathrm{IP}$ – INTEGEROutput
On exit: $p$, number of parameter estimates.
If ${\mathbf{LISX}}=0$, $p={\mathbf{M}}$, i.e., the number of variables in D.
Otherwise $p$ is the number of nonzero values in ISX.
13:   $\mathrm{NSTEP}$ – INTEGEROutput
On exit: $K$, the actual number of steps carried out in the model fitting process.
14:   $\mathrm{B}\left({\mathbf{LDB}},*\right)$ – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array B must be at least ${\mathbf{MNSTEP}}+2$.
On exit: $\beta$ the parameter estimates, with ${\mathbf{B}}\left(j,k\right)={\beta }_{kj}$, the parameter estimate for the $j$th variable, $j=1,2,\dots ,p$ at the $k$th step of the model fitting process, $k=1,2,\dots ,{\mathbf{NSTEP}}$.
By default, when ${\mathbf{PRED}}=2$ or $3$ 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.
If ${\mathbf{PRED}}=0$,
$\begin{array}{lll}{\mathbf{B}}\left(j,{\mathbf{NSTEP}}+1\right)& =& 1\\ {\mathbf{B}}\left(j,{\mathbf{NSTEP}}+2\right)& =& 0\end{array}$
If ${\mathbf{PRED}}=1$,
$\begin{array}{lll}{\mathbf{B}}\left(j,{\mathbf{NSTEP}}+1\right)& =& 1\\ {\mathbf{B}}\left(j,{\mathbf{NSTEP}}+2\right)& =& {\stackrel{-}{x}}_{j}\end{array}$
If ${\mathbf{PRED}}=2$,
$\begin{array}{lll}{\mathbf{B}}\left(j,{\mathbf{NSTEP}}+1\right)& =& 1/\sqrt{{x}_{j}^{\mathrm{T}}{x}_{j}}\\ {\mathbf{B}}\left(j,{\mathbf{NSTEP}}+2\right)& =& 0\end{array}$
If ${\mathbf{PRED}}=3$,
$\begin{array}{lll}{\mathbf{B}}\left(j,{\mathbf{NSTEP}}+1\right)& =& 1/\sqrt{{\left({x}_{j}-{\stackrel{-}{x}}_{j}\right)}^{\mathrm{T}}\left({x}_{j}-{\stackrel{-}{x}}_{j}\right)}\\ {\mathbf{B}}\left(j,{\mathbf{NSTEP}}+2\right)& =& {\stackrel{-}{x}}_{j}\end{array}$
for $j=1,2,\dots ,p$.
15:   $\mathrm{LDB}$ – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which G02MAF is called.
Constraint: ${\mathbf{LDB}}\ge p$, where $p$ is the number of parameter estimates as described in IP.
16:   $\mathrm{FITSUM}\left(6,{\mathbf{MNSTEP}}+1\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: summaries of the model fitting process. When $k=1,2,\dots ,{\mathbf{NSTEP}}$,
${\mathbf{FITSUM}}\left(1,k\right)$
${‖{\beta }_{k}‖}_{1}$, the sum of the absolute values of the parameter estimates for the $k$th step of the modelling fitting process. If ${\mathbf{PRED}}=2$ or $3$, the scaled parameter estimates are used in the summation.
${\mathbf{FITSUM}}\left(2,k\right)$
${\mathrm{RSS}}_{k}$, the residual sums of squares for the $k$th step, where ${\mathrm{RSS}}_{k}={‖y-{X}^{\mathrm{T}}{\beta }_{k}‖}^{2}$.
${\mathbf{FITSUM}}\left(3,k\right)$
${\nu }_{k}$, approximate degrees of freedom for the $k$th step.
${\mathbf{FITSUM}}\left(4,k\right)$
${C}_{p}^{\left(k\right)}$, a ${C}_{p}$-type statistic for the $k$th step, where ${C}_{p}^{\left(k\right)}=\frac{{\mathrm{RSS}}_{k}}{{\sigma }^{2}}-n+2{\nu }_{k}$.
${\mathbf{FITSUM}}\left(5,k\right)$
${\stackrel{^}{C}}_{k}$, correlation between the residual at step $k-1$ and the most correlated variable not yet in the active set $\mathcal{A}$, where the residual at step $0$ is $y$.
${\mathbf{FITSUM}}\left(6,k\right)$
${\stackrel{^}{\gamma }}_{k}$, the step size used at step $k$.
${\mathbf{FITSUM}}\left(1,{\mathbf{NSTEP}}+1\right)$
$\alpha$, with $\alpha =\stackrel{-}{y}$ if ${\mathbf{PREY}}=1$ and $0$ otherwise.
${\mathbf{FITSUM}}\left(2,{\mathbf{NSTEP}}+1\right)$
${\mathrm{RSS}}_{0}$, the residual sums of squares for the null model, where ${\mathrm{RSS}}_{0}={y}^{\mathrm{T}}y$ when ${\mathbf{PREY}}=0$ and ${\mathrm{RSS}}_{0}={\left(y-\stackrel{-}{y}\right)}^{\mathrm{T}}\left(y-\stackrel{-}{y}\right)$ otherwise.
${\mathbf{FITSUM}}\left(3,{\mathbf{NSTEP}}+1\right)$
${\nu }_{0}$, the degrees of freedom for the null model, where ${\nu }_{0}=0$ if ${\mathbf{PREY}}=0$ and ${\nu }_{0}=1$ otherwise.
${\mathbf{FITSUM}}\left(4,{\mathbf{NSTEP}}+1\right)$
${C}_{p}^{\left(0\right)}$, a ${C}_{p}$-type statistic for the null model, where ${C}_{p}^{\left(0\right)}=\frac{{\mathrm{RSS}}_{0}}{{\sigma }^{2}}-n+2{\nu }_{0}$.
${\mathbf{FITSUM}}\left(5,{\mathbf{NSTEP}}+1\right)$
${\sigma }^{2}$, where ${\sigma }^{2}=\frac{n-{\mathrm{RSS}}_{K}}{{\nu }_{K}}$ and $K={\mathbf{NSTEP}}$.
Although the ${C}_{p}$ statistics described above are returned when ${\mathbf{IFAIL}}={\mathbf{112}}$ they may not be meaningful due to the estimate ${\sigma }^{2}$ not being based on the saturated model.
17:   $\mathrm{ROPT}\left({\mathbf{LROPT}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: optional parameters to control various aspects of the LARS algorithm.
The default value will be used for ${\mathbf{ROPT}}\left(i\right)$ if ${\mathbf{LROPT}}, therefore setting ${\mathbf{LROPT}}=0$ 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 ${\mathbf{ROPT}}\left(i\right)=-1$ will use the default value for argument $i$.
${\mathbf{ROPT}}\left(1\right)$
The minimum step size that will be taken.
Default is $100×\mathit{eps}$ is used, where $\mathit{eps}$ is the machine precision returned by X02AJF.
${\mathbf{ROPT}}\left(2\right)$
General tolerance, used amongst other things, for comparing correlations.
Default is ${\mathbf{ROPT}}\left(1\right)$.
${\mathbf{ROPT}}\left(3\right)$
If set to $1$, parameter estimates are rescaled before being returned.
If set to $0$, no rescaling is performed.
This argument has no effect when ${\mathbf{PRED}}=0$ or $1$.
Default is for the parameter estimates to be rescaled.
${\mathbf{ROPT}}\left(4\right)$
If set to $1$, it is assumed that the model contains an intercept during the model fitting process and when calculating the degrees of freedom.
If set to $0$, no intercept is assumed.
This has no effect on the amount of preprocessing performed on Y.
Default is to treat the model as having an intercept when ${\mathbf{PREY}}=1$ and as not having an intercept when ${\mathbf{PREY}}=0$.
${\mathbf{ROPT}}\left(5\right)$
As implemented, the LARS algorithm can either work directly with $y$ and $X$, or it can work with the cross-product matrices, ${X}^{\mathrm{T}}y$ and ${X}^{\mathrm{T}}X$. In most cases it is more efficient to work with the cross-product matrices. This flag allows you direct control over which method is used, however, the default value will usually be the best choice.
If ${\mathbf{ROPT}}\left(5\right)=1$, $y$ and $X$ are worked with directly.
If ${\mathbf{ROPT}}\left(5\right)=0$, the cross-product matrices are used.
Default is $1$ when $p\ge 500$ and $n and $0$ otherwise.
Constraints:
• ;
• ;
• ${\mathbf{ROPT}}\left(3\right)=0$ or $1$;
• ${\mathbf{ROPT}}\left(4\right)=0$ or $1$;
• ${\mathbf{ROPT}}\left(5\right)=0$ or $1$.
18:   $\mathrm{LROPT}$ – INTEGERInput
On entry: length of the options array ROPT.
Constraint: $0\le {\mathbf{LROPT}}\le 5$.
19:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if ${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}1$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G02MAF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=11$
On entry, ${\mathbf{MTYPE}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{MTYPE}}=1$, $2$, $3$ or $4$.
${\mathbf{IFAIL}}=21$
On entry, ${\mathbf{PRED}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{PRED}}=0$, $1$, $2$ or $3$.
${\mathbf{IFAIL}}=31$
On entry, ${\mathbf{PREY}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{PREY}}=0$ or $1$.
${\mathbf{IFAIL}}=41$
On entry, ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{N}}\ge 1$.
${\mathbf{IFAIL}}=51$
On entry, ${\mathbf{M}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{M}}\ge 1$.
${\mathbf{IFAIL}}=71$
On entry, ${\mathbf{LDD}}=〈\mathit{\text{value}}〉$ and ${\mathbf{N}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LDD}}\ge {\mathbf{N}}$.
${\mathbf{IFAIL}}=81$
On entry, ${\mathbf{ISX}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ISX}}\left(i\right)=0$ or $1$ for all $i$.
${\mathbf{IFAIL}}=82$
On entry, all values of ISX are zero.
Constraint: at least one value of ISX must be nonzero.
${\mathbf{IFAIL}}=91$
On entry, ${\mathbf{LISX}}=〈\mathit{\text{value}}〉$ and ${\mathbf{M}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LISX}}=0$ or ${\mathbf{M}}$.
${\mathbf{IFAIL}}=111$
On entry, ${\mathbf{MNSTEP}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{MNSTEP}}\ge 1$.
${\mathbf{IFAIL}}=112$
Fitting process did not finish 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, $\sigma$ and the ${C}_{p}$ statistics may not be meaningful.
${\mathbf{IFAIL}}=151$
On entry, ${\mathbf{LDB}}=〈\mathit{\text{value}}〉$ and ${\mathbf{M}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{LISX}}=0$ then ${\mathbf{LDB}}\ge {\mathbf{M}}$.
${\mathbf{IFAIL}}=152$
On entry, ${\mathbf{LDB}}=〈\mathit{\text{value}}〉$ and $p=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{LISX}}=M$ then ${\mathbf{LDB}}\ge p$.
${\mathbf{IFAIL}}=161$
${\sigma }^{2}$ is approximately zero and hence the ${C}_{p}$-type criterion cannot be calculated. All other output is returned as documented.
${\mathbf{IFAIL}}=162$
${\nu }_{K}=n$, therefore $\sigma$ has been set to a large value. Output is returned as documented.
${\mathbf{IFAIL}}=163$
Degenerate model, no variables added and ${\mathbf{NSTEP}}=0$. Output is returned as documented.
${\mathbf{IFAIL}}=181$
On entry, ${\mathbf{LROPT}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{LROPT}}\le 5$.
${\mathbf{IFAIL}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8  Parallelism and Performance

G02MAF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02MAF 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.

## 9  Further Comments

G02MAF returns the parameter estimates at various points along the solution path of a LARS, LASSO or stagewise regression analysis. If the solution is required at a different set of points, for example when performing cross-validation, then G02MCF can be used.
For datasets with a large number of observations, $n$, it may be impractical to store the full $X$ matrix in memory in one go. In such instances the cross-product matrices ${X}^{\mathrm{T}}y$ and ${X}^{\mathrm{T}}X$ can be calculated, using for example, multiple calls to G02BUF and G02BZF, and G02MBF called to perform the analysis.
The amount of workspace used by G02MAF depends on whether the cross-product matrices are being used internally (as controlled by ROPT). If the cross-product matrices are being used then G02MAF internally allocates approximately $2{p}^{2}+4p+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(np\right)$ elements of real storage compared to ${p}^{2}+3p+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(np\right)+2n+n×p$ elements when $X$ and $y$ are used directly. In both cases approximately $5p$ elements of integer storage are also used. If a forward linear stagewise analysis is performed than an additional ${p}^{2}+5p$ elements of real storage are required.

## 10  Example

This example performs a LARS on a simulated dataset with $20$ observations and $6$ independent variables.

### 10.1  Program Text

Program Text (g02mafe.f90)

### 10.2  Program Data

Program Data (g02mafe.d)

### 10.3  Program Results

Program Results (g02mafe.r)

This example plot shows the regression coefficients (${\beta }_{k}$) plotted against the scaled absolute sum of the parameter estimates (${‖{\beta }_{k}‖}_{1}$).