NAG Library Function Document

1Purpose

nag_lars_param (g02mcc) calculates additional parameter estimates following Least Angle Regression (LARS), forward stagewise linear regression or Least Absolute Shrinkage and Selection Operator (LASSO) as performed by nag_lars (g02mac) and nag_lars_xtx (g02mbc).

2Specification

 #include #include
 void nag_lars_param (Integer nstep, Integer ip, const double b[], Integer pdb, const double fitsum[], Nag_LARSTargetType ktype, const double nk[], Integer lnk, double nb[], Integer pdnb, NagError *fail)

3Description

nag_lars (g02mac) and nag_lars_xtx (g02mbc) 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 nag_lars (g02mac) and nag_lars_xtx (g02mbc) 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.
nag_lars_param (g02mcc) 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.
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}$IntegerInput
On entry: $K$, the number of steps carried out in the model fitting process, as returned by nag_lars (g02mac) and nag_lars_xtx (g02mbc).
Constraint: ${\mathbf{nstep}}\ge 0$.
2:    $\mathbf{ip}$IntegerInput
On entry: $p$, number of parameter estimates, as returned by nag_lars (g02mac) and nag_lars_xtx (g02mbc).
Constraint: ${\mathbf{ip}}\ge 1$.
3:    $\mathbf{b}\left[\mathit{dim}\right]$const doubleInput
Note: the dimension, dim, of the array b must be at least ${\mathbf{pdb}}×\left({\mathbf{nstep}}+1\right)$.
On entry: $\beta$ the parameter estimates, as returned by nag_lars (g02mac) and nag_lars_xtx (g02mbc), with ${\mathbf{b}}\left[\left(k-1\right)×{\mathbf{pdb}}+\mathit{j}-1\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 nag_lars (g02mac) or nag_lars_xtx (g02mbc).
4:    $\mathbf{pdb}$IntegerInput
On entry: the stride separating row elements in the two-dimensional data stored in the array b.
Constraint: ${\mathbf{pdb}}\ge {\mathbf{ip}}$.
5:    $\mathbf{fitsum}\left[6×\left({\mathbf{nstep}}+1\right)\right]$const doubleInput
On entry: summaries of the model fitting process, as returned by nag_lars (g02mac) and nag_lars_xtx (g02mbc).
Constraint: fitsum should be unchanged since the last call to nag_lars (g02mac) or nag_lars_xtx (g02mbc)..
6:    $\mathbf{ktype}$Nag_LARSTargetTypeInput
On entry: indicates what target values are held in nk.
${\mathbf{ktype}}=\mathrm{Nag_LARS_StepNumber}$
nk holds (fractional) LARS step numbers.
${\mathbf{ktype}}=\mathrm{Nag_LARS_ScaledNorm}$
nk holds values for ${L}_{1}$ norm of the (scaled) parameters.
${\mathbf{ktype}}=\mathrm{Nag_LARS_ProportionScaledNorm}$
nk holds ratios with respect to the largest (scaled) ${L}_{1}$ norm.
${\mathbf{ktype}}=\mathrm{Nag_LARS_UnscaledNorm}$
nk holds values for the ${L}_{1}$ norm of the (unscaled) parameters.
${\mathbf{ktype}}=\mathrm{Nag_LARS_ProportionUnscaledNorm}$
nk holds ratios with respect to the largest (unscaled) ${L}_{1}$ norm.
If nag_lars (g02mac) was called with ${\mathbf{pred}}=\mathrm{Nag_LARS_None}$ or $\mathrm{Nag_LARS_Centered}$ or nag_lars_xtx (g02mbc) was called with ${\mathbf{pred}}=\mathrm{Nag_LARS_None}$ 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}}=\mathrm{Nag_LARS_ScaledNorm}$ or $\mathrm{Nag_LARS_ProportionScaledNorm}$ and ${\mathbf{ktype}}=\mathrm{Nag_LARS_UnscaledNorm}$ or $\mathrm{Nag_LARS_ProportionUnscaledNorm}$.
Constraint: ${\mathbf{ktype}}=\mathrm{Nag_LARS_StepNumber}$, $\mathrm{Nag_LARS_ScaledNorm}$, $\mathrm{Nag_LARS_ProportionScaledNorm}$, $\mathrm{Nag_LARS_UnscaledNorm}$ or $\mathrm{Nag_LARS_ProportionUnscaledNorm}$.
7:    $\mathbf{nk}\left[{\mathbf{lnk}}\right]$const doubleInput
On entry: target values used for predicting the new set of parameter estimates.
Constraints:
• if ${\mathbf{ktype}}=\mathrm{Nag_LARS_StepNumber}$, $0\le {\mathbf{nk}}\left[\mathit{i}-1\right]\le {\mathbf{nstep}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{lnk}}$;
• if ${\mathbf{ktype}}=\mathrm{Nag_LARS_ScaledNorm}$, $0\le {\mathbf{nk}}\left[\mathit{i}-1\right]\le {\mathbf{fitsum}}\left[\left({\mathbf{nstep}}-1\right)×6\right]$, for $\mathit{i}=1,2,\dots ,{\mathbf{lnk}}$;
• if ${\mathbf{ktype}}=\mathrm{Nag_LARS_ProportionScaledNorm}$ or $\mathrm{Nag_LARS_ProportionUnscaledNorm}$, $0\le {\mathbf{nk}}\left[\mathit{i}-1\right]\le 1$, for $\mathit{i}=1,2,\dots ,{\mathbf{lnk}}$;
• if ${\mathbf{ktype}}=\mathrm{Nag_LARS_UnscaledNorm}$, $0\le {\mathbf{nk}}\left[\mathit{i}-1\right]\le {‖{\beta }_{K}‖}_{1}$, for $\mathit{i}=1,2,\dots ,{\mathbf{lnk}}$.
8:    $\mathbf{lnk}$IntegerInput
On entry: number of values supplied in nk.
Constraint: ${\mathbf{lnk}}\ge 1$.
9:    $\mathbf{nb}\left[\mathit{dim}\right]$doubleOutput
Note: the dimension, dim, of the array nb must be at least ${\mathbf{pdnb}}×{\mathbf{lnk}}$.
On exit: $\stackrel{~}{\beta }$ the predicted parameter estimates, with ${\mathbf{b}}\left[\left(i-1\right)×{\mathbf{pdb}}+j-1\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-1\right]$, $i=1,2,\dots ,{\mathbf{lnk}}$.
10:  $\mathbf{pdnb}$IntegerInput
On entry: the stride separating row elements in the two-dimensional data stored in the array nb.
Constraint: ${\mathbf{pdnb}}\ge {\mathbf{ip}}$.
11:  $\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{pdb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ip}}=〈\mathit{\text{value}}〉$
Constraint: ${\mathbf{pdb}}\ge {\mathbf{ip}}$.
On entry, ${\mathbf{pdnb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdnb}}\ge {\mathbf{ip}}$.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{ip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ip}}\ge 1$.
On entry, ${\mathbf{lnk}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lnk}}\ge 1$.
On entry, ${\mathbf{nstep}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nstep}}\ge 0$.
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_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_OUT_OF_RANGE
On entry, ${\mathbf{ktype}}=\mathrm{Nag_LARS_ProportionScaledNorm}$ or $\mathrm{Nag_LARS_ProportionUnscaledNorm}$, ${\mathbf{nk}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{nk}}\left[i\right]\le 1$ for all $i$.
On entry, ${\mathbf{ktype}}=\mathrm{Nag_LARS_ScaledNorm}$, ${\mathbf{nk}}\left[〈\mathit{\text{value}}〉\right]=〈\mathit{\text{value}}〉$, ${\mathbf{nstep}}=〈\mathit{\text{value}}〉$ and ${\mathbf{fitsum}}\left[\left({\mathbf{nstep}}-1\right)×6\right]=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{nk}}\left[i\right]\le {\mathbf{fitsum}}\left[\left({\mathbf{nstep}}-1\right)×6\right]$ for all $i$.
On entry, ${\mathbf{ktype}}=\mathrm{Nag_LARS_StepNumber}$, ${\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$.
On entry, ${\mathbf{ktype}}=\mathrm{Nag_LARS_UnscaledNorm}$, ${\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$.
NE_REAL_ARRAY
b has been corrupted since the last call to nag_lars (g02mac) or nag_lars_xtx (g02mbc).
fitsum has been corrupted since the last call to nag_lars (g02mac) or nag_lars_xtx (g02mbc).

Not applicable.

None.

9Example

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$.

9.1Program Text

Program Text (g02mcce.c)

9.2Program Data

Program Data (g02mcce.d)

9.3Program Results

Program Results (g02mcce.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017