| Title: | A Fast Algorithm for Kernel Quantile Regression |
|---|---|
| Description: | Implements fast algorithms for kernel quantile regression and related models, including non-crossing kernel quantile regression and regularized linear quantile regression. The methods are described in Tang, Gu and Wang (2026) <doi:10.1080/10618600.2025.2541004>. |
| Authors: | Qian Tang [aut, cre], Yuwen Gu [aut], Boxiang Wang [aut] |
| Maintainer: | Qian Tang <[email protected]> |
| License: | GPL-2 |
| Version: | 1.0.1 |
| Built: | 2026-09-30 09:12:04 UTC |
| Source: | https://github.com/cran/fastkqr |
Extract Coefficients from a cv.fastlqr Object
## S3 method for class 'cv.fastlqr' coef(object, s = c("lambda.1se", "lambda.min"), ...)## S3 method for class 'cv.fastlqr' coef(object, s = c("lambda.1se", "lambda.min"), ...)
object |
A fitted |
s |
|
... |
Passed to |
A coefficient matrix.
Extract Coefficients from a fastlqr Object
## S3 method for class 'fastlqr' coef(object, s = NULL, ...)## S3 method for class 'fastlqr' coef(object, s = NULL, ...)
object |
A fitted |
s |
Optional lambda value(s). If omitted, all coefficients are returned. |
... |
Not used. |
A coefficient matrix with rows (Intercept) and predictors.
kqr object.Computes the coefficients at the requested value(s) for lambda from a
kqr() object.
## S3 method for class 'kqr' coef(object, s = NULL, ...)## S3 method for class 'kqr' coef(object, s = NULL, ...)
object |
Fitted |
s |
Value(s) of the penalty parameter |
... |
Not used. |
s is the new vector of lambda values at which predictions are requested.
If s is not in the lambda sequence used for fitting the model, the coef
function will use linear interpolation to make predictions. The new values
are interpolated using a fraction of coefficients from both left and right
lambda indices.
The coefficients at the requested values for lambda.
kqr() and predict.kqr().
set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) fit <- kqr(x, y, lambda = lambda, tau = 0.5) coef(fit)set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) fit <- kqr(x, y, lambda = lambda, tau = 0.5) coef(fit)
nckqr object.Computes the coefficients at the requested value(s) for lambda1 for a
given lambda2 from a nckqr() object.
## S3 method for class 'nckqr' coef(object, s1 = NULL, s2, ...)## S3 method for class 'nckqr' coef(object, s1 = NULL, s2, ...)
object |
A fitted |
s1 |
Value(s) of the penalty parameter |
s2 |
Value of the penalty parameter |
... |
Not used. |
s1 is the new vector of lambda1 values at which predictions are requested.
If s1 is not in the lambda sequence used for fitting the model, the coef
function will use linear interpolation to make predictions. The new values
are interpolated using a fraction of coefficients from both left and right
lambda indices.
The coefficients for the non-crossing kernel quantile regression model.
nckqr() and predict.nckqr().
set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) tau <- c(0.25, 0.5, 0.75) lambda1 <- 1 lambda2 <- 10^seq(0, -2, length.out = 3) fit <- nckqr(x, y, lambda1 = lambda1, lambda2 = lambda2, tau = tau) coef(fit, s1 = lambda1, s2 = lambda2[1])set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) tau <- c(0.25, 0.5, 0.75) lambda1 <- 1 lambda2 <- 10^seq(0, -2, length.out = 3) fit <- nckqr(x, y, lambda1 = lambda1, lambda2 = lambda2, tau = tau) coef(fit, s1 = lambda1, s2 = lambda2[1])
Performs k-fold cross-validation for kqr().
cv.kqr( x, y, tau, lambda = NULL, sigma = NULL, kernel = "rbfdot", nfolds = 5L, foldid, parallel = FALSE, ncores = max(1L, parallel::detectCores() - 1L), Kfull = NULL, ... )cv.kqr( x, y, tau, lambda = NULL, sigma = NULL, kernel = "rbfdot", nfolds = 5L, foldid, parallel = FALSE, ncores = max(1L, parallel::detectCores() - 1L), Kfull = NULL, ... )
x |
A numerical input matrix. The dimension is |
y |
Response variable. |
tau |
A user-supplied |
lambda |
A user-supplied |
sigma |
Kernel bandwidth parameter used by |
kernel |
Kernel function. Supported values are |
nfolds |
The number of folds in cross-validation. Default is 5. |
foldid |
An optional vector which indexed the observations into each
cross-validation fold. If supplied, |
parallel |
If |
ncores |
Number of worker processes used when |
Kfull |
Optional precomputed full |
... |
Additional arguments passed into |
The function computes the average cross-validation error and reports the standard error.
An object of class cv.kqr is returned, which is a
list with the components describing the cross-validation error.
lambda |
The |
cvm |
Mean cross-validation error. |
cvsd |
Estimates of standard error of cross-validation error. |
cvup |
The upper curve: |
cvlo |
The lower curve: |
lambda.min |
The |
lambda.1se |
The largest |
cv.min |
The cross-validation error at |
cv.1se |
The cross-validation error at |
set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) foldid <- rep(1:3, length.out = nrow(x)) cv.fit <- cv.kqr(x, y, lambda = lambda, tau = 0.5, foldid = foldid)set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) foldid <- rep(1:3, length.out = nrow(x)) cv.fit <- cv.kqr(x, y, lambda = lambda, tau = 0.5, foldid = foldid)
Performs k-fold cross-validation for nckqr().
cv.nckqr( x, y, tau, lambda1 = NULL, lambda2 = NULL, sigma = NULL, kernel = "rbfdot", nfolds = 5L, foldid, parallel = FALSE, ncores = max(1L, parallel::detectCores() - 1L), Kfull = NULL, ... )cv.nckqr( x, y, tau, lambda1 = NULL, lambda2 = NULL, sigma = NULL, kernel = "rbfdot", nfolds = 5L, foldid, parallel = FALSE, ncores = max(1L, parallel::detectCores() - 1L), Kfull = NULL, ... )
x |
A numerical input matrix. The dimension is |
y |
Response variable. |
tau |
A user-supplied |
lambda1 |
A user-supplied |
lambda2 |
A user-supplied |
sigma |
Kernel bandwidth parameter used by |
kernel |
Kernel function. Supported values are |
nfolds |
The number of folds in cross-validation. Default is 5. |
foldid |
An optional vector which indexed the observations into each
cross-validation fold. If supplied, |
parallel |
If |
ncores |
Number of worker processes used when |
Kfull |
Optional precomputed full |
... |
Additional arguments passed into |
The function computes the average cross-validation error and reports the standard error.
An object of class cv.nckqr is returned, which is a
list with the components describing the cross-validation error.
lambda2 |
The |
cvm |
Mean cross-validation error. |
cvsd |
Estimates of standard error of cross-validation error. |
cvup |
The upper curve: |
cvlo |
The lower curve: |
lambda.min |
The |
lambda.1se |
The largest |
cv.min |
The cross-validation error at |
cv.1se |
The cross-validation error at |
set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) foldid <- rep(1:3, length.out = nrow(x)) cvres <- cv.nckqr(x, y, tau = c(0.25, 0.5, 0.75), lambda1 = 1, lambda2 = lambda, foldid = foldid)set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) foldid <- rep(1:3, length.out = nrow(x)) cvres <- cv.nckqr(x, y, tau = c(0.25, 0.5, 0.75), lambda1 = 1, lambda2 = lambda, foldid = foldid)
Selects the ridge penalty for qr() by K-fold cross-validation.
cv.qr( x, y, lambda, tau = 0.5, nfolds = 5L, foldid = NULL, delta = 0.125, eps = 1e-05, maxit = 1e+06, gam = 1e-07, is_exact = FALSE, standardize = FALSE, keep.x = FALSE, parallel = FALSE, ncores = max(1L, parallel::detectCores() - 1L), ... )cv.qr( x, y, lambda, tau = 0.5, nfolds = 5L, foldid = NULL, delta = 0.125, eps = 1e-05, maxit = 1e+06, gam = 1e-07, is_exact = FALSE, standardize = FALSE, keep.x = FALSE, parallel = FALSE, ncores = max(1L, parallel::detectCores() - 1L), ... )
x |
Numeric predictor matrix. |
y |
Numeric response vector. |
lambda |
Positive ridge penalty sequence. |
tau |
Single quantile level in |
nfolds |
Number of folds. |
foldid |
Optional fold assignments. |
delta |
Smoothing parameter passed to |
eps |
Stopping criterion passed to |
maxit |
Maximum iterations passed to |
gam |
Numerical ridge passed to |
is_exact |
Whether to use exact projection in |
standardize |
Standardization is not implemented; must be |
keep.x |
Whether to store training |
parallel |
Parallel CV is not implemented for this first version. |
ncores |
Reserved for future parallel CV support. |
... |
Compatibility arguments. |
An object of class cv.fastlqr.
lambda.Solve the kernel quantile regression. The solution path is computed
at a grid of values of tuning parameter lambda.
kqr( x, y, lambda, tau, delta = 0.125, eps = 1e-05, maxit = 1e+06, gam = 1e-07, sigma = NULL, kernel = "rbfdot", Kmat = NULL, is_exact = FALSE )kqr( x, y, lambda, tau, delta = 0.125, eps = 1e-05, maxit = 1e+06, gam = 1e-07, sigma = NULL, kernel = "rbfdot", Kmat = NULL, is_exact = FALSE )
x |
A numerical input matrix. The dimension is |
y |
Response variable. The length is |
lambda |
A user-supplied |
tau |
A user-supplied |
delta |
The smoothing index for |
eps |
Stopping criterion. |
maxit |
Maximum number of iterates. |
gam |
A small number for numerical stability. |
sigma |
Kernel bandwidth parameter used by |
kernel |
Kernel function. Supported values are |
Kmat |
Optional precomputed training kernel matrix. If supplied, it is
reused instead of recomputing |
is_exact |
Exact or approximated solutions. Default is |
The function implements an accelerated proximal gradient descent to solve kernel quantile regression.
An object with S3 class kqr
alpha |
An |
lambda |
The |
delta |
The smoothing index. |
npass |
The total number of iterates used to train the classifier. |
jerr |
Warnings and errors; 0 if none. |
info |
A list includes some settings used to fit this object: |
.
set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) fit <- kqr(x, y, lambda = lambda, tau = 0.5)set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) fit <- kqr(x, y, lambda = lambda, tau = 0.5)
Trains the kernel quantile regression
nckqr( x, y, lambda1, lambda2, tau, delta = 0.125, eps = 1e-08, maxit = 5e+06, gam = 1e-07, sigma = NULL, kernel = "rbfdot", Kmat = NULL, is_exact = FALSE )nckqr( x, y, lambda1, lambda2, tau, delta = 0.125, eps = 1e-08, maxit = 5e+06, gam = 1e-07, sigma = NULL, kernel = "rbfdot", Kmat = NULL, is_exact = FALSE )
x |
A numerical input matrix with |
y |
Response variable. The length is |
lambda1 |
A user-supplied |
lambda2 |
A user-supplied |
tau |
A user-supplied |
delta |
The smoothing index for |
eps |
Stopping criterion. |
maxit |
Maximum number of iterates. |
gam |
A small number for numerical stability. |
sigma |
Kernel bandwidth parameter used by |
kernel |
Kernel function. Supported values are |
Kmat |
Optional precomputed training kernel matrix. If supplied, it is
reused instead of recomputing |
is_exact |
Exact or approximated solutions. |
The function implements the majorization-minimization method to solve non-crossing kernel quantile regression.
An object with S3 class nckqr
alpha |
An |
tau |
The |
lambda1 |
The |
lambda2 |
The |
delta |
The smoothing index. |
npass |
The total number of iterates used to train the classifier. |
jerr |
Warnings and errors; 0 if none. |
info |
A list includes some settings used to fit this object: |
.
set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) tau <- c(0.25, 0.5, 0.75) lambda1 <- 1 lambda2 <- 10^seq(0, -2, length.out = 3) fit <- nckqr(x, y, lambda1 = lambda1, lambda2 = lambda2, tau = tau)set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) tau <- c(0.25, 0.5, 0.75) lambda1 <- 1 lambda2 <- 10^seq(0, -2, length.out = 3) fit <- nckqr(x, y, lambda1 = lambda1, lambda2 = lambda2, tau = tau)
Predict from a cv.fastlqr Object
## S3 method for class 'cv.fastlqr' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)## S3 method for class 'cv.fastlqr' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
object |
A fitted |
newx |
New predictor matrix. |
s |
|
... |
Passed to |
A matrix of fitted linear quantiles.
Predict from a fastlqr Object
## S3 method for class 'fastlqr' predict(object, newx, s = NULL, ...)## S3 method for class 'fastlqr' predict(object, newx, s = NULL, ...)
object |
A fitted |
newx |
New predictor matrix. If omitted, training data are used when
the model was fit with |
s |
Optional lambda value(s). |
... |
Not used. |
A matrix of fitted linear quantiles.
kqr object.Predict the fitted values for a kqr object.
## S3 method for class 'kqr' predict(object, x, newx = NULL, s = NULL, ...)## S3 method for class 'kqr' predict(object, x, newx = NULL, s = NULL, ...)
object |
A fitted |
x |
The predictor matrix, i.e., the |
newx |
A matrix of new values for |
s |
Value(s) of the penalty parameter |
... |
Not used. |
The result is where and are from the
kqr object and is the ith row of the kernel matrix.
Returns the fitted values.
set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) fit <- kqr(x, y, lambda = lambda, tau = 0.5) predict(fit, x, x[1:5, , drop = FALSE])set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) fit <- kqr(x, y, lambda = lambda, tau = 0.5) predict(fit, x, x[1:5, , drop = FALSE])
nckqr object.Predict the fitted values for a nckqr object.
## S3 method for class 'nckqr' predict(object, x, newx = NULL, s2, s1 = NULL, ...)## S3 method for class 'nckqr' predict(object, x, newx = NULL, s2, s1 = NULL, ...)
object |
A fitted |
x |
The predictor matrix, i.e., the |
newx |
A matrix of new values for |
s2 |
Value of the penalty parameter |
s1 |
Value(s) of the penalty parameter |
... |
Not used. |
Returns the fitted values for the non-crossing kernel quantile regression model.
set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) tau <- c(0.25, 0.5, 0.75) lambda1 <- 1 lambda2 <- 10^seq(0, -2, length.out = 3) fit <- nckqr(x, y, lambda1 = lambda1, lambda2 = lambda2, tau = tau) predict(fit, x, x[1:5, , drop = FALSE], s1 = lambda1, s2 = lambda2[1])set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) tau <- c(0.25, 0.5, 0.75) lambda1 <- 1 lambda2 <- 10^seq(0, -2, length.out = 3) fit <- nckqr(x, y, lambda1 = lambda1, lambda2 = lambda2, tau = tau) predict(fit, x, x[1:5, , drop = FALSE], s1 = lambda1, s2 = lambda2[1])
Fits a parametric linear quantile regression path
.
qr( x, y, lambda, tau = 0.5, delta = 0.125, eps = 1e-05, maxit = 1e+06, gam = 1e-07, is_exact = FALSE, standardize = FALSE, intercept = TRUE, keep.x = FALSE, ... )qr( x, y, lambda, tau = 0.5, delta = 0.125, eps = 1e-05, maxit = 1e+06, gam = 1e-07, is_exact = FALSE, standardize = FALSE, intercept = TRUE, keep.x = FALSE, ... )
x |
Numeric predictor matrix. |
y |
Numeric response vector. |
lambda |
Positive ridge penalty sequence. |
tau |
Single quantile level in |
delta |
Smoothing parameter used by the Fortran solver. |
eps |
Stopping criterion. |
maxit |
Maximum number of iterations. |
gam |
Small ridge added internally for numerical stability. |
is_exact |
Whether to run the exact projection path. |
standardize |
Standardization is not implemented; must be |
intercept |
Intercept is required by |
keep.x |
If |
... |
Compatibility arguments. |
The objective is
The intercept is not penalized. This function masks base::qr(); use
base::qr() when QR decomposition is needed. This parametric linear
model is the supported path for linear quantile regression; kernel methods
kqr() and nckqr() no longer support kernel = "lineardot".
An object of class fastlqr.
set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) fit <- qr(x, y, lambda = lambda, tau = 0.5) predict(fit, x[1:5, , drop = FALSE])set.seed(1) x <- matrix(rnorm(60), 30, 2) y <- x[, 1] + rnorm(30) lambda <- 10^seq(0, -2, length.out = 3) fit <- qr(x, y, lambda = lambda, tau = 0.5) predict(fit, x[1:5, , drop = FALSE])