# NAG FL Interfaceg02mcf (lars_​param)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g02mcf calculates additional parameter estimates following Least Angle Regression (LARS), forward stagewise linear regression or Least Absolute Shrinkage and Selection Operator (LASSO) as performed by g02maf and g02mbf.

## 2Specification

Fortran Interface
 Subroutine g02mcf ( ip, b, ldb, nk, lnk, nb, ldnb,
 Integer, Intent (In) :: nstep, ip, ldb, ktype, lnk, ldnb Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: b(ldb,*), fitsum(6,nstep+1), nk(lnk) Real (Kind=nag_wp), Intent (Inout) :: nb(ldnb,*)
#include <nag.h>
 void g02mcf_ (const Integer *nstep, const Integer *ip, const double b[], const Integer *ldb, const double fitsum[], const Integer *ktype, const double nk[], const Integer *lnk, double nb[], const Integer *ldnb, Integer *ifail)
The routine may be called by the names g02mcf or nagf_correg_lars_param.

## 3Description

g02maf and g02mbf fit either a LARS, forward stagewise linear regression, LASSO or positive LASSO model to 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$ is given by the $j$th independent variable ${x}_{j}$. The models are fit using the LARS algorithm of Efron et al. (2004).
Figure 1
The full solution path for all four of these models follow a similar pattern where the parameter estimate for a given variable is piecewise linear. One such path, for a LARS model with six variables $\left(p=6\right)$ can be seen in Figure 1. Both g02maf and g02mbf return the vector of $p$ parameter estimates, ${\beta }_{k}$, at $K$ points along this path (so $k=1,2,\dots ,K$). Each point corresponds to a step of the LARS algorithm. The number of steps taken depends on the model being fitted. In the case of a LARS model, $K=p$ and each step corresponds to a new variable being included in the model. In the case of the LASSO models, each step corresponds to either a new variable being included in the model or an existing variable being removed from the model; the value of $K$ is, therefore, no longer bound by the number of parameters. For forward stagewise linear regression, each step no longer corresponds to the addition or removal of a variable;, therefore, the number of possible steps is often markedly greater than for a corresponding LASSO model.
g02mcf uses the piecewise linear nature of the solution path to predict the parameter estimates, $\stackrel{~}{\beta }$, at a different point on this path. The location of the solution can either be defined in terms of a (fractional) step number or a function of the ${L}_{1}$ norm of the parameter estimates.

## 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{nstep}$Integer Input
On entry: $K$, the number of steps carried out in the model fitting process, as returned by g02maf and g02mbf.
Constraint: ${\mathbf{nstep}}\ge 0$.
2: $\mathbf{ip}$Integer Input
On entry: $p$, number of parameter estimates, as returned by g02maf and g02mbf.
Constraint: ${\mathbf{ip}}\ge 1$.
3: $\mathbf{b}\left({\mathbf{ldb}},*\right)$Real (Kind=nag_wp) array Input
Note: the second dimension of the array b must be at least ${\mathbf{nstep}}+1$.
On entry: $\beta$ the parameter estimates, as returned by g02maf and g02mbf, with ${\mathbf{b}}\left(\mathit{j},k\right)={\beta }_{k\mathit{j}}$, the parameter estimate for the $\mathit{j}$th variable, for $\mathit{j}=1,2,\dots ,p$, at the $k$th step of the model fitting process.
Constraint: b should be unchanged since the last call to g02maf or g02mbf.
4: $\mathbf{ldb}$Integer Input
On entry: the first dimension of the array b as declared in the (sub)program from which g02mcf is called.
Constraint: ${\mathbf{ldb}}\ge {\mathbf{ip}}$.
5: $\mathbf{fitsum}\left(6,{\mathbf{nstep}}+1\right)$Real (Kind=nag_wp) array Input
On entry: summaries of the model fitting process, as returned by g02maf and g02mbf.
Constraint: fitsum should be unchanged since the last call to g02maf or g02mbf..
6: $\mathbf{ktype}$Integer Input
On entry: indicates what target values are held in nk.
${\mathbf{ktype}}=1$
nk holds (fractional) LARS step numbers.
${\mathbf{ktype}}=2$
nk holds values for ${L}_{1}$ norm of the (scaled) parameters.
${\mathbf{ktype}}=3$
nk holds ratios with respect to the largest (scaled) ${L}_{1}$ norm.
${\mathbf{ktype}}=4$
nk holds values for the ${L}_{1}$ norm of the (unscaled) parameters.
${\mathbf{ktype}}=5$
nk holds ratios with respect to the largest (unscaled) ${L}_{1}$ norm.
If g02maf was called with ${\mathbf{pred}}=0$ or $1$ or g02mbf was called with ${\mathbf{pred}}=0$ then the model fitting routine did not rescale the independent variables, $X$, prior to fitting the model and, therefore, there is no difference between ${\mathbf{ktype}}=2$ or $3$ and ${\mathbf{ktype}}=4$ or $5$.
Constraint: ${\mathbf{ktype}}=1$, $2$, $3$, $4$ or $5$.
7: $\mathbf{nk}\left({\mathbf{lnk}}\right)$Real (Kind=nag_wp) array Input
On entry: target values used for predicting the new set of parameter estimates.
Constraints:
• if ${\mathbf{ktype}}=1$, $0\le {\mathbf{nk}}\left(\mathit{i}\right)\le {\mathbf{nstep}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{lnk}}$;
• if ${\mathbf{ktype}}=2$, $0\le {\mathbf{nk}}\left(\mathit{i}\right)\le {\mathbf{fitsum}}\left(1,{\mathbf{nstep}}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{lnk}}$;
• if ${\mathbf{ktype}}=3$ or $5$, $0\le {\mathbf{nk}}\left(\mathit{i}\right)\le 1$, for $\mathit{i}=1,2,\dots ,{\mathbf{lnk}}$;
• if ${\mathbf{ktype}}=4$, $0\le {\mathbf{nk}}\left(\mathit{i}\right)\le {‖{\beta }_{K}‖}_{1}$, for $\mathit{i}=1,2,\dots ,{\mathbf{lnk}}$.
8: $\mathbf{lnk}$Integer Input
On entry: number of values supplied in nk.
Constraint: ${\mathbf{lnk}}\ge 1$.
9: $\mathbf{nb}\left({\mathbf{ldnb}},*\right)$Real (Kind=nag_wp) array Output
Note: the second dimension of the array nb must be at least ${\mathbf{lnk}}$.
On exit: $\stackrel{~}{\beta }$ the predicted parameter estimates, with ${\mathbf{b}}\left(j,i\right)={\stackrel{~}{\beta }}_{ij}$, the parameter estimate for variable $j$, $j=1,2,\dots ,p$ at the point in the fitting process associated with ${\mathbf{nk}}\left(i\right)$, $i=1,2,\dots ,{\mathbf{lnk}}$.
10: $\mathbf{ldnb}$Integer Input
On entry: the first dimension of the array nb as declared in the (sub)program from which g02mcf is called.
Constraint: ${\mathbf{ldnb}}\ge {\mathbf{ip}}$.
11: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $-1$ is recommended since useful values can be provided in some output arguments even when ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit. When the value $-\mathbf{1}$ or $\mathbf{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).

## 6Error 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).
Errors or warnings detected by the routine:
Note: in some cases g02mcf may return useful information.
${\mathbf{ifail}}=11$
On entry, ${\mathbf{nstep}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nstep}}\ge 0$.
${\mathbf{ifail}}=21$
On entry, ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ip}}\ge 1$.
${\mathbf{ifail}}=31$
b has been corrupted since the last call to g02maf or g02mbf.
${\mathbf{ifail}}=41$
On entry, ${\mathbf{ldb}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$
Constraint: ${\mathbf{ldb}}\ge {\mathbf{ip}}$.
${\mathbf{ifail}}=51$
fitsum has been corrupted since the last call to g02maf or g02mbf.
${\mathbf{ifail}}=61$
On entry, ${\mathbf{ktype}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ktype}}=1$, $2$, $3$, $4$ or $5$.
${\mathbf{ifail}}=71$
On entry, ${\mathbf{ktype}}=1$, ${\mathbf{nk}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{nstep}}=⟨\mathit{\text{value}}⟩$
Constraint: $0\le {\mathbf{nk}}\left(i\right)\le {\mathbf{nstep}}$, for all $i$.
${\mathbf{ifail}}=72$
On entry, ${\mathbf{ktype}}=2$, ${\mathbf{nk}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$, ${\mathbf{nstep}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{fitsum}}\left(1,{\mathbf{nstep}}\right)=⟨\mathit{\text{value}}⟩$.
Constraint: $0\le {\mathbf{nk}}\left(i\right)\le {\mathbf{fitsum}}\left(1,{\mathbf{nstep}}\right)$, for all $i$.
${\mathbf{ifail}}=73$
On entry, ${\mathbf{ktype}}=3$ or $5$, ${\mathbf{nk}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$.
Constraint: $0\le {\mathbf{nk}}\left(i\right)\le 1$, for all $i$.
${\mathbf{ifail}}=74$
On entry, ${\mathbf{ktype}}=4$, ${\mathbf{nk}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$ and ${‖{\beta }_{K}‖}_{1}=⟨\mathit{\text{value}}⟩$
Constraint: $0\le {\mathbf{nk}}\left(i\right)\le {‖{\beta }_{K}‖}_{1}$, for all $i$.
${\mathbf{ifail}}=81$
On entry, ${\mathbf{lnk}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lnk}}\ge 1$.
${\mathbf{ifail}}=101$
On entry, ${\mathbf{ldnb}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldnb}}\ge {\mathbf{ip}}$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

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

None.

## 10Example

This example performs a LARS on a set a simulated dataset with $20$ observations and $6$ independent variables.
Additional parameter estimates are obtained corresponding to a LARS step number of $0.2,1.2,3.2,4.5$ and $5.2$. Where, for example, $4.5$ corresponds to the solution halfway between that obtained at step $4$ and that obtained at step $5$.

### 10.1Program Text

Program Text (g02mcfe.f90)

### 10.2Program Data

Program Data (g02mcfe.d)

### 10.3Program Results

Program Results (g02mcfe.r)