hdqr {hdqr}R Documentation

Solve the linear quantile regression. The solution path is computed at a grid of values of tuning parameter lambda.

Description

Solve the linear quantile regression. The solution path is computed at a grid of values of tuning parameter lambda.

Usage

hdqr(
  x,
  y,
  tau,
  nlambda = 100,
  lambda.factor = ifelse(nobs < nvars, 0.01, 1e-04),
  lambda = NULL,
  lam2 = 0.01,
  hval = 0.125,
  pf = rep(1, nvars),
  pf2 = rep(1, nvars),
  exclude,
  dfmax = nvars + 1,
  pmax = min(dfmax * 1.2, nvars),
  standardize = TRUE,
  eps = 1e-08,
  maxit = 1e+06,
  sigma = 0.05,
  is_exact = FALSE
)

Arguments

x

Matrix of predictors, of dimension (nobs * nvars); each row is an observation.

y

Response variable. The length is n.

tau

The quantile level \tau. The value must be in (0,1). Default is 0.5.

nlambda

The number of lambda values (default is 100).

lambda.factor

The factor for getting the minimal value in the lambda sequence, where min(lambda) = lambda.factor * max(lambda) and max(lambda) is the smallest value of lambda for which all coefficients (except the intercept when it is present) are penalized to zero. The default depends on the relationship between n (the number of rows in the design matrix) and p (the number of predictors). If n < p, it defaults to 0.05. If n > p, the default is 0.001, closer to zero. A very small value of lambda.factor will lead to a saturated fit. The argument takes no effect if there is a user-supplied lambda sequence.

lambda

A user-supplied lambda sequence. Typically, by leaving this option unspecified, users can have the program compute its own lambda sequence based on nlambda and lambda.factor. It is better to supply, if necessary, a decreasing sequence of lambda values than a single (small) value. The program will ensure that the user-supplied lambda sequence is sorted in decreasing order before fitting the model to take advanage of the warm-start technique.

lam2

Regularization parameter lambda2 for the quadratic penalty of the coefficients. Unlike lambda, only one value of lambda2 is used for each fitting process.

hval

The smoothing index for method='huber'. Default is 0.125.

pf

L1 penalty factor of length p used for the adaptive LASSO or adaptive elastic net. Separate L1 penalty weights can be applied to each coefficient to allow different L1 shrinkage. Can be 0 for some variables (but not all), which imposes no shrinkage, and results in that variable always being included in the model. Default is 1 for all variables (and implicitly infinity for variables in the exclude list).

pf2

L2 penalty factor of length p used for adaptive elastic net. Separate L2 penalty weights can be applied to each coefficient to allow different L2 shrinkage. Can be 0 for some variables, which imposes no shrinkage. Default is 1 for all variables.

exclude

Indices of variables to be excluded from the model. Default is none. Equivalent to an infinite penalty factor.

dfmax

The maximum number of variables allowed in the model. Useful for very large p when a partial path is desired. Default is p+1.

pmax

The maximum number of coefficients allowed ever to be nonzero along the solution path. For example, once \beta enters the model, no matter how many times it exits or re-enters the model through the path, it will be counted only once. Default is min(dfmax*1.2, p).

standardize

Logical flag for variable standardization, prior to fitting the model sequence. The coefficients are always returned to the original scale. Default is TRUE.

eps

Stopping criterion.

maxit

Maximum number of iterates.

sigma

Penalty parameter appearing in the quadratic term of the augmented Lagrangian function. Must be positive.

is_exact

Exact or approximated solutions. Default is FALSE.

Details

Note that the objective function in the penalized quantile regression is

1'\rho_{\tau}(y-X\beta-b_0))/N + \lambda_1\cdot|pf_1\circ\beta|_1 + 0.5*\lambda_2\cdot|\sqrt{pf_2}\circ\beta|^2,

where \rho_{\tau} the quantile or check loss and the penalty is a combination of weighted L1 and L2 terms and \circ denotes the Hadmamard product.

For faster computation, if the algorithm is not converging or running slow, consider increasing eps, increasing sigma, decreasing nlambda, or increasing lambda.factor before increasing maxit.

Value

An object with S3 class hdqr consisting of

call

the call that produced this object

b0

intercept sequence of length length(lambda)

beta

a p*length(lambda) matrix of coefficients, stored as a sparse matrix (dgCMatrix class, the standard class for sparse numeric matrices in the Matrix package.). To convert it into normal type matrix, use as.matrix().

lambda

the actual sequence of lambda values used

df

the number of nonzero coefficients for each value of lambda.

npasses

the number of iterations for every lambda value

jerr

error flag, for warnings and errors, 0 if no error.

Examples

set.seed(315)
n <- 100
p <- 400
x <- matrix(data = rnorm(n * p, mean = 0, sd = 1), nrow = n, ncol = p)
beta_star <- c(c(2, 1.5, 0.8, 1, 1.75, 0.75, 0.3), rep(0, (p - 7)))
eps <- rnorm(n, mean = 0, sd = 1)
y <- x %*% beta_star + eps
tau <- 0.5
lam2 <- 0.01
fit <- hdqr(x = x, y = y, tau = tau, lam2 = lam2)

[Package hdqr version 1.0.1 Index]