# NAG CPP Interfacenagcpp::correg::lars (g02ma)

Settings help

CPP Name Style:

## 1Purpose

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

## 2Specification

```#include "g02/nagcpp_g02ma.hpp"
```
```template <typename D, typename ISX, typename Y, typename B, typename FITSUM>

void function lars(const types::f77_integer mtype, const D &d, const ISX &isx, const Y &y, types::f77_integer &ip, types::f77_integer &nstep, B &&b, FITSUM &&fitsum, OptionalG02MA opt)```
```template <typename D, typename ISX, typename Y, typename B, typename FITSUM>

void function lars(const types::f77_integer mtype, const D &d, const ISX &isx, const Y &y, types::f77_integer &ip, types::f77_integer &nstep, B &&b, FITSUM &&fitsum)```

## 3Description

lars 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. 1.Set $k=1$ and all coefficients to zero, that is $\beta =0$.
2. 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. 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. 4.Increment $k$ and add ${x}_{{j}_{k}}$ to $\mathcal{A}$.
5. 5.If $|\mathcal{A}|=p$ go to 8.
6. 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. 7.Go to 4.
8. 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 ‖βk‖1 ≤tk$
for all values of ${t}_{k}$, where $\alpha =\overline{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. 1.Initialize $k=1$ and the vector of residuals ${r}_{0}=y-\alpha$.
2. 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. 3.Calculate ${j}_{k}=\underset{j}{\mathrm{argmax}}\phantom{\rule{0.25em}{0ex}}|{c}_{j}|$, the value of $j$ with the largest absolute value of ${c}_{j}$.
4. 4.If $|{c}_{{j}_{k}}|<\epsilon$ then go to 7.
5. 5.Update the residual values, with
 $rk = rk-1 + δ ⁢ ​ ​ sign(cjk) ⁢ 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. 6.Increment $k$ and go to 2.
7. 7.Set $K=k$.
If the largest possible step were to be taken, that is $\delta =|{c}_{{j}_{k}}|$ then forward stagewise linear regression reverts to the standard forward selection method as implemented in g02eef (no CPP interface).
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
 $Cp(k) = ‖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)}$.

## 4References

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

## 5Arguments

