Title: | A Fast Algorithm for Kernel Quantile Regression |
---|---|
Description: | An efficient algorithm to fit and tune kernel quantile regression models based on the majorization-minimization (MM) method. It can also fit multiple quantile curves simultaneously without crossing. |
Authors: | Qian Tang [aut, cre], Yuwen Gu [aut], Boxiang Wang [aut] |
Maintainer: | Qian Tang <[email protected]> |
License: | GPL-2 |
Version: | 1.0.0 |
Built: | 2024-11-10 06:43:37 UTC |
Source: | CRAN |
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 [kqr()] object. |
s |
Value(s) of the penalty parameter 'lambda' at which coefficients are required. Default is the entire sequence. |
... |
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()].
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG lambda <- 10^(seq(1, -4, length.out=10)) fit <- kqr(x, y, lambda=lambda, tau=0.1) coef(fit)
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG lambda <- 10^(seq(1, -4, length.out=10)) fit <- kqr(x, y, lambda=lambda, tau=0.1) coef(fit)
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 'lambda1' at which coefficients are required. Default is the entire sequence used to create the model. |
s2 |
Value of the penalty parameter 'lambda2' at which coefficients are required. |
... |
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()].
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG l2 <- 1e-4 ttau <- c(0.1, 0.3, 0.5, 0.7, 0.9) l1_list <- 10^seq(-8, 2, length.out=10) fit <- nckqr(x,y, lambda1=l1_list, lambda2=l2, tau=ttau) coef(fit, s1=l1_list[1:3], s2=1e-4)
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG l2 <- 1e-4 ttau <- c(0.1, 0.3, 0.5, 0.7, 0.9) l1_list <- 10^seq(-8, 2, length.out=10) fit <- nckqr(x,y, lambda1=l1_list, lambda2=l2, tau=ttau) coef(fit, s1=l1_list[1:3], s2=1e-4)
Performs k-fold cross-validation for [kqr()]. This function is largely similar [glmnet::cv.glmnet()].
cv.kqr(x, y, tau, lambda = NULL, sigma = NULL, nfolds = 5L, foldid, ...)
cv.kqr(x, y, tau, lambda = NULL, sigma = NULL, nfolds = 5L, foldid, ...)
x |
A numerical input matrix. The dimension is |
y |
Response variable. |
tau |
A user-supplied |
lambda |
A user-supplied |
sigma |
Kernel bandwidth. |
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, |
... |
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 |
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG lambda <- 10^(seq(1, -4, length.out=10)) cv.fit <- cv.kqr(x, y, lambda=lambda, tau=0.1)
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG lambda <- 10^(seq(1, -4, length.out=10)) cv.fit <- cv.kqr(x, y, lambda=lambda, tau=0.1)
Performs k-fold cross-validation for [nckqr()]. This function is largely similar [glmnet::cv.glmnet()].
cv.nckqr( x, y, tau, lambda1 = NULL, lambda2 = NULL, sigma = NULL, nfolds = 5L, foldid, ... )
cv.nckqr( x, y, tau, lambda1 = NULL, lambda2 = NULL, sigma = NULL, nfolds = 5L, foldid, ... )
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. |
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, |
... |
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 |
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG ttau <- c(0.1, 0.3, 0.5) l2_list <- 10^(seq(1, -4, length.out=10)) cvres <- cv.nckqr(x, y, ttau, lambda1 = 10, lambda2 = l2_list)
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG ttau <- c(0.1, 0.3, 0.5) l2_list <- 10^(seq(1, -4, length.out=10)) cvres <- cv.nckqr(x, y, ttau, lambda1 = 10, lambda2 = l2_list)
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, is_exact = FALSE )
kqr( x, y, lambda, tau, delta = 0.125, eps = 1e-05, maxit = 1e+06, gam = 1e-07, sigma = 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. |
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: |
.
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG lambda <- 10^(seq(1, -4, length.out=30)) fit <- kqr(x, y, lambda=lambda, tau=0.1, is_exact=TRUE)
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG lambda <- 10^(seq(1, -4, length.out=30)) fit <- kqr(x, y, lambda=lambda, tau=0.1, is_exact=TRUE)
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", 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", is_exact = FALSE )
x |
A numerical input matrix. The dimension is |
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. |
kernel |
Name of kernel function. Default is "Gaussian". |
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: |
.
library(MASS) lambda2 <- 1e-4 tau <- c(0.1, 0.3, 0.5, 0.7, 0.9) lambda1 <- 10^seq(-8, 2, length.out=10) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG fit <- nckqr(x ,y, lambda1 = lambda1 , lambda2 = lambda2, tau = tau)
library(MASS) lambda2 <- 1e-4 tau <- c(0.1, 0.3, 0.5, 0.7, 0.9) lambda1 <- 10^seq(-8, 2, length.out=10) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG fit <- nckqr(x ,y, lambda1 = lambda1 , lambda2 = lambda2, tau = tau)
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 'lambda' at which predictions are required. Default is the entire sequence used to create the model. |
... |
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.
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG lambda <- 10^(seq(1, -4, length.out=30)) fit <- kqr(x, y, lambda=lambda, tau=0.1, is_exact=TRUE) predict(fit, x, tail(x))
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG lambda <- 10^(seq(1, -4, length.out=30)) fit <- kqr(x, y, lambda=lambda, tau=0.1, is_exact=TRUE) predict(fit, x, tail(x))
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 'lambda2' at which predictions are required. |
s1 |
Value(s) of the penalty parameter 'lambda1' at which predictions are required. Default is the entire sequence used to create the model. |
... |
Not used. |
Returns the fitted values for the non-crossing kernel quantile regression model.
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG l2 <- 1e-4 ttau <- c(0.1, 0.3, 0.5, 0.7, 0.9) l1_list <- 10^seq(-8, 2, length.out=10) fit <- nckqr(x,y, lambda1=l1_list, lambda2=l2, tau=ttau) predict(fit, x, tail(x), s1=l1_list[1:3], s2=1e-4)
library(MASS) data(GAGurine) x <- as.matrix(GAGurine$Age) y <- GAGurine$GAG l2 <- 1e-4 ttau <- c(0.1, 0.3, 0.5, 0.7, 0.9) l1_list <- 10^seq(-8, 2, length.out=10) fit <- nckqr(x,y, lambda1=l1_list, lambda2=l2, tau=ttau) predict(fit, x, tail(x), s1=l1_list[1:3], s2=1e-4)