Title: | Penalized Quantile Regression |
---|---|
Description: | Performs penalized quantile regression with LASSO, elastic net, SCAD and MCP penalty functions including group penalties. In addition, offers a group penalty that provides consistent variable selection across quantiles. Provides a function that automatically generates lambdas and evaluates different models with cross validation or BIC, including a large p version of BIC. Below URL provides a link to a work in progress vignette. |
Authors: | Ben Sherwood [aut, cre], Shaobo Li [aut], Adam Maidman [aut] |
Maintainer: | Ben Sherwood <[email protected]> |
License: | MIT + file LICENSE |
Version: | 4.1.2 |
Built: | 2024-10-30 09:26:38 UTC |
Source: | CRAN |
Plot of how coefficients change with tau
bytau.plot(x, ...)
bytau.plot(x, ...)
x |
A rq.pen.seq or rq.pen.seq.cv object. |
... |
Additional arguments see bytau.plot.rq.pen.seq() or bytau.plot.rq.pen.seq.cv() for more information. |
Returns the plot of how coefficients change with tau.
Ben Sherwood, [email protected]
Plot of how coefficients change with tau.
## S3 method for class 'rq.pen.seq' bytau.plot(x, a = NULL, lambda = NULL, lambdaIndex = NULL, vars = NULL, ...)
## S3 method for class 'rq.pen.seq' bytau.plot(x, a = NULL, lambda = NULL, lambdaIndex = NULL, vars = NULL, ...)
x |
An rq.pen.seq object |
a |
The tuning parameter a of interest |
lambda |
The lambda value of interest. |
lambdaIndex |
The lambda index of interest. Only specify lambdaIndex or lambda, not both. |
vars |
Index of the variables to plot with 1 being the intercept, 2 being the first predictor, etc. Default is to include all variables. |
... |
Additional parameters sent to coef() |
A plot of coefficient values by tau.
Ben Sherwood, [email protected]
set.seed(1) x <- matrix(rnorm(800),nrow=100) y <- 1 + x[,1] - 3*x[,5] + rnorm(100) lassoModels <- rq.pen(x,y,tau=seq(.1,.9,.1)) bytau.plot(lassoModels,lambda=lassoModels$lambda[5])
set.seed(1) x <- matrix(rnorm(800),nrow=100) y <- 1 + x[,1] - 3*x[,5] + rnorm(100) lassoModels <- rq.pen(x,y,tau=seq(.1,.9,.1)) bytau.plot(lassoModels,lambda=lassoModels$lambda[5])
Produces plots of how coefficient estimates vary by quantile for models selected by using cross validation.
## S3 method for class 'rq.pen.seq.cv' bytau.plot( x, septau = ifelse(x$fit$penalty != "gq", TRUE, FALSE), cvmin = TRUE, useDefaults = TRUE, vars = NULL, ... )
## S3 method for class 'rq.pen.seq.cv' bytau.plot( x, septau = ifelse(x$fit$penalty != "gq", TRUE, FALSE), cvmin = TRUE, useDefaults = TRUE, vars = NULL, ... )
x |
An rq.pen.seq.cv object |
septau |
Whether optimal tuning parameters are estimated separately for each quantile. |
cvmin |
Whether the minimum cv error should be used or the one standard error rule. |
useDefaults |
Set to FALSE if you want to use something besides minimum cv or 1se. |
vars |
Index of the variables to plot with 1 being the intercept, 2 being the first predictor, etc. Default is to include all variables. |
... |
Additional parameters sent to coef() |
Returns plots of coefficient estimates varying by quantile.
Ben Sherwood, [email protected]
set.seed(1) x <- matrix(runif(800),nrow=100) y <- 1 + x[,1] - 3*x[,5] + (1+x[,4])*rnorm(100) lmcv <- rq.pen.cv(x,y,tau=seq(.1,.9,.1)) bytau.plot(lmcv)
set.seed(1) x <- matrix(runif(800),nrow=100) y <- 1 + x[,1] - 3*x[,5] + (1+x[,4])*rnorm(100) lmcv <- rq.pen.cv(x,y,tau=seq(.1,.9,.1)) bytau.plot(lmcv)
Returns coefficients of a rq.pen.seq object
## S3 method for class 'rq.pen.seq' coef( object, tau = NULL, a = NULL, lambda = NULL, modelsIndex = NULL, lambdaIndex = NULL, ... )
## S3 method for class 'rq.pen.seq' coef( object, tau = NULL, a = NULL, lambda = NULL, modelsIndex = NULL, lambdaIndex = NULL, ... )
object |
rq.pen.seq object |
tau |
Quantile of interest. Default is NULL, which will return all quantiles. Should not be specified if modelsIndex is used. |
a |
Tuning parameter of a. Default is NULL, which returns coefficients for all values of a. Should not be specified if modelsIndex is used. |
lambda |
Tuning parameter of |
modelsIndex |
Index of the models for which coefficients should be returned. Does not need to be specified if tau or a are specified. |
lambdaIndex |
Index of the lambda values for which coefficients should be returned. Does not need to be specified if lambda is specified. |
... |
Additional parameters. |
A list of a matrix of coefficients for each tau and a combination
Ben Sherwood, [email protected]
x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75),lambda=c(.1,.05,.01)) allCoefs <- coef(m1) targetCoefs <- coef(m1,tau=.25,a=.5,lambda=.1) idxApproach <- coef(m1,modelsIndex=2) bothIdxApproach <- coef(m1,modelsIndex=2,lambdaIndex=1)
x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75),lambda=c(.1,.05,.01)) allCoefs <- coef(m1) targetCoefs <- coef(m1,tau=.25,a=.5,lambda=.1) idxApproach <- coef(m1,modelsIndex=2) bothIdxApproach <- coef(m1,modelsIndex=2,lambdaIndex=1)
Returns coefficients from a rq.pen.seq.cv object.
## S3 method for class 'rq.pen.seq.cv' coef( object, septau = ifelse(object$fit$penalty != "gq", TRUE, FALSE), cvmin = TRUE, useDefaults = TRUE, tau = NULL, ... )
## S3 method for class 'rq.pen.seq.cv' coef( object, septau = ifelse(object$fit$penalty != "gq", TRUE, FALSE), cvmin = TRUE, useDefaults = TRUE, tau = NULL, ... )
object |
An rq.pen.seq.cv object. |
septau |
Whether tuning parameter should be optimized separately for each quantile. |
cvmin |
If TRUE then minimum error is used, if FALSE then one standard error rule is used. |
useDefaults |
Whether the default results are used. Set to FALSE if you you want to specify specific models and lambda values. |
tau |
Quantiles of interest. |
... |
Additional parameters sent to coef.rq.pen.seq() |
Returns coefficients
Ben Sherwood, [email protected]
## Not run: set.seed(1) x <- matrix(rnorm(800),nrow=100) y <- 1 + x[,1] - 3*x[,5] + rnorm(100) lassoModels <- rq.pen.cv(x,y,tau=seq(.1,.9,.1)) coefficients(lassoModels,septau=FALSE) coefficients(lassoModels,cvmin=FALSE) ## End(Not run)
## Not run: set.seed(1) x <- matrix(rnorm(800),nrow=100) y <- 1 + x[,1] - 3*x[,5] + rnorm(100) lassoModels <- rq.pen.cv(x,y,tau=seq(.1,.9,.1)) coefficients(lassoModels,septau=FALSE) coefficients(lassoModels,cvmin=FALSE) ## End(Not run)
Plot of coefficients of rq.pen.seq object as a function of lambda
## S3 method for class 'rq.pen.seq' plot( x, vars = NULL, logLambda = TRUE, tau = NULL, a = NULL, lambda = NULL, modelsIndex = NULL, lambdaIndex = NULL, main = NULL, ... )
## S3 method for class 'rq.pen.seq' plot( x, vars = NULL, logLambda = TRUE, tau = NULL, a = NULL, lambda = NULL, modelsIndex = NULL, lambdaIndex = NULL, main = NULL, ... )
x |
rq.pen.seq object |
vars |
Variables of interest |
logLambda |
Whether lambda should be reported on the log scale |
tau |
Quantiles of interest |
a |
Tuning parameter a values of interest. |
lambda |
Values of lambda of interest. |
modelsIndex |
Specific models of interest. |
lambdaIndex |
Specific lambda values of interest. |
main |
Title of the plots. Can be a vector of multiple titles if multiple plots are created. |
... |
Additional arguments sent to plot |
Returns plot(s) of coefficients as they change with lambda.
Ben Sherwood, [email protected]
set.seed(1) x <- matrix(rnorm(100*8,sd=10),ncol=8) y <- 1 + x[,1] + 3*x[,3] - x[,8] + rt(100,3) m1 <- rq.pen(x,y,tau=c(.1,.5,.7),penalty="SCAD",a=c(3,4)) plot(m1,a=3,tau=.7) plot(m1) mlist <- list() for(i in 1:6){ mlist[[i]] <- paste("Plot",i) } plot(m1,main=mlist)
set.seed(1) x <- matrix(rnorm(100*8,sd=10),ncol=8) y <- 1 + x[,1] + 3*x[,3] - x[,8] + rt(100,3) m1 <- rq.pen(x,y,tau=c(.1,.5,.7),penalty="SCAD",a=c(3,4)) plot(m1,a=3,tau=.7) plot(m1) mlist <- list() for(i in 1:6){ mlist[[i]] <- paste("Plot",i) } plot(m1,main=mlist)
Provides plots of cross-validation results by lambda. If septau is set to TRUE then plots the cross-validation results for each quantile. If septau is set to FALSE then provides one plot for cross-validation results across all quantiles.
## S3 method for class 'rq.pen.seq.cv' plot( x, septau = ifelse(x$fit$penalty != "gq", TRUE, FALSE), tau = NULL, logLambda = TRUE, main = NULL, ... )
## S3 method for class 'rq.pen.seq.cv' plot( x, septau = ifelse(x$fit$penalty != "gq", TRUE, FALSE), tau = NULL, logLambda = TRUE, main = NULL, ... )
x |
The rq.pen.seq.cv object |
septau |
If set to true then optimal tuning parameters are selected seperately for each quantile and there will be a different plot for each quanitle. |
tau |
Quantiles of interest. |
logLambda |
Whether log(lambda) is used for the x-axis |
main |
Title to the plot |
... |
Additional parameters sent to the plot function. |
Plots of the cross validation results by lambda.
Ben Sherwood, [email protected]
set.seed(1) x <- matrix(rnorm(100*8,sd=1),ncol=8) y <- 1 + x[,1] + 3*x[,3] - x[,8] + rt(100,3) m1 <- rq.pen.cv(x,y,tau=c(.1,.3,.7)) plot(m1) plot(m1,septau=FALSE)
set.seed(1) x <- matrix(rnorm(100*8,sd=1),ncol=8) y <- 1 + x[,1] + 3*x[,3] - x[,8] + rt(100,3) m1 <- rq.pen.cv(x,y,tau=c(.1,.3,.7)) plot(m1) plot(m1,septau=FALSE)
Predictions from a qic.select object
## S3 method for class 'qic.select' predict(object, newx, sort = FALSE, ...)
## S3 method for class 'qic.select' predict(object, newx, sort = FALSE, ...)
object |
qic.select object |
newx |
Data matrix to make predictions from. |
sort |
If there are crossing quantiles the predictions will be sorted to avoid this issue. |
... |
No additional parameters are used but this is needed for how R handles predict functions. |
A matrix of predicted values.
Ben Sherwood, [email protected]
x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,tau=c(.25,.75)) q1 <- qic.select(m1) newx <- matrix(runif(80),ncol=8) preds <- predict(q1,newx)
x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,tau=c(.25,.75)) q1 <- qic.select(m1) newx <- matrix(runif(80),ncol=8) preds <- predict(q1,newx)
Predictions from rq.pen.seq object
## S3 method for class 'rq.pen.seq' predict( object, newx, tau = NULL, a = NULL, lambda = NULL, modelsIndex = NULL, lambdaIndex = NULL, sort = FALSE, ... )
## S3 method for class 'rq.pen.seq' predict( object, newx, tau = NULL, a = NULL, lambda = NULL, modelsIndex = NULL, lambdaIndex = NULL, sort = FALSE, ... )
object |
rq.pen.seq object |
newx |
Matrix of predictors |
tau |
Quantile of interest. Default is NULL, which will return all quantiles. Should not be specified if modelsIndex is used. |
a |
Tuning parameter of a. Default is NULL, which returns coefficients for all values of a. Should not be specified if modelsIndex is used. |
lambda |
Tuning parameter of |
modelsIndex |
Index of the models for which coefficients should be returned. Does not need to be specified if tau or a are specified. |
lambdaIndex |
Index of the lambda values for which coefficients should be returned. Does not need to be specified if lambda is specified. |
sort |
If there are crossing quantiles the predictions will be sorted to avoid this issue. |
... |
Additional parameters passed to coef.rq.pen.seq() |
A matrix of predictions for each tau and a combination
Ben Sherwood, [email protected]
x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75),lambda=c(.1,.05,.01)) newx <- matrix(runif(80),ncol=8) allCoefs <- predict(m1,newx) targetCoefs <- predict(m1,newx,tau=.25,a=.5,lambda=.1) idxApproach <- predict(m1,newx,modelsIndex=2) bothIdxApproach <- predict(m1,newx,modelsIndex=2,lambdaIndex=1)
x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75),lambda=c(.1,.05,.01)) newx <- matrix(runif(80),ncol=8) allCoefs <- predict(m1,newx) targetCoefs <- predict(m1,newx,tau=.25,a=.5,lambda=.1) idxApproach <- predict(m1,newx,modelsIndex=2) bothIdxApproach <- predict(m1,newx,modelsIndex=2,lambdaIndex=1)
Predictions from rq.pen.seq.cv object
## S3 method for class 'rq.pen.seq.cv' predict( object, newx, tau = NULL, septau = ifelse(object$fit$penalty != "gq", TRUE, FALSE), cvmin = TRUE, useDefaults = TRUE, sort = FALSE, lambda = NULL, lambdaIndex = NULL, ... )
## S3 method for class 'rq.pen.seq.cv' predict( object, newx, tau = NULL, septau = ifelse(object$fit$penalty != "gq", TRUE, FALSE), cvmin = TRUE, useDefaults = TRUE, sort = FALSE, lambda = NULL, lambdaIndex = NULL, ... )
object |
rq.pen.seq.cv object |
newx |
Matrix of predictors |
tau |
Quantile of interest. Default is NULL, which will return all quantiles. Should not be specified if modelsIndex is used. |
septau |
Whether tuning parameter should be optimized separately for each quantile. |
cvmin |
If TRUE then minimum error is used, if FALSE then one standard error rule is used. |
useDefaults |
Whether the default results are used. Set to FALSE if you you want to specify specific models and lambda values. |
sort |
If there are crossing quantiles the predictions will be sorted to avoid this issue. |
lambda |
The value of lambda for which predictions are wanted. Ignored unless useDefaults is set to false. |
lambdaIndex |
The indices for lambda for which predictions are wanted. Ignored unless useDefaults is set to false. |
... |
Additional parameters sent to coef.rq.pen.seq.cv(). |
A matrix of predictions for each tau and a combination
Ben Sherwood, [email protected]
x <- matrix(runif(1600),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(200) m1 <- rq.pen.cv(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75),lambda=c(.1,.05,.01)) newx <- matrix(runif(80),ncol=8) cvpreds <- predict(m1,newx)
x <- matrix(runif(1600),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(200) m1 <- rq.pen.cv(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75),lambda=c(.1,.05,.01)) newx <- matrix(runif(80),ncol=8) cvpreds <- predict(m1,newx)
Print a qic.select object
## S3 method for class 'qic.select' print(x, ...)
## S3 method for class 'qic.select' print(x, ...)
x |
qic.select object |
... |
optional arguments |
Prints the coefficients of the qic.select object
Ben Sherwood, [email protected]
Print a rq.pen.seq object
## S3 method for class 'rq.pen.seq' print(x, ...)
## S3 method for class 'rq.pen.seq' print(x, ...)
x |
rq.pen.seq object |
... |
optional arguments |
If only one model, prints a data.frame of the number of nonzero coefficients and lambda. Otherwise prints information about the quantiles being modeled and choices for a.
Ben Sherwood, [email protected]
Prints a rq.pen.seq.cv object
## S3 method for class 'rq.pen.seq.cv' print(x, ...)
## S3 method for class 'rq.pen.seq.cv' print(x, ...)
x |
A req.pen.seq.cv object. |
... |
Additional arguments. |
Print of btr and gtr from a rq.pen.seq.cv object. If only one quantile is modeled then only btr is returned.
Selects tuning parameter and a according to information criterion of choice. For a given
the information criterion is calculated
as
where d is the number of nonzero coefficients and b depends on the method used. For AIC ,
for BIC
and for PBIC
where p is the dimension of
.
If septau set to FALSE then calculations are made across the quantiles. Let
be the coefficient vector for the qth quantile of Q quantiles. In addition let
and
be d and b values from the qth quantile model. Note, for all of these we are assuming eqn and a are the same. Then the summary across all quantiles is
where is the weight assigned for the qth quantile model.
qic.select(obj, ...)
qic.select(obj, ...)
obj |
A rq.pen.seq or rq.pen.seq.cv object. |
... |
Additional arguments see qic.select.rq.pen.seq() or qic.select.rq.pen.seq.cv() for more information. |
Returns a qic.select object.
Ben Sherwood, [email protected]
Lee ER, Noh H, Park BU (2014). “Model Selection via Bayesian Information Criterion for Quantile Regression Models.” Journal of the American Statistical Association, 109(505), 216–229. ISSN 01621459.
set.seed(1) x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75)) qic.select(m1)
set.seed(1) x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75)) qic.select(m1)
Selects tuning parameter and a according to information criterion of choice. For a given
the information criterion is calculated
as
where d is the number of nonzero coefficients and b depends on the method used. For AIC ,
for BIC
and for PBIC
where p is the dimension of
.
If septau set to FALSE then calculations are made across the quantiles. Let
be the coefficient vector for the qth quantile of Q quantiles. In addition let
and
be d and b values from the qth quantile model. Note, for all of these we are assuming eqn and a are the same. Then the summary across all quantiles is
where is the weight assigned for the qth quantile model.
## S3 method for class 'rq.pen.seq' qic.select( obj, method = c("BIC", "AIC", "PBIC"), septau = ifelse(obj$penalty != "gq", TRUE, FALSE), tauWeights = NULL, ... )
## S3 method for class 'rq.pen.seq' qic.select( obj, method = c("BIC", "AIC", "PBIC"), septau = ifelse(obj$penalty != "gq", TRUE, FALSE), tauWeights = NULL, ... )
obj |
A rq.pen.seq or rq.pen.seq.cv object. |
method |
Choice of BIC, AIC or PBIC, a large p BIC. |
septau |
If optimal values of |
tauWeights |
Weights for each quantile. Useful if you set septau to FALSE but want different weights for the different quantiles. If not specified default is to have |
... |
Additional arguments. |
Coefficients of the selected models.
Information criterion values for all considered models.
Model info for the selected models related to the original object obj.
Information criterion summarized across all quantiles. Only returned if septau set to FALSE
Ben Sherwood, [email protected]
Lee ER, Noh H, Park BU (2014). “Model Selection via Bayesian Information Criterion for Quantile Regression Models.” Journal of the American Statistical Association, 109(505), 216–229. ISSN 01621459.
set.seed(1) x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75)) qic.select(m1)
set.seed(1) x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75)) qic.select(m1)
Selects tuning parameter and a according to information criterion of choice. For a given
the information criterion is calculated
as
where d is the number of nonzero coefficients and b depends on the method used. For AIC ,
for BIC
and for PBIC
where p is the dimension of
.
If septau set to FALSE then calculations are made across the quantiles. Let
be the coefficient vector for the qth quantile of Q quantiles. In addition let
and
be d and b values from the qth quantile model. Note, for all of these we are assuming eqn and a are the same. Then the summary across all quantiles is
where is the weight assigned for the qth quantile model.
## S3 method for class 'rq.pen.seq.cv' qic.select( obj, method = c("BIC", "AIC", "PBIC"), septau = ifelse(obj$fit$penalty != "gq", TRUE, FALSE), weights = NULL, ... )
## S3 method for class 'rq.pen.seq.cv' qic.select( obj, method = c("BIC", "AIC", "PBIC"), septau = ifelse(obj$fit$penalty != "gq", TRUE, FALSE), weights = NULL, ... )
obj |
A rq.pen.seq.cv object. |
method |
Choice of BIC, AIC or PBIC, a large p BIC. |
septau |
If optimal values of |
weights |
Weights for each quantile. Useful if you set septau to FALSE but want different weights for the different quantiles. If not specified default is to have |
... |
Additional arguments. |
Coefficients of the selected models.
Information criterion values for all considered models.
Model info for the selected models related to the original object obj.
Information criterion summarized across all quantiles. Only returned if septau set to FALSE
Ben Sherwood, [email protected]
Lee ER, Noh H, Park BU (2014). “Model Selection via Bayesian Information Criterion for Quantile Regression Models.” Journal of the American Statistical Association, 109(505), 216–229. ISSN 01621459.
set.seed(1) x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen.cv(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75)) qic.select(m1)
set.seed(1) x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) m1 <- rq.pen.cv(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.75)) qic.select(m1)
Uses the group lasso penalty across the quantiles to provide consistent selection across all, K, modeled quantiles. Let
be the coefficients for the kth quantiles,
be the Q-dimensional vector of the jth coefficient for each quantile, and
is the quantile loss function. The method minimizes
Uses a Huber approximation in the fitting of model, as presented in Sherwood and Li (2022). Where,
where is a quantile weight
that can be specified by
tau.penalty.factor
, is a predictor weight that can be assigned by
penalty.factor
,
and is an observation weight that can be set by
weights
.
rq.gq.pen( x, y, tau, lambda = NULL, nlambda = 100, eps = ifelse(nrow(x) < ncol(x), 0.01, 0.001), weights = NULL, penalty.factor = NULL, scalex = TRUE, tau.penalty.factor = NULL, gmma = 0.2, max.iter = 200, lambda.discard = TRUE, converge.eps = 1e-04, beta0 = NULL )
rq.gq.pen( x, y, tau, lambda = NULL, nlambda = 100, eps = ifelse(nrow(x) < ncol(x), 0.01, 0.001), weights = NULL, penalty.factor = NULL, scalex = TRUE, tau.penalty.factor = NULL, gmma = 0.2, max.iter = 200, lambda.discard = TRUE, converge.eps = 1e-04, beta0 = NULL )
x |
covariate matrix |
y |
a univariate response variable |
tau |
a sequence of quantiles to be modeled, must be of at least length 3. |
lambda |
shrinkage parameter. Default is NULL, and the algorithm provides a solution path. |
nlambda |
Number of lambda values to be considered. |
eps |
If not pre-specified the lambda vector will be from lambda_max to lambda_max times eps |
weights |
observation weights. Default is NULL, which means equal weights. |
penalty.factor |
weights for the shrinkage parameter for each covariate. Default is equal weight. |
scalex |
Whether x should be scaled before fitting the model. Coefficients are returned on the original scale. |
tau.penalty.factor |
weights for different quantiles. Default is equal weight. |
gmma |
tuning parameter for the Huber loss |
max.iter |
maximum number of iteration. Default is 200. |
lambda.discard |
Default is TRUE, meaning that the solution path stops if the relative deviance changes sufficiently small. It usually happens near the end of solution path. However, the program returns at least 70 models along the solution path. |
converge.eps |
The epsilon level convergence. Default is 1e-4. |
beta0 |
Initial estimates. Default is NULL, and the algorithm starts with the intercepts being the quantiles of response variable and other coefficients being zeros. |
An rq.pen.seq object.
A list of each model fit for each tau and a combination.
Sample size.
Number of predictors.
Algorithm used. Options are "huber" or any method implemented in rq(), such as "br".
Quantiles modeled.
Tuning parameters a used.
Information about the quantile and a value for each model.
Lambda values used for all models. If a model has fewer coefficients than lambda, say k. Then it used the first k values of lambda. Setting lambda.discard to TRUE will gurantee all values use the same lambdas, but may increase computational time noticeably and for little gain.
Penalty used.
Original call.
Each model in the models list has the following values.
Coefficients for each value of lambda.
The unpenalized objective function for each value of lambda.
The penalized objective function for each value of lambda.
The number of nonzero coefficients for each value of lambda.
Quantile of the model.
Value of a for the penalized loss function.
Shaobo Li and Ben Sherwood, [email protected]
Wang M, Kang X, Liang J, Wang K, Wu Y (2024). “Heteroscedasticity identification and variable selection via multiple quantile regression.” Journal of Statistical Computation and Simulation, 94(2), 297-314.
Sherwood B, Li S (2022). “Quantile regression feature selection and estimation with grouped variables using Huber approximation.” Statistics and Computing, 32(5), 75.
## Not run: n<- 200 p<- 10 X<- matrix(rnorm(n*p),n,p) y<- -2+X[,1]+0.5*X[,2]-X[,3]-0.5*X[,7]+X[,8]-0.2*X[,9]+rt(n,2) taus <- seq(0.1, 0.9, 0.2) fit<- rq.gq.pen(X, y, taus) #use IC to select best model, see rq.gq.pen.cv() for a cross-validation approach qfit <- qic.select(fit) ## End(Not run)
## Not run: n<- 200 p<- 10 X<- matrix(rnorm(n*p),n,p) y<- -2+X[,1]+0.5*X[,2]-X[,3]-0.5*X[,7]+X[,8]-0.2*X[,9]+rt(n,2) taus <- seq(0.1, 0.9, 0.2) fit<- rq.gq.pen(X, y, taus) #use IC to select best model, see rq.gq.pen.cv() for a cross-validation approach qfit <- qic.select(fit) ## End(Not run)
Title Cross validation for consistent variable selection across multiple quantiles.
rq.gq.pen.cv( x = NULL, y = NULL, tau = NULL, lambda = NULL, nfolds = 10, cvFunc = c("rq", "se"), tauWeights = NULL, foldid = NULL, printProgress = FALSE, weights = NULL, ... )
rq.gq.pen.cv( x = NULL, y = NULL, tau = NULL, lambda = NULL, nfolds = 10, cvFunc = c("rq", "se"), tauWeights = NULL, foldid = NULL, printProgress = FALSE, weights = NULL, ... )
x |
covariate matrix. Not needed if |
y |
univariate response. Not needed if |
tau |
a sequence of tau to be modeled, must be at least of length 3. |
lambda |
Values of |
nfolds |
number of folds |
cvFunc |
loss function to be evaluated for cross-validation. Supported loss functions include quantile ("rq") and squared loss("se"). Default is the quantile loss. |
tauWeights |
weights for different quantiles in calculating the cv error. Default is equal weight. |
foldid |
indices of pre-split testing obervations |
printProgress |
If set to TRUE prints which partition is being worked on. |
weights |
Weights for the quantile loss objective function. |
... |
other arguments for |
Let and
index the observations in
fold b. Let
be the estimator for a given quantile and tuning parameters that did not use the bth fold. Let
be the number of observations in fold
b. Then the cross validation error for fold b is
Where, is the weight for the ith observation in fold b and
is a quantile specific weight. Note that
can be replaced squared error loss. Provides results about how the average of the cross-validation error changes with
. Uses a
Huber approximation in the fitting of model, as presented in Sherwood and Li (2022).
An rq.pen.seq.cv object.
Matrix of cvSummary function, default is average, cross-validation error for each model, tau and a combination, and lambda.
Matrix of the standard error of cverr foreach model, tau and a combination, and lambda.
The rq.pen.seq object fit to the full data.
Let blank, unlike rq.pen.seq.cv() or rq.group.pen.cv(), because optmizes the quantiles individually does not make sense with this penalty.
A data.table for the combination of a and lambda that minimize the cross validation error across all tau.
Group, across all quantiles, cross-validation error results for each value of a and lambda.
Original call to the function.
Shaobo Li and Ben Sherwood, [email protected]
Wang M, Kang X, Liang J, Wang K, Wu Y (2024). “Heteroscedasticity identification and variable selection via multiple quantile regression.” Journal of Statistical Computation and Simulation, 94(2), 297-314.
Sherwood B, Li S (2022). “Quantile regression feature selection and estimation with grouped variables using Huber approximation.” Statistics and Computing, 32(5), 75.
## Not run: n<- 200 p<- 10 X<- matrix(rnorm(n*p),n,p) y<- -2+X[,1]+0.5*X[,2]-X[,3]-0.5*X[,7]+X[,8]-0.2*X[,9]+rt(n,2) taus <- seq(0.1, 0.9, 0.2) cvfit<- rq.gq.pen.cv(x=X, y=y, tau=taus) cvCoefs <- coefficients(cvfit) ## End(Not run)
## Not run: n<- 200 p<- 10 X<- matrix(rnorm(n*p),n,p) y<- -2+X[,1]+0.5*X[,2]-X[,3]-0.5*X[,7]+X[,8]-0.2*X[,9]+rt(n,2) taus <- seq(0.1, 0.9, 0.2) cvfit<- rq.gq.pen.cv(x=X, y=y, tau=taus) cvCoefs <- coefficients(cvfit) ## End(Not run)
Let the predictors be divided into G groups with G corresponding vectors of coefficients, .
Let
. Fits quantile regression models for Q quantiles by minimizing the penalized objective function of
Where and
are designated by penalty.factor and tau.penalty.factor respectively and
can be set by weights. The value of
is chosen by
norm
.
Value of P() depends on the penalty. Briefly, but see references or vignette for more details,
Note if and the group lasso penalty is used then this is identical to the regular lasso and thus function will stop and
suggest that you use rq.pen() instead. For Adaptive LASSO the values of
come from a Ridge solution with the same value of
.
If the Huber algorithm is used than
is replaced by a Huber-type approximation. Specifically, it is replaced by
where
Where if , we get the usual Huber loss function.
rq.group.pen( x, y, tau = 0.5, groups = 1:ncol(x), penalty = c("gLASSO", "gAdLASSO", "gSCAD", "gMCP"), lambda = NULL, nlambda = 100, eps = ifelse(nrow(x) < ncol(x), 0.05, 0.01), alg = c("huber", "br"), a = NULL, norm = 2, group.pen.factor = NULL, tau.penalty.factor = rep(1, length(tau)), scalex = TRUE, coef.cutoff = 1e-08, max.iter = 5000, converge.eps = 1e-04, gamma = IQR(y)/10, lambda.discard = TRUE, weights = NULL, ... )
rq.group.pen( x, y, tau = 0.5, groups = 1:ncol(x), penalty = c("gLASSO", "gAdLASSO", "gSCAD", "gMCP"), lambda = NULL, nlambda = 100, eps = ifelse(nrow(x) < ncol(x), 0.05, 0.01), alg = c("huber", "br"), a = NULL, norm = 2, group.pen.factor = NULL, tau.penalty.factor = rep(1, length(tau)), scalex = TRUE, coef.cutoff = 1e-08, max.iter = 5000, converge.eps = 1e-04, gamma = IQR(y)/10, lambda.discard = TRUE, weights = NULL, ... )
x |
Matrix of predictors. |
y |
Vector of responses. |
tau |
Vector of quantiles. |
groups |
Vector of group assignments for predictors. |
penalty |
Penalty used, choices are group lasso ("gLASSO"), group adaptive lasso ("gAdLASSO"), group SCAD ("gSCAD") and group MCP ("gMCP") |
lambda |
Vector of lambda tuning parameters. Will be autmoatically generated if it is not set. |
nlambda |
The number of lambda tuning parameters. |
eps |
The value to be multiplied by the largest lambda value to determine the smallest lambda value. |
alg |
Algorithm used. Choices are Huber approximation ("huber") or linear programming ("lp"). |
a |
The additional tuning parameter for adaptive lasso, SCAD and MCP. |
norm |
Whether a L1 or L2 norm is used for the grouped coefficients. |
group.pen.factor |
Penalty factor for each group. Default is 1 for all groups if norm=1 and square root of group size if norm=2. |
tau.penalty.factor |
Penalty factor for each quantile. |
scalex |
Whether X should be centered and scaled so that the columns have mean zero and standard deviation of one. If set to TRUE, the coefficients will be returned to the original scale of the data. |
coef.cutoff |
Coefficient cutoff where any value below this number is set to zero. Useful for the lp algorithm, which are prone to finding almost, but not quite, sparse solutions. |
max.iter |
The maximum number of iterations for the algorithm. |
converge.eps |
The convergence criteria for the algorithms. |
gamma |
The tuning parameter for the Huber loss. |
lambda.discard |
Whether lambdas should be discarded if for small values of lambda there is very little change in the solutions. |
weights |
Weights used in the quanitle loss objective function. |
... |
Additional parameters |
An rq.pen.seq object.
A list of each model fit for each tau and a combination.
Sample size.
Number of predictors.
Algorithm used.
Quantiles modeled.
Penalty used.
Tuning parameters a used.
Lambda values used for all models. If a model has fewer coefficients than lambda, say k. Then it used the first k values of lambda. Setting lambda.discard to TRUE will gurantee all values use the same lambdas, but may increase computational time noticeably and for little gain.
Information about the quantile and a value for each model.
Original call.
Each model in the models list has the following values.
Coefficients for each value of lambda.
The unpenalized objective function for each value of lambda.
The penalized objective function for each value of lambda. If scalex=TRUE then this is the value for the scaled version of x.
The number of nonzero coefficients for each value of lambda.
Quantile of the model.
Value of a for the penalized loss function.
Ben Sherwood, [email protected], Shaobo Li [email protected] and Adam Maidman
Peng B, Wang L (2015). “An iterative coordinate descent algorithm for high-dimensional nonconvex penalized quantile regression.” J. Comput. Graph. Statist., 24(3), 676-694.
## Not run: set.seed(1) x <- matrix(rnorm(200*8,sd=1),ncol=8) y <- 1 + x[,1] + 3*x[,3] - x[,8] + rt(200,3) g <- c(1,1,1,2,2,2,3,3) tvals <- c(.25,.75) r1 <- rq.group.pen(x,y,groups=g) r5 <- rq.group.pen(x,y,groups=g,tau=tvals) #Linear programming approach with group SCAD penalty and L1-norm m2 <- rq.group.pen(x,y,groups=g,alg="br",penalty="gSCAD",norm=1,a=seq(3,4)) # No penalty for the first group m3 <- rq.group.pen(x,y,groups=g,group.pen.factor=c(0,rep(1,2))) # Smaller penalty for the median m4 <- rq.group.pen(x,y,groups=g,tau=c(.25,.5,.75),tau.penalty.factor=c(1,.25,1)) ## End(Not run)
## Not run: set.seed(1) x <- matrix(rnorm(200*8,sd=1),ncol=8) y <- 1 + x[,1] + 3*x[,3] - x[,8] + rt(200,3) g <- c(1,1,1,2,2,2,3,3) tvals <- c(.25,.75) r1 <- rq.group.pen(x,y,groups=g) r5 <- rq.group.pen(x,y,groups=g,tau=tvals) #Linear programming approach with group SCAD penalty and L1-norm m2 <- rq.group.pen(x,y,groups=g,alg="br",penalty="gSCAD",norm=1,a=seq(3,4)) # No penalty for the first group m3 <- rq.group.pen(x,y,groups=g,group.pen.factor=c(0,rep(1,2))) # Smaller penalty for the median m4 <- rq.group.pen(x,y,groups=g,tau=c(.25,.5,.75),tau.penalty.factor=c(1,.25,1)) ## End(Not run)
Performs cross validation for a group penalty.
rq.group.pen.cv( x, y, tau = 0.5, groups = 1:ncol(x), lambda = NULL, a = NULL, cvFunc = NULL, nfolds = 10, foldid = NULL, groupError = TRUE, cvSummary = mean, tauWeights = rep(1, length(tau)), printProgress = FALSE, weights = NULL, ... )
rq.group.pen.cv( x, y, tau = 0.5, groups = 1:ncol(x), lambda = NULL, a = NULL, cvFunc = NULL, nfolds = 10, foldid = NULL, groupError = TRUE, cvSummary = mean, tauWeights = rep(1, length(tau)), printProgress = FALSE, weights = NULL, ... )
x |
Matrix of predictors. |
y |
Vector of responses. |
tau |
Vector of quantiles. |
groups |
Vector of group assignments for the predictors. |
lambda |
Vector of lambda values, if set to NULL they will be generated automatically. |
a |
Vector of the other tuning parameter values. |
cvFunc |
Function used for cross-validation error, default is quantile loss. |
nfolds |
Number of folds used for cross validation. |
foldid |
Fold assignments, if not set this will be randomly created. |
groupError |
If errors are to be reported as a group or as the average for each fold. |
cvSummary |
The |
tauWeights |
Weights for the tau penalty only used in group tau results (gtr). |
printProgress |
If set to TRUE will print which fold the process is working on. |
weights |
Weights for the quantile loss function. Used in both model fitting and cross-validation. |
... |
Additional parameters that will be sent to rq.group.pen(). |
Two cross validation results are returned. One that considers the best combination of a and lambda for each quantile. The second considers the best combination of the tuning
parameters for all quantiles. Let ,
, and
index the response, predictors, and weights of observations in
fold b. Let
be the estimator for a given quantile and tuning parameters that did not use the bth fold. Let
be the number of observations in fold
b. Then the cross validation error for fold b is
Note that can be replaced by a different function by setting the cvFunc parameter. The function returns two different cross-validation summaries. The first is btr, by tau results.
It provides the values of
lambda
and a
that minimize the average, or whatever function is used for cvSummary
, of . In addition it provides the
sparsest solution that is within one standard error of the minimum results.
The other approach is the group tau results, gtr. Consider the case of estimating Q quantiles of with quantile (tauWeights) of
. The gtr returns the values of
lambda
and a
that minimizes the average, or again whatever function is used for cvSummary
, of
If only one quantile is modeled then the gtr results can be ignored as they provide the same minimum solution as btr.
An rq.pen.seq.cv object.
Matrix of cvSummary function, default is average, cross-validation error for each model, tau and a combination, and lambda.
Matrix of the standard error of cverr foreach model, tau and a combination, and lambda.
The rq.pen.seq object fit to the full data.
A data.table of the values of a and lambda that are best as determined by the minimum cross validation error and the one standard error rule, which fixes a. In btr the values of lambda and a are selected seperately for each quantile.
A data.table for the combination of a and lambda that minimize the cross validation error across all tau.
Group, across all quantiles, cross-validation error results for each value of a and lambda.
Original call to the function.
Ben Sherwood, [email protected] and Shaobo Li [email protected]
set.seed(1) x <- matrix(rnorm(100*8,sd=1),ncol=8) y <- 1 + x[,1] + 3*x[,3] - x[,8] + rt(100,3) g <- c(1,1,1,1,2,2,3,3) tvals <- c(.25,.75) ## Not run: m1 <- rq.group.pen.cv(x,y,tau=c(.1,.3,.7),groups=g) m2 <- rq.group.pen.cv(x,y,penalty="gAdLASSO",tau=c(.1,.3,.7),groups=g) m3 <- rq.group.pen.cv(x,y,penalty="gSCAD",tau=c(.1,.3,.7),a=c(3,4,5),groups=g) m4 <- rq.group.pen.cv(x,y,penalty="gMCP",tau=c(.1,.3,.7),a=c(3,4,5),groups=g) ## End(Not run)
set.seed(1) x <- matrix(rnorm(100*8,sd=1),ncol=8) y <- 1 + x[,1] + 3*x[,3] - x[,8] + rt(100,3) g <- c(1,1,1,1,2,2,3,3) tvals <- c(.25,.75) ## Not run: m1 <- rq.group.pen.cv(x,y,tau=c(.1,.3,.7),groups=g) m2 <- rq.group.pen.cv(x,y,penalty="gAdLASSO",tau=c(.1,.3,.7),groups=g) m3 <- rq.group.pen.cv(x,y,penalty="gSCAD",tau=c(.1,.3,.7),a=c(3,4,5),groups=g) m4 <- rq.group.pen.cv(x,y,penalty="gMCP",tau=c(.1,.3,.7),a=c(3,4,5),groups=g) ## End(Not run)
Let q index the Q quantiles of interest. Let . Fits quantile regression models by minimizing the penalized objective function of
Where and
are designated by penalty.factor and tau.penalty.factor respectively, and
is designated by weights. Value of
depends on the penalty. See references or vignette for more details,
For Adaptive LASSO the values of come from a Ridge solution with the same value of
. Three different algorithms are implemented
Uses a Huber approximation of the quantile loss function. See Yi and Huang 2017 for more details.
Solution is found by re-formulating the problem so it can be solved with the rq() function from quantreg with the br algorithm.
The huber algorithm offers substantial speed advantages without much, if any, loss in performance. However, it should be noted that it solves an approximation of the quantile loss function.
rq.pen( x, y, tau = 0.5, lambda = NULL, penalty = c("LASSO", "Ridge", "ENet", "aLASSO", "SCAD", "MCP"), a = NULL, nlambda = 100, eps = ifelse(nrow(x) < ncol(x), 0.05, 0.01), penalty.factor = rep(1, ncol(x)), alg = c("huber", "br", "fn"), scalex = TRUE, tau.penalty.factor = rep(1, length(tau)), coef.cutoff = 1e-08, max.iter = 5000, converge.eps = 1e-04, lambda.discard = TRUE, weights = NULL, ... )
rq.pen( x, y, tau = 0.5, lambda = NULL, penalty = c("LASSO", "Ridge", "ENet", "aLASSO", "SCAD", "MCP"), a = NULL, nlambda = 100, eps = ifelse(nrow(x) < ncol(x), 0.05, 0.01), penalty.factor = rep(1, ncol(x)), alg = c("huber", "br", "fn"), scalex = TRUE, tau.penalty.factor = rep(1, length(tau)), coef.cutoff = 1e-08, max.iter = 5000, converge.eps = 1e-04, lambda.discard = TRUE, weights = NULL, ... )
x |
matrix of predictors |
y |
vector of responses |
tau |
vector of quantiles |
lambda |
vector of lambda, if not set will be generated automatically |
penalty |
choice of penalty |
a |
Additional tuning parameter, not used for lasso or ridge penalties. However, will be set to the elastic net values of 1 and 0 respectively. Defaults are ENet(0), aLASSO(1), SCAD(3.7) and MCP(3). |
nlambda |
number of lambda, ignored if lambda is set |
eps |
If not pre-specified the lambda vector will be from lambda_max to lambda_max times eps |
penalty.factor |
penalty factor for the predictors |
alg |
Algorithm used. |
scalex |
Whether x should be scaled before fitting the model. Coefficients are returned on the original scale. |
tau.penalty.factor |
A penalty factor for each quantile. |
coef.cutoff |
Some of the linear programs will provide very small, but not sparse solutions. Estimates below this number will be set to zero. This is ignored if a non-linear programming algorithm is used. |
max.iter |
Maximum number of iterations of non-linear programming algorithms. |
converge.eps |
Convergence threshold for non-linear programming algorithms. |
lambda.discard |
Algorithm may stop for small values of lambda if the coefficient estimates are not changing drastically. One example of this is it is possible for the LLA weights of the non-convex functions to all become zero and smaller values of lambda are extremely likely to produce the same zero weights. |
weights |
Weights for the quantile objective function. |
... |
Extra parameters. |
An rq.pen.seq object.
A list of each model fit for each tau and a combination.
Sample size.
Number of predictors.
Algorithm used. Options are "huber" or any method implemented in rq(), such as "br".
Quantiles modeled.
Tuning parameters a used.
Information about the quantile and a value for each model.
Lambda values used for all models. If a model has fewer coefficients than lambda, say k. Then it used the first k values of lambda. Setting lambda.discard to TRUE will gurantee all values use the same lambdas, but may increase computational time noticeably and for little gain.
Penalty used.
Original call.
Each model in the models list has the following values.
Coefficients for each value of lambda.
The unpenalized objective function for each value of lambda.
The penalized objective function for each value of lambda. If scalex=TRUE then this is the value for the scaled version of x.
The number of nonzero coefficients for each value of lambda.
Quantile of the model.
Value of a for the penalized loss function.
If the Huber algorithm is used than is replaced by a Huber-type approximation. Specifically, it is replaced by
where
Where if , we get the usual Huber loss function. The Huber implementation calls the package hqreg which implements the methods of Yi and Huang (2017)
for Huber loss with elastic net penalties. For non-elastic net penalties the LLA algorithm of Zou and Li (2008) is used to approximate those loss functions
with a lasso penalty with different weights for each predictor.
Ben Sherwood, [email protected], Shaobo Li, and Adam Maidman
Zou H, Li R (2008). “One-step sparse estimates in nonconcave penalized likelihood models.” Ann. Statist., 36(4), 1509-1533.
Yi C, Huang J (2017). “Semismooth Newton Coordinate Descent Algorithm for Elastic-Net Penalized Huber Loss Regression and Quantile Regression.” J. Comput. Graph. Statist., 26(3), 547-557.
Belloni A, Chernozhukov V (2011). “L1-Penalized quantile regression in high-dimensional sparse models.” Ann. Statist., 39(1), 82-130.
Peng B, Wang L (2015). “An iterative coordinate descent algorithm for high-dimensional nonconvex penalized quantile regression.” J. Comput. Graph. Statist., 24(3), 676-694.
n <- 200 p <- 8 x <- matrix(runif(n*p),ncol=p) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(n) r1 <- rq.pen(x,y) #Lasso fit for median # Lasso for multiple quantiles r2 <- rq.pen(x,y,tau=c(.25,.5,.75)) # Elastic net fit for multiple quantiles, which must use Huber algorithm r3 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),alg="huber") # First variable is not penalized r4 <- rq.pen(x,y,penalty.factor=c(0,rep(1,7))) tvals <- c(.1,.2,.3,.4,.5) #Similar to penalty proposed by Belloni and Chernouzhukov. #To be exact you would divide the tau.penalty.factor by n. r5 <- rq.pen(x,y,tau=tvals, tau.penalty.factor=sqrt(tvals*(1-tvals)))
n <- 200 p <- 8 x <- matrix(runif(n*p),ncol=p) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(n) r1 <- rq.pen(x,y) #Lasso fit for median # Lasso for multiple quantiles r2 <- rq.pen(x,y,tau=c(.25,.5,.75)) # Elastic net fit for multiple quantiles, which must use Huber algorithm r3 <- rq.pen(x,y,penalty="ENet",a=c(0,.5,1),alg="huber") # First variable is not penalized r4 <- rq.pen(x,y,penalty.factor=c(0,rep(1,7))) tvals <- c(.1,.2,.3,.4,.5) #Similar to penalty proposed by Belloni and Chernouzhukov. #To be exact you would divide the tau.penalty.factor by n. r5 <- rq.pen(x,y,tau=tvals, tau.penalty.factor=sqrt(tvals*(1-tvals)))
and a.Does k-folds cross validation for rq.pen. If multiple values of a are specified then does a grid based search for best value of and a.
rq.pen.cv( x, y, tau = 0.5, lambda = NULL, penalty = c("LASSO", "Ridge", "ENet", "aLASSO", "SCAD", "MCP"), a = NULL, cvFunc = NULL, nfolds = 10, foldid = NULL, nlambda = 100, groupError = TRUE, cvSummary = mean, tauWeights = rep(1, length(tau)), printProgress = FALSE, weights = NULL, ... )
rq.pen.cv( x, y, tau = 0.5, lambda = NULL, penalty = c("LASSO", "Ridge", "ENet", "aLASSO", "SCAD", "MCP"), a = NULL, cvFunc = NULL, nfolds = 10, foldid = NULL, nlambda = 100, groupError = TRUE, cvSummary = mean, tauWeights = rep(1, length(tau)), printProgress = FALSE, weights = NULL, ... )
x |
Matrix of predictors. |
y |
Vector of responses. |
tau |
Quantiles to be modeled. |
lambda |
Values of |
penalty |
Choice of penalty between LASSO, Ridge, Elastic Net (ENet), Adaptive Lasso (aLASSO), SCAD and MCP. |
a |
Tuning parameter of a. LASSO and Ridge has no second tuning parameter, but for notation is set to 1 or 0 respectively, the values for elastic net. Defaults are Ridge () |
cvFunc |
Loss function for cross-validation. Defaults to quantile loss, but user can specify their own function. |
nfolds |
Number of folds. |
foldid |
Ids for folds. If set will override nfolds. |
nlambda |
Number of lambda, ignored if lambda is set. |
groupError |
If set to false then reported error is the sum of all errors, not the sum of error for each fold. |
cvSummary |
Function to summarize the errors across the folds, default is mean. User can specify another function, such as median. |
tauWeights |
Weights for the different tau models. Only used in group tau results (gtr). |
printProgress |
If set to TRUE prints which partition is being worked on. |
weights |
Weights for the quantile loss objective function. |
... |
Additional arguments passed to rq.pen() |
Two cross validation results are returned. One that considers the best combination of a and lambda for each quantile. The second considers the best combination of the tuning
parameters for all quantiles. Let ,
, and
index the response, predictors, and weights of observations in
fold b. Let
be the estimator for a given quantile and tuning parameters that did not use the bth fold. Let
be the number of observations in fold
b. Then the cross validation error for fold b is
Note that can be replaced by a different function by setting the cvFunc parameter. The function returns two different cross-validation summaries. The first is btr, by tau results.
It provides the values of
lambda
and a
that minimize the average, or whatever function is used for cvSummary
, of . In addition it provides the
sparsest solution that is within one standard error of the minimum results.
The other approach is the group tau results, gtr. Consider the case of estimating Q quantiles of with quantile (tauWeights) of
. The gtr returns the values of
lambda
and a
that minimizes the average, or again whatever function is used for cvSummary
, of
If only one quantile is modeled then the gtr results can be ignored as they provide the same minimum solution as btr.
An rq.pen.seq.cv object.
Matrix of cvSummary function, default is average, cross-validation error for each model, tau and a combination, and lambda.
Matrix of the standard error of cverr foreach model, tau and a combination, and lambda.
The rq.pen.seq object fit to the full data.
A data.table of the values of a and lambda that are best as determined by the minimum cross validation error and the one standard error rule, which fixes a. In btr the values of lambda and a are selected seperately for each quantile.
A data.table for the combination of a and lambda that minimize the cross validation error across all tau.
Group, across all quantiles, cross-validation error results for each value of a and lambda.
Original call to the function.
Ben Sherwood, [email protected]
## Not run: x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) r1 <- rq.pen.cv(x,y) #lasso fit for median # Elastic net fit for multiple values of a and tau r2 <- rq.pen.cv(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.5,.75)) #same as above but more weight given to median when calculating group cross validation error. r3 <- rq.pen.cv(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.5,.75),tauWeights=c(.25,.5,.25)) # uses median cross-validation error instead of mean. r4 <- rq.pen.cv(x,y,cvSummary=median) #Cross-validation with no penalty on the first variable. r5 <- rq.pen.cv(x,y,penalty.factor=c(0,rep(1,7))) ## End(Not run)
## Not run: x <- matrix(runif(800),ncol=8) y <- 1 + x[,1] + x[,8] + (1+.5*x[,3])*rnorm(100) r1 <- rq.pen.cv(x,y) #lasso fit for median # Elastic net fit for multiple values of a and tau r2 <- rq.pen.cv(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.5,.75)) #same as above but more weight given to median when calculating group cross validation error. r3 <- rq.pen.cv(x,y,penalty="ENet",a=c(0,.5,1),tau=c(.25,.5,.75),tauWeights=c(.25,.5,.25)) # uses median cross-validation error instead of mean. r4 <- rq.pen.cv(x,y,cvSummary=median) #Cross-validation with no penalty on the first variable. r5 <- rq.pen.cv(x,y,penalty.factor=c(0,rep(1,7))) ## End(Not run)
The package estimates a quantile regression model using LASSO, Adaptive LASSO, SCAD, MCP, elastic net, and their group counterparts, with the exception of elastic net for which there is no group penalty implementation.
The most important functions are rq.pen(), rq.group.pen(), rq.pen.cv() and rq.group.pen.cv(). These functions fit quantile regression models with individual or group penalties. The cv functions automate the cross-validation process for selection of tuning parameters.
Useful links: