# NAG C Library Function Document

## 1Purpose

nag_lars_xtx (g02mbc) performs Least Angle Regression (LARS), forward stagewise linear regression or Least Absolute Shrinkage and Selection Operator (LASSO) using cross-product matrices.

## 2Specification

 #include #include
 void nag_lars_xtx (Nag_LARSModelType mtype, Nag_LARSPreProcess pred, Nag_LARSPreProcess intcpt, Integer n, Integer m, const double dtd[], Integer pddtd, const Integer isx[], const double dty[], double yty, Integer mnstep, Integer *ip, Integer *nstep, double b[], Integer pdb, double fitsum[], const double ropt[], Integer lropt, NagError *fail)

## 3Description

nag_lars_xtx (g02mbc) 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, 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 nag_step_regsn (g02eec).
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)}$.

## 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}$Nag_LARSModelTypeInput
On entry: indicates the type of model to fit.
${\mathbf{mtype}}=\mathrm{Nag_LARS_LAR}$
LARS is performed.
${\mathbf{mtype}}=\mathrm{Nag_LARS_ForwardStagewise}$
Forward linear stagewise regression is performed.
${\mathbf{mtype}}=\mathrm{Nag_LARS_LASSO}$
LASSO model is fit.
${\mathbf{mtype}}=\mathrm{Nag_LARS_PositiveLASSO}$
A positive LASSO model is fit.
Constraint: ${\mathbf{mtype}}=\mathrm{Nag_LARS_LAR}$, $\mathrm{Nag_LARS_ForwardStagewise}$, $\mathrm{Nag_LARS_LASSO}$ or $\mathrm{Nag_LARS_PositiveLASSO}$.
2:    $\mathbf{pred}$Nag_LARSPreProcessInput
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.
${\mathbf{pred}}=\mathrm{Nag_LARS_None}$
No preprocessing is performed.
${\mathbf{pred}}=\mathrm{Nag_LARS_Normalized}$
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[{\mathbf{nstep}}×{\mathbf{pdb}}+\mathit{j}-1\right]$.
Constraint: ${\mathbf{pred}}=\mathrm{Nag_LARS_None}$ or $\mathrm{Nag_LARS_Normalized}$.
3:    $\mathbf{intcpt}$Nag_LARSPreProcessInput
On entry: indicates the type of data preprocessing that was perform on the dependent variable, $y$, prior to calling this function.
${\mathbf{intcpt}}=\mathrm{Nag_LARS_None}$
No preprocessing was performed.
${\mathbf{intcpt}}=\mathrm{Nag_LARS_Centered}$
The dependent variable, $y$, was mean centred.
Constraint: ${\mathbf{intcpt}}=\mathrm{Nag_LARS_None}$ or $\mathrm{Nag_LARS_Centered}$.
4:    $\mathbf{n}$IntegerInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
5:    $\mathbf{m}$IntegerInput
On entry: $m$, the total number of independent variables.
Constraint: ${\mathbf{m}}\ge 1$.
6:    $\mathbf{dtd}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array dtd must be at least
• ${\mathbf{pddtd}}×\left({\mathbf{m}}\left({\mathbf{m}}+1\right)/2\right)$ when ${\mathbf{pddtd}}=1$;
• ${\mathbf{pddtd}}×{\mathbf{m}}$ when .
On entry: ${D}^{\mathrm{T}}D$, the cross-product matrix, which along with isx, defines the design matrix cross-product ${X}^{\mathrm{T}}X$.
If ${\mathbf{pddtd}}=1$, ${\mathbf{dtd}}\left[\left(\mathit{i}×\left(\mathit{i}-1\right)/2+\mathit{j}-1\right)×{\mathbf{pddtd}}\right]$ must contain the cross-product of the $\mathit{i}$th and $\mathit{j}$th variable, for $\mathit{i}=1,2,\dots ,{\mathbf{m}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{m}}$. That is the cross-product stacked by columns as returned by nag_sum_sqs (g02buc), for example.
Otherwise ${\mathbf{dtd}}\left[\left(\mathit{j}-1\right)×{\mathbf{pddtd}}+\mathit{i}-1\right]$ must contain the cross-product of the $\mathit{i}$th and $\mathit{j}$th variable, for $\mathit{i}=1,2,\dots ,{\mathbf{m}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{m}}$. It should be noted that, even though ${D}^{\mathrm{T}}D$ is symmetric, the full matrix must be supplied.
The matrix specified in dtd must be a valid cross-products matrix.
7:    $\mathbf{pddtd}$IntegerInput
On entry: the stride separating row elements in the two-dimensional data stored in the array dtd.
Constraint: .
8:    $\mathbf{isx}\left[\mathit{dim}\right]$const IntegerInput
Note: the dimension, dim, of the array isx must be at least
• ${\mathbf{m}}$, when ${\mathbf{isx}}\phantom{\rule{0.25em}{0ex}}\text{is not}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$.
On entry: indicates which independent variables from dtd will be included in the design matrix, $X$.
If isx is NULL, all variables are included in the design matrix.
Otherwise, for $\mathit{j}=1,2,\dots ,{\mathbf{m}}$ when ${\mathbf{isx}}\left[j-1\right]$ must be set as follows:
${\mathbf{isx}}\left[j-1\right]=1$
To indicate that the $j$th variable, as supplied in dtd, is included in the design matrix;
${\mathbf{isx}}\left[\mathit{j}-1\right]=0$
To indicate that the $j$th variable, as supplied in dtd, is not included in the design matrix;
and $p=\sum _{\mathit{j}=1}^{m}{\mathbf{isx}}\left[\mathit{j}-1\right]$.
Constraint: ${\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}}$.
9:    $\mathbf{dty}\left[{\mathbf{m}}\right]$const doubleInput
On entry: ${D}^{\mathrm{T}}y$, the cross-product between the dependent variable, $y$, and the independent variables $D$.
10:  $\mathbf{yty}$doubleInput
On entry: ${y}^{\mathrm{T}}y$, the sums of squares of the dependent variable.
Constraint: ${\mathbf{yty}}>0.0$.
11:  $\mathbf{mnstep}$IntegerInput
On entry: the maximum number of steps to carry out in the model fitting process.
If ${\mathbf{mtype}}=\mathrm{Nag_LARS_LAR}$, the maximum number of steps the algorithm will take is $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,n\right)$ if ${\mathbf{intcpt}}=\mathrm{Nag_LARS_None}$, otherwise $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(p,n-1\right)$.
If ${\mathbf{mtype}}=\mathrm{Nag_LARS_ForwardStagewise}$, 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}}=\mathrm{Nag_LARS_LASSO}$ or $\mathrm{Nag_LARS_PositiveLASSO}$, 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:  $\mathbf{ip}$Integer *Output
On exit: $p$, number of parameter estimates.
If isx is NULL, $p={\mathbf{m}}$, i.e., the number of variables in dtd.
Otherwise $p$ is the number of nonzero values in isx.
13:  $\mathbf{nstep}$Integer *Output
On exit: $K$, the actual number of steps carried out in the model fitting process.
14:  $\mathbf{b}\left[\mathit{dim}\right]$doubleOutput
Note: the dimension, dim, of the array b must be at least ${\mathbf{pdb}}×\left({\mathbf{mnstep}}+1\right)$.
On exit: $\beta$ the parameter estimates, with ${\mathbf{b}}\left[\left(k-1\right)×{\mathbf{pdb}}+j-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}}=\mathrm{Nag_LARS_Normalized}$ 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.
$\begin{array}{llll}\text{If ​}{\mathbf{pred}}=\mathrm{Nag_LARS_None}& {\mathbf{b}}\left[{\mathbf{nstep}}×{\mathbf{pdb}}+j-1\right]& =& 1\text{,}\\ \\ \text{if ​}{\mathbf{pred}}=\mathrm{Nag_LARS_Normalized}& {\mathbf{b}}\left[{\mathbf{nstep}}×{\mathbf{pdb}}+j-1\right]& =& 1/\sqrt{{x}_{j}^{\mathrm{T}}{x}_{j}}\text{,}\end{array}$
for $j=1,2,\dots p$.
15:  $\mathbf{pdb}$IntegerInput
On entry: the stride separating row elements in the two-dimensional data stored in the array b.
Constraint: ${\mathbf{pdb}}\ge p$, where $p$ is the number of parameter estimates as described in ip.
16:  $\mathbf{fitsum}\left[6×\left({\mathbf{mnstep}}+1\right)\right]$doubleOutput
On exit: summaries of the model fitting process. When $k=1,2,\dots ,{\mathbf{nstep}}$
${\mathbf{fitsum}}\left[\left(k-1\right)×6\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}}=\mathrm{Nag_LARS_Normalized}$, the scaled parameter estimates are used in the summation.
${\mathbf{fitsum}}\left[\left(k-1\right)×6+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[\left(k-1\right)×6+2\right]$
${\nu }_{k}$, approximate degrees of freedom for the $k$th step.
${\mathbf{fitsum}}\left[\left(k-1\right)×6+3\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[\left(k-1\right)×6+4\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[\left(k-1\right)×6+5\right]$
${\stackrel{^}{\gamma }}_{k}$, the step size used at step $k$.
${\mathbf{fitsum}}\left[{\mathbf{nstep}}×6\right]$
$0$.
${\mathbf{fitsum}}\left[{\mathbf{nstep}}×6+1\right]$
${\mathrm{RSS}}_{0}$, the residual sums of squares for the null model, where ${\mathrm{RSS}}_{0}={y}^{\mathrm{T}}y$.
${\mathbf{fitsum}}\left[{\mathbf{nstep}}×6+2\right]$
${\nu }_{0}$, the degrees of freedom for the null model, where ${\nu }_{0}=0$ if ${\mathbf{intcpt}}=\mathrm{Nag_LARS_None}$ and ${\nu }_{0}=1$ otherwise.
${\mathbf{fitsum}}\left[{\mathbf{nstep}}×6+3\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[{\mathbf{nstep}}×6+4\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{fail}}\mathbf{.}\mathbf{code}=$ NW_LIMIT_REACHED they may not be meaningful due to the estimate ${\sigma }^{2}$ not being based on the saturated model.
17:  $\mathbf{ropt}\left[{\mathbf{lropt}}\right]$const doubleInput
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 ${\mathbf{lropt}}, therefore setting ${\mathbf{lropt}}=0$ will use the default values for all optional arguments and ropt need not be set and may be NULL. 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}$ is used, where $\mathit{eps}$ is the machine precision returned by nag_machine_precision (X02AJC).
${\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$ then parameter estimates are rescaled before being returned. If set to $0$ then no rescaling is performed. This argument has no effect when ${\mathbf{pred}}=\mathrm{Nag_LARS_None}$.
Default is for the parameter estimates to be rescaled.
Constraints:
• ;
• .
18:  $\mathbf{lropt}$IntegerInput
On entry: length of the options array ropt.
Constraint: $0\le {\mathbf{lropt}}\le 3$.
19:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_ARRAY_SIZE
On entry, ${\mathbf{lropt}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{lropt}}\le 3$.
On entry, ${\mathbf{pdb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: if isx is NULL then ${\mathbf{pdb}}\ge$ or ${\mathbf{m}}$.
On entry, ${\mathbf{pdb}}=〈\mathit{\text{value}}〉$ and $p=〈\mathit{\text{value}}〉$.
Constraint: if isx is not NULL, ${\mathbf{pdb}}\ge p$.
On entry, ${\mathbf{pddtd}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$
Constraint: .
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
NE_INT_ARRAY
On entry, all values of isx are zero.
Constraint: at least one value of isx must be nonzero.
On entry, ${\mathbf{isx}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{isx}}\left[i\right]=0$ or $1$, for all $i$.
On entry, ${\mathbf{isx}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
Constraint: ${\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}}$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_MAX_STEP
On entry, ${\mathbf{mnstep}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mnstep}}\ge 1$.
NE_NEG_ELEMENT
On entry, ${\mathbf{dtd}}\left[〈\mathit{\text{value}}〉×{\mathbf{pddtd}}\right]=〈\mathit{\text{value}}〉$.
Constraint: diagonal elements of ${D}^{\mathrm{T}}D$ must be positive.
On entry, $i=〈\mathit{\text{value}}〉$ and ${\mathbf{dtd}}\left[\left(i-1\right)×{\mathbf{pddtd}}+i-1\right]=〈\mathit{\text{value}}〉$.
Constraint: diagonal elements of ${D}^{\mathrm{T}}D$ must be positive.
NE_NEG_SX
A negative value for the residual sums of squares was obtained. Check the values of dtd, dty and yty.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_REAL
On entry, ${\mathbf{yty}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{yty}}>0.0$.
NE_SYMM_MATRIX
The cross-product matrix supplied in dtd is not symmetric.
NW_LIMIT_REACHED
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, $\sigma$ and the ${C}_{p}$ statistics may not be meaningful.
NW_OVERFLOW_WARN
${\nu }_{K}=n$, therefore sigma has been set to a large value. Output is returned as documented.
${\sigma }^{2}$ is approximately zero and hence the ${C}_{p}$-type criterion cannot be calculated. All other output is returned as documented.
NW_POTENTIAL_PROBLEM
Degenerate model, no variables added and ${\mathbf{nstep}}=0$. Output is returned as documented.

## 7Accuracy

Not applicable.

The solution path to the LARS, LASSO and stagewise regression analysis is a continuous, piecewise linear. nag_lars_xtx (g02mbc) returns the parameter estimates at various points along this path. nag_lars_param (g02mcc) can be used to obtain estimates at different points along the path.
If you have the raw data values, that is $D$ and $y$, then nag_lars (g02mac) can be used instead of nag_lars_xtx (g02mbc).

## 9Example

This example performs a LARS on a simulated dataset with $20$ observations and $6$ independent variables.
The example uses nag_sum_sqs (g02buc) to get the cross-products of the augmented matrix $\left[D\phantom{\rule{0.5em}{0ex}}y\right]$. The first $m\left(m+1\right)/2$ elements of the (column packed) cross-products matrix returned therefore contain the elements of ${D}^{\mathrm{T}}D$, the next $m$ elements contain ${D}^{\mathrm{T}}y$ and the last element ${y}^{\mathrm{T}}y$.

### 9.1Program Text

Program Text (g02mbce.c)

### 9.2Program Data

Program Data (g02mbce.d)

### 9.3Program Results

Program Results (g02mbce.r)

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