Title: | Least Angle Regression, Lasso and Forward Stagewise |
---|---|
Description: | Efficient procedures for fitting an entire lasso sequence with the cost of a single least squares fit. Least angle regression and infinitesimal forward stagewise regression are related to the lasso, as described in the paper below. |
Authors: | Trevor Hastie <[email protected]> and Brad Efron <[email protected]> |
Maintainer: | Trevor Hastie <[email protected]> |
License: | GPL-2 |
Version: | 1.3 |
Built: | 2024-11-08 06:27:07 UTC |
Source: | CRAN |
Computes the K-fold cross-validated mean squared prediction error for lars, lasso, or forward stagewise.
cv.lars(x, y, K = 10, index, trace = FALSE, plot.it = TRUE, se = TRUE, type = c("lasso", "lar", "forward.stagewise", "stepwise"), mode=c("fraction", "step"), ...)
cv.lars(x, y, K = 10, index, trace = FALSE, plot.it = TRUE, se = TRUE, type = c("lasso", "lar", "forward.stagewise", "stepwise"), mode=c("fraction", "step"), ...)
x |
Input to lars |
y |
Input to lars |
K |
Number of folds |
index |
Abscissa values at which CV curve should be computed.
If |
trace |
Show computations? |
plot.it |
Plot it? |
se |
Include standard error bands? |
type |
type of |
mode |
This refers to the index that is used for
cross-validation. The default is |
... |
Additional arguments to |
Invisibly returns a list with components (which can be plotted using plotCVlars
)
index |
As above |
cv |
The CV curve at each value of index |
cv.error |
The standard error of the CV curve |
mode |
As above |
Trevor Hastie
Efron, Hastie, Johnstone and Tibshirani (2003) "Least Angle Regression" (with discussion) Annals of Statistics; see also https://hastie.su.domains/Papers/LARS/LeastAngle_2002.pdf.
data(diabetes) attach(diabetes) cv.lars(x2,y,trace=TRUE,max.steps=80) detach(diabetes)
data(diabetes) attach(diabetes) cv.lars(x2,y,trace=TRUE,max.steps=80) detach(diabetes)
The diabetes
data frame has 442 rows and 3 columns.
These are the data used in the Efron et al "Least Angle Regression" paper.
This data frame contains the following columns:
a matrix with 10 columns
a numeric vector
a matrix with 64 columns
The x matrix has been standardized to have unit L2 norm in each column and zero mean. The matrix x2 consists of x plus certain interactions.
https://hastie.su.domains/Papers/LARS/LeastAngle_2002.pdf
Efron, Hastie, Johnstone and Tibshirani (2003) "Least Angle Regression" (with discussion) Annals of Statistics
These are all variants of Lasso, and provide the entire sequence of coefficients and fits, starting from zero, to the least squares fit.
lars(x, y, type = c("lasso", "lar", "forward.stagewise", "stepwise"), trace = FALSE, normalize = TRUE, intercept = TRUE, Gram, eps = 1e-12, max.steps, use.Gram = TRUE)
lars(x, y, type = c("lasso", "lar", "forward.stagewise", "stepwise"), trace = FALSE, normalize = TRUE, intercept = TRUE, Gram, eps = 1e-12, max.steps, use.Gram = TRUE)
x |
matrix of predictors |
y |
response |
type |
One of "lasso", "lar", "forward.stagewise" or "stepwise". The names can be abbreviated to any unique substring. Default is "lasso". |
trace |
If TRUE, lars prints out its progress |
normalize |
If TRUE, each variable is standardized to have unit L2 norm, otherwise it is left alone. Default is TRUE. |
intercept |
if TRUE, an intercept is included in the model (and not penalized), otherwise no intercept is included. Default is TRUE. |
Gram |
The X'X matrix; useful for repeated runs (bootstrap) where a large X'X stays the same. |
eps |
An effective zero, with default |
max.steps |
Limit the number of steps taken; the default is |
use.Gram |
When the number m of variables is very large, i.e. larger than N, then
you may not want LARS to precompute the Gram matrix. Default is
|
LARS is described in detail in Efron, Hastie, Johnstone and Tibshirani (2002). With the "lasso" option, it computes the complete lasso solution simultaneously for ALL values of the shrinkage parameter in the same computational cost as a least squares fit. A "stepwise" option has recently been added to LARS.
A "lars" object is returned, for which print, plot, predict, coef and summary methods exist.
Brad Efron and Trevor Hastie
Efron, Hastie, Johnstone and Tibshirani (2003) "Least Angle Regression" (with discussion) Annals of Statistics doi:10.1214/009053604000000067; see also https://hastie.su.domains/Papers/LARS/LeastAngle_2002.pdf. Hastie, Tibshirani and Friedman (2002) Elements of Statistical Learning, Springer, NY.
print, plot, summary and predict methods for lars, and cv.lars
data(diabetes) par(mfrow=c(2,2)) attach(diabetes) object <- lars(x,y) plot(object) object2 <- lars(x,y,type="lar") plot(object2) object3 <- lars(x,y,type="for") # Can use abbreviations plot(object3) detach(diabetes)
data(diabetes) par(mfrow=c(2,2)) attach(diabetes) object <- lars(x,y) plot(object) object2 <- lars(x,y,type="lar") plot(object2) object3 <- lars(x,y,type="for") # Can use abbreviations plot(object3) detach(diabetes)
Produce a plot of a lars fit. The default is a complete coefficient path.
## S3 method for class 'lars' plot(x, xvar= c("norm", "df", "arc.length", "step"), breaks = TRUE, plottype = c("coefficients", "Cp"), omit.zeros = TRUE, eps = 1e-10, ...)
## S3 method for class 'lars' plot(x, xvar= c("norm", "df", "arc.length", "step"), breaks = TRUE, plottype = c("coefficients", "Cp"), omit.zeros = TRUE, eps = 1e-10, ...)
x |
lars object |
xvar |
The type of x variable against which to
plot. |
breaks |
If |
plottype |
Either |
omit.zeros |
When the number of variables is much greater than
the number of observations, many coefficients will never be nonzero;
this logical (default |
eps |
Definition of zero above, default is |
... |
Additonal arguments for generic plot. Can be used to set xlims, change colors, line widths, etc |
The default plot uses the fraction of L1 norm as the xvar. For forward stagewise and LAR, coefficients can pass through zero during a step, which causes a change of slope of L1 norm vs arc-length. Since the coefficients are piecewise linear in arc-length between each step, this causes a change in slope of the coefficients.
NULL
Trevor Hastie
Efron, Hastie, Johnstone and Tibshirani (2003) "Least Angle Regression" (with discussion) Annals of Statistics; see also https://hastie.su.domains/Papers/LARS/LeastAngle_2002.pdf. Yann-Ael Le Borgne (private communication) pointed out the problems in plotting forward stagewise and LAR coefficients against L1 norm, and the solution we have implemented.
data(diabetes) attach(diabetes) object <- lars(x,y) plot(object) detach(diabetes)
data(diabetes) attach(diabetes) object <- lars(x,y) plot(object) detach(diabetes)
While lars() produces the entire path of solutions, predict.lars allows one to extract a prediction at a particular point along the path.
## S3 method for class 'lars' predict(object, newx, s, type = c("fit", "coefficients"), mode = c("step", "fraction", "norm", "lambda"), ...) ## S3 method for class 'lars' coef(object, ...)
## S3 method for class 'lars' predict(object, newx, s, type = c("fit", "coefficients"), mode = c("step", "fraction", "norm", "lambda"), ...) ## S3 method for class 'lars' coef(object, ...)
object |
A fitted lars object |
newx |
If type="fit", then newx should be the x values at which the fit is required. If type="coefficients", then newx can be omitted. |
s |
a value, or vector of values, indexing the path. Its values depends on the mode= argument. By default (mode="step"), s should take on values between 0 and p (e.g., a step of 1.3 means .3 of the way between step 1 and 2.) |
type |
If type="fit", predict returns the fitted values. If type="coefficients", predict returns the coefficients. Abbreviations allowed. |
mode |
Mode="step" means the s= argument indexes the lars step number, and the coefficients will be returned corresponding to the values corresponding to step s. If mode="fraction", then s should be a number between 0 and 1, and it refers to the ratio of the L1 norm of the coefficient vector, relative to the norm at the full LS solution. Mode="norm" means s refers to the L1 norm of the coefficient vector. Mode="lambda" uses the lasso regularization parameter for s; for other models it is the maximal correlation (does not make sense for lars/stepwise models). Abbreviations allowed. |
... |
Any arguments for |
LARS is described in detail in Efron, Hastie, Johnstone and Tibshirani (2002). With the "lasso" option, it computes the complete lasso solution simultaneously for ALL values of the shrinkage parameter in the same computational cost as a least squares fit.
Either a vector/matrix of fitted values, or a vector/matrix of coefficients.
Trevor Hastie
Efron, Hastie, Johnstone and Tibshirani (2002) "Least Angle Regression" (with discussion) Annals of Statistics; see also doi:10.1214/009053604000000067. Hastie, Tibshirani and Friedman (2002) Elements of Statistical Learning, Springer, NY.
print, plot, lars, cv.lars
data(diabetes) attach(diabetes) object <- lars(x,y,type="lasso") ### make predictions at the values in x, at each of the ### steps produced in object fits <- predict.lars(object, x, type="fit") ### extract the coefficient vector with L1 norm=4.1 coef4.1 <- coef(object, s=4.1, mode="norm") # or coef4.1 <- predict(object, s=4.1, type="coef", mode="norm") detach(diabetes)
data(diabetes) attach(diabetes) object <- lars(x,y,type="lasso") ### make predictions at the values in x, at each of the ### steps produced in object fits <- predict.lars(object, x, type="fit") ### extract the coefficient vector with L1 norm=4.1 coef4.1 <- coef(object, s=4.1, mode="norm") # or coef4.1 <- predict(object, s=4.1, type="coef", mode="norm") detach(diabetes)
Produce an anova-type summary for a lars object.
## S3 method for class 'lars' summary(object, sigma2=NULL, ...)
## S3 method for class 'lars' summary(object, sigma2=NULL, ...)
object |
lars object |
sigma2 |
optional variance measure (for p>n) |
... |
Additional arguments for summary generic |
An anova summary is produced, with Df, RSS and Cp for each step. Df is tricky for some models, such as forward stagewise and stepwise, and is not likely to be accurate. When p>n, the user is responsible for supplying sigma2.
An anova object is returned, with rownames the step number, and with components:
Df |
Estimated degree of freedom |
Rss |
The Residual sum of Squares |
Cp |
The Cp statistic |
Brad Efron and Trevor Hastie
Efron, Hastie, Johnstone and Tibshirani (2003) "Least Angle Regression" (with discussion) Annals of Statistics; see also doi:10.1214/009053604000000067. Hastie, Tibshirani and Friedman (2002) Elements of Statistical Learning, Springer, NY.
lars, and print, plot,and predict methods for lars, and cv.lars
data(diabetes) attach(diabetes) object <- lars(x,y) summary(object) detach(diabetes)
data(diabetes) attach(diabetes) object <- lars(x,y) summary(object) detach(diabetes)