1: $\mathbf{mtype}$types::f77_integer Input
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: $\mathbf{d}\left({\mathbf{n}},{\mathbf{m}}\right)$double array Input
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}-1,\mathit{j}-1\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{m}}$.
3: $\mathbf{isx}\left({\mathbf{lisx}}\right)$types::f77_integer array Input
On entry: indicates which independent variables from d will be included in the design matrix, $X$.
If isx is nullptr, all variables are included in the design matrix.
Otherwise${\mathbf{isx}}\left(\mathit{j}-1\right)$ must be set as follows, for $\mathit{j}=1,2,\dots ,{\mathbf{m}}$:
${\mathbf{isx}}\left(j-1\right)=1$
To indicate that the $j$th variable, as supplied in d, is included in the design matrix;
${\mathbf{isx}}\left(j-1\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}-1\right)$.
Constraint: if ${\mathbf{lisx}}={\mathbf{m}}$, ${\mathbf{isx}}\left(\mathit{j}-1\right)=0$ or $1$ and at least one value of ${\mathbf{isx}}\left(\mathit{j}-1\right)\ne 0$, for $\mathit{j}=1,2,\dots ,{\mathbf{m}}$.
4: $\mathbf{y}\left({\mathbf{n}}\right)$double array Input
On entry: $y$, the observations on the dependent variable.
5: $\mathbf{ip}$types::f77_integer Output
On exit: $p$, number of parameter estimates.
If isx is nullptr, $p={\mathbf{m}}$, i.e., the number of variables in d.
Otherwise $p$ is the number of nonzero values in isx.
6: $\mathbf{nstep}$types::f77_integer Output
On exit: $K$, the actual number of steps carried out in the model fitting process.
7: $\mathbf{b}\left(\mathrm{vl_p},{\mathbf{mnstep}}+2\right)$double array Output
On exit: $\beta$ the parameter estimates, with ${\mathbf{b}}\left(j-1,k-1\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-1,{\mathbf{nstep}}\right)& =& 1\\ {\mathbf{b}}\left(j-1,{\mathbf{nstep}}+1\right)& =& 0\end{array}$
If ${\mathbf{pred}}=1$,
$\begin{array}{lll}{\mathbf{b}}\left(j-1,{\mathbf{nstep}}\right)& =& 1\\ {\mathbf{b}}\left(j-1,{\mathbf{nstep}}+1\right)& =& {\overline{x}}_{j}\end{array}$
If ${\mathbf{pred}}=2$,
$\begin{array}{lll}{\mathbf{b}}\left(j-1,{\mathbf{nstep}}\right)& =& 1/\sqrt{{x}_{j}^{\mathrm{T}}{x}_{j}}\\ {\mathbf{b}}\left(j-1,{\mathbf{nstep}}+1\right)& =& 0\end{array}$
If ${\mathbf{pred}}=3$,
$\begin{array}{lll}{\mathbf{b}}\left(j-1,{\mathbf{nstep}}\right)& =& 1/\sqrt{{\left({x}_{j}-{\overline{x}}_{j}\right)}^{\mathrm{T}}\left({x}_{j}-{\overline{x}}_{j}\right)}\\ {\mathbf{b}}\left(j-1,{\mathbf{nstep}}+1\right)& =& {\overline{x}}_{j}\end{array}$
for $j=1,2,\dots ,p$.
8: $\mathbf{fitsum}\left(6,{\mathbf{mnstep}}+1\right)$double array Output
On exit: summaries of the model fitting process. When $k=1,2,\dots ,{\mathbf{nstep}}$,
${\mathbf{fitsum}}\left(0,k-1\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(1,k-1\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(2,k-1\right)$
${\nu }_{k}$, approximate degrees of freedom for the $k$th step.
${\mathbf{fitsum}}\left(3,k-1\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(4,k-1\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(5,k-1\right)$
${\stackrel{^}{\gamma }}_{k}$, the step size used at step $k$.
${\mathbf{fitsum}}\left(0,{\mathbf{nstep}}\right)$
$\alpha$, with $\alpha =\overline{y}$ if ${\mathbf{prey}}=1$ and $0$ otherwise.
${\mathbf{fitsum}}\left(1,{\mathbf{nstep}}\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-\overline{y}\right)}^{\mathrm{T}}\left(y-\overline{y}\right)$ otherwise.
${\mathbf{fitsum}}\left(2,{\mathbf{nstep}}\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(3,{\mathbf{nstep}}\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(4,{\mathbf{nstep}}\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{errorid}={\mathbf{112}}$ they may not be meaningful due to the estimate ${\sigma }^{2}$ not being based on the saturated model.
9: $\mathbf{opt}$OptionalG02MA Input/Output
Optional parameter container, derived from Optional.
Container for:
predtypes::f77_integer
This optional parameter may be set using the method OptionalG02MA::pred and accessed via OptionalG02MA::get_pred.
Default: $3$
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, $\overline{x}$, are returned in b, with ${\overline{x}}_{\mathit{j}}={\mathbf{b}}\left(\mathit{j}-1,{\mathbf{nstep}}+1\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}-1,{\mathbf{nstep}}\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$.
preytypes::f77_integer
This optional parameter may be set using the method OptionalG02MA::prey and accessed via OptionalG02MA::get_prey.
Default: $1$
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 =\overline{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(0,{\mathbf{nstep}}\right)$.
Suggested value: ${\mathbf{prey}}=1$.
Constraint: ${\mathbf{prey}}=0$ or $1$.
mnsteptypes::f77_integer
This optional parameter may be set using the method OptionalG02MA::mnstep and accessed via OptionalG02MA::get_mnstep.
Default: if $\left({\mathbf{mtype}}=1\right)$: ${\mathbf{m}}$; otherwise: $200*{\mathbf{m}}$
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$.
roptvector<double> array
This optional parameter may be set using the method OptionalG02MA::ropt and accessed via OptionalG02MA::get_ropt.
On entry: optional parameters to control various aspects of the LARS algorithm.
The default value will be used for ${\mathbf{ropt}}\left(i-1\right)$ if the length of ropt is less than $i$, therefore, to use the default values for all optional parameters 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-1\right)=-1$ will use the default value for argument $i$.
${\mathbf{ropt}}\left(0\right)$
The minimum step size that will be taken.
Default is $100×\mathit{eps}$, where $\mathit{eps}$ is the machine precision returned by precision.
${\mathbf{ropt}}\left(1\right)$
General tolerance, used amongst other things, for comparing correlations.
Default is ${\mathbf{ropt}}\left(0\right)$.
${\mathbf{ropt}}\left(2\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(3\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(4\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(4\right)=1$, $y$ and $X$ are worked with directly.
If ${\mathbf{ropt}}\left(4\right)=0$, the cross-product matrices are used.
Default is $1$ when $p\ge 500$ and $n and $0$ otherwise.
Constraints:
• ;
• ;
• ${\mathbf{ropt}}\left(2\right)=0$ or $1$;
• ${\mathbf{ropt}}\left(3\right)=0$ or $1$;
• ${\mathbf{ropt}}\left(4\right)=0$ or $1$.

1: $\mathbf{n}$
$n$, the number of observations.
2: $\mathbf{m}$
$m$, the total number of independent variables.
3: $\mathbf{lisx}$
Length of the isx array.
4: $\mathbf{ldb}$
The first dimension of the array b.
5: $\mathbf{lropt}$
Length of the options array ropt

## 6Exceptions and Warnings

Errors or warnings detected by the function:
Note: in some cases lars may return useful information.
All errors and warnings have an associated numeric error code field, errorid, stored either as a member of the thrown exception object (see errorid), or as a member of opt.ifail, depending on how errors and warnings are being handled (see Error Handling for more details).
Raises: ErrorException
$\mathbf{errorid}=11$
On entry, ${\mathbf{mtype}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{mtype}}=1,2,3\text{​ or ​}4$.
$\mathbf{errorid}=21$
On entry, ${\mathbf{pred}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{pred}}=0,1,2\text{​ or ​}3$.
$\mathbf{errorid}=31$
On entry, ${\mathbf{prey}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{prey}}=0\text{​ or ​}1$.
$\mathbf{errorid}=41$
On entry, ${\mathbf{n}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
$\mathbf{errorid}=51$
On entry, ${\mathbf{m}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
$\mathbf{errorid}=81$
On entry, ${\mathbf{isx}}\left[⟨\mathit{value}⟩\right]=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{isx}}\left[i\right]=0\text{​ or ​}1$, for all $i$.
$\mathbf{errorid}=82$
On entry, all values of isx are zero.
Constraint: at least one value of isx must be nonzero.
$\mathbf{errorid}=91$
On entry, ${\mathbf{lisx}}=⟨\mathit{value}⟩$ and ${\mathbf{m}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{lisx}}=0\text{​ or ​}{\mathbf{m}}$.
$\mathbf{errorid}=111$
On entry, ${\mathbf{mnstep}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{mnstep}}\ge 1$.
$\mathbf{errorid}=151$
On entry, ${\mathbf{ldb}}=⟨\mathit{value}⟩$ and ${\mathbf{m}}=⟨\mathit{value}⟩$.
Constraint: if ${\mathbf{lisx}}=0$ then ${\mathbf{ldb}}\ge {\mathbf{m}}$.
$\mathbf{errorid}=152$
On entry, ${\mathbf{ldb}}=⟨\mathit{value}⟩$ and $p=⟨\mathit{value}⟩$.
Constraint: if ${\mathbf{lisx}}={\mathbf{m}}$ then ${\mathbf{ldb}}\ge p$.
$\mathbf{errorid}=181$
On entry, ${\mathbf{lropt}}=⟨\mathit{value}⟩$.
Constraint: $0\le ;{\mathbf{lropt}}\le ;5$.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument has $⟨\mathit{\text{value}}⟩$ dimensions.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument was a vector of size $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
The size for the supplied array could not be ascertained.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a $⟨\mathit{\text{value}}⟩$ x $⟨\mathit{\text{value}}⟩$ array.
Supplied argument has $⟨\mathit{\text{value}}⟩$ dimensions.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a $⟨\mathit{\text{value}}⟩$ x $⟨\mathit{\text{value}}⟩$ array.
Supplied argument was a $⟨\mathit{\text{value}}⟩$ x $⟨\mathit{\text{value}}⟩$ array.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a $⟨\mathit{\text{value}}⟩$ x $⟨\mathit{\text{value}}⟩$ array.
Not all of the sizes for the supplied array could be ascertained.
$\mathbf{errorid}=10602$
On entry, the raw data component of $⟨\mathit{\text{value}}⟩$ is null.
$\mathbf{errorid}=10603$
On entry, unable to ascertain a value for $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=10604$
On entry, the data in $⟨\mathit{\text{value}}⟩$ is stored in $⟨\mathit{\text{value}}⟩$ Major Order.
The data was expected to be in $⟨\mathit{\text{value}}⟩$ Major Order.
$\mathbf{errorid}=10703$
An exception was thrown during IO (writing).
$\mathbf{errorid}=-99$
An unexpected error has been triggered by this routine.
$\mathbf{errorid}=-399$
Your licence key may have expired or may not have been installed correctly.
$\mathbf{errorid}=-999$
Dynamic memory allocation failed.
Raises: WarningException
$\mathbf{errorid}=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{errorid}=161$
${\sigma }^{2}$ is approximately zero and hence the ${C}_{p}$-type criterion
cannot be calculated. All other output is returned as documented.
$\mathbf{errorid}=162$
${\nu }_{K}=n$, therefore, $\sigma$ has been set to a large value.
Output is returned as documented.
$\mathbf{errorid}=163$
Degenerate model, no variables added and ${\mathbf{nstep}}=0$.
Output is returned as documented.
$\mathbf{errorid}=163$
Degenerate model, no variables added and ${\mathbf{nstep}}=0$.
Output is returned as documented.

Not applicable.

## 8Parallelism and Performance

Please see the description for the underlying computational routine in this section of the FL Interface documentation.

lars 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 (no CPP interface) 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 (no CPP interface) and g02bzf (no CPP interface), and g02mbf (no CPP interface) called to perform the analysis.
The amount of workspace used by lars depends on whether the cross-product matrices are being used internally (as controlled by ropt). If the cross-product matrices are being used then lars 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.

## 10Example

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

### 10.1Example Program

Source File Data Results
ex_g02ma.cpp None ex_g02ma.r