G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02MCF

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

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.

## 2  Specification

 SUBROUTINE G02MCF ( NSTEP, IP, B, LDB, FITSUM, KTYPE, NK, LNK, NB, LDNB, IFAIL)
 INTEGER NSTEP, IP, LDB, KTYPE, LNK, LDNB, IFAIL REAL (KIND=nag_wp) B(LDB,*), FITSUM(6,NSTEP+1), NK(LNK), NB(LDNB,*)

## 3  Description

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.

## 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{NSTEP}$ – INTEGERInput
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:     $\mathrm{IP}$ – INTEGERInput
On entry: $p$, number of parameter estimates, as returned by G02MAF and G02MBF.
Constraint: ${\mathbf{IP}}\ge 1$.
3:     $\mathrm{B}\left({\mathbf{LDB}},*\right)$ – REAL (KIND=nag_wp) arrayInput
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:     $\mathrm{LDB}$ – INTEGERInput
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:     $\mathrm{FITSUM}\left(6,{\mathbf{NSTEP}}+1\right)$ – REAL (KIND=nag_wp) arrayInput
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:     $\mathrm{KTYPE}$ – INTEGERInput
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:     $\mathrm{NK}\left({\mathbf{LNK}}\right)$ – REAL (KIND=nag_wp) arrayInput
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:     $\mathrm{LNK}$ – INTEGERInput
On entry: number of values supplied in NK.
Constraint: ${\mathbf{LNK}}\ge 1$.
9:     $\mathrm{NB}\left({\mathbf{LDNB}},*\right)$ – REAL (KIND=nag_wp) arrayOutput
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:   $\mathrm{LDNB}$ – INTEGERInput
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:   $\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: G02MCF 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{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 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

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.

## 10  Example

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.1  Program Text

Program Text (g02mcfe.f90)

### 10.2  Program Data

Program Data (g02mcfe.d)

### 10.3  Program Results

Program Results (g02mcfe.r)