This package provides tools for fitting elastic net penalized quantile regression.

The strengths and improvements that this package offers relative to other quantile regression packages are as follows:

For this getting-started vignette, first, we will randomly generate x, an input matrix of predictors of dimension \(n\times p\) and a response variable 'y'.

library(hdqr)
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

Then the elastic net penalized quantile regression model is formulated as:

$$ \min{\beta\in\mathbb{R}{p},b_0\in\mathbb{R}} \frac{1}{n} \sum{i=1}{n}\rho{\tau}(y{i}-b_0-x_i{\top}\beta)

hdqr()

Given an input matrix x, a quantile level tau, and a response vector y, the elastic net penalized quantile regression model is estimated for a sequence of penalty parameter values. The other main arguments the users might supply are:

lambda <- 10^(seq(1, -4, length.out=30))
lam2 <- 0.01
tau <- 0.5
fit <- hdqr(x, y, lambda=lambda, lam2=lam2, tau=tau)

cv.hdqr()

This function performs k-fold cross-validation (cv) for the hdqr() model. It takes the same arguments x, y, tau, lambda, which are specified above, with additional argument nfolds and foldid for the error measure.

cv.fit <- cv.hdqr(x, y, lambda=lambda, tau=tau)

nc.hdqr()

This function fits the penalized quantile regression model using nonconvex penalties such as SCAD or MCP. It allows for flexible control over the regularization parameters and offers advanced options for initializing and optimizing the fit. It takes the same arguments x, y,lambda, lam2, which are specified above.The other main arguments the users might supply are:

nc.fit <- nc.hdqr(x=x, y=y, tau=tau, lambda=lambda, lam2=lam2, pen="scad")

cv.nc.hdqr()

This function onducts k-fold cross-validation for the nc.hdqr() function. It takes the same arguments as the cv.hdqr() function.

cv.nc.fit <- cv.nc.hdqr(y=y, x=x, tau=tau, lambda=lambda, lam2=lam2, pen="scad")

Methods

A number of S3 methods are provided for hdqr, cv.hdqr, nc.hdqr and cv.nc.hdqr objects.

coefs <- coef(fit, s = fit$lambda[3:5])
preds <- predict(fit, newx = tail(x), s = fit$lambda[3:5])
cv.coefs <- coef(cv.fit, s = c(0.02, 0.03))
cv.preds <- predict(cv.fit, newx = x[50:60, ], s = "lambda.min")
nc.coefs <- coef(nc.fit, s = nc.fit$lambda[3:5])
nc.preds <- predict(nc.fit, newx = tail(x), s = fit$lambda[3:5])
cv.nc.coefs <- coef(cv.nc.fit, s = c(0.02, 0.03))
cv.nc.preds <- predict(cv.nc.fit, newx = x[50:60, ], s = "lambda.min")