Title: | Fast Algorithm for Penalized Quantile Regression |
---|---|
Description: | Implements an efficient algorithm to fit and tune penalized quantile regression models using the generalized coordinate descent algorithm. Designed to handle high-dimensional datasets effectively, with emphasis on precision and computational efficiency. This package implements the algorithms proposed in Tang, Q., Zhang, Y., & Wang, B. (2022) <https://openreview.net/pdf?id=RvwMTDYTOb>. |
Authors: | Qian Tang [aut, cre], Yikai Zhang [aut], Boxiang Wang [aut] |
Maintainer: | Qian Tang <[email protected]> |
License: | GPL-2 |
Version: | 1.0.1 |
Built: | 2025-02-12 20:24:08 UTC |
Source: | CRAN |
Retrieves coefficients from a cross-validated 'hdqr()' model, using the stored '"hdqr.fit"' object and the optimal 'lambda' value determined during cross-validation.
## S3 method for class 'cv.hdqr' coef(object, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.hdqr' coef(object, s = c("lambda.1se", "lambda.min"), ...)
object |
A fitted 'cv.hdqr()' object from which coefficients are to be extracted. |
s |
Specifies the value(s) of the penalty parameter 'lambda' for which coefficients are desired. The default is 's = "lambda.1se"', which corresponds to the largest value of 'lambda' such that the cross-validation error estimate is within one standard error of the minimum. Alternatively, 's = "lambda.min"' can be used, corresponding to the minimum of the cross-validation error estimate. If 's' is numeric, these are taken as the actual values of 'lambda' to use. |
... |
Not used. |
Returns the coefficients at the specified 'lambda' values.
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 cv.fit <- cv.hdqr(x = x, y = y, tau = tau, lam2 = lam2) coef(cv.fit, s = c(0.02, 0.03))
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 cv.fit <- cv.hdqr(x = x, y = y, tau = tau, lam2 = lam2) coef(cv.fit, s = c(0.02, 0.03))
Retrieves coefficients at specified values of 'lambda' from a fitted 'cv.nc.hdqr()' model. Utilizes the stored '"nchdqr.fit"' object and the optimal 'lambda' values determined during the cross-validation process.
## S3 method for class 'cv.nc.hdqr' coef(object, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.nc.hdqr' coef(object, s = c("lambda.1se", "lambda.min"), ...)
object |
A fitted 'cv.nc.hdqr()' object from which coefficients are to be extracted. |
s |
Specifies the 'lambda' values at which coefficients are requested. The default is 's = "lambda.1se"', representing the largest 'lambda' such that the cross-validation error estimate is within one standard error of the minimum. Alternatively, 's = "lambda.min"' corresponds to the 'lambda' yielding the minimum cross-validation error. If 's' is numeric, these values are directly used as the 'lambda' values for coefficient extraction. |
... |
Not used. |
Returns a vector or matrix of coefficients corresponding to the specified 'lambda' values.
cv.nc.hdqr
, predict.cv.nc.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 tau <- 0.5 lam2 <- 0.01 lambda <- 10^(seq(1,-4, length.out=30)) cv.nc.fit <- cv.nc.hdqr(x = x, y = y, tau = tau, lambda = lambda, lam2 = lam2) coef(cv.nc.fit, s = c(0.02, 0.03))
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 lambda <- 10^(seq(1,-4, length.out=30)) cv.nc.fit <- cv.nc.hdqr(x = x, y = y, tau = tau, lambda = lambda, lam2 = lam2) coef(cv.nc.fit, s = c(0.02, 0.03))
Retrieves the coefficients at specified values of 'lambda' from a fitted 'hdqr()' model.
## S3 method for class 'hdqr' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
## S3 method for class 'hdqr' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
object |
Fitted 'hdqr()' object. |
s |
Values of the penalty parameter 'lambda' for which coefficients are requested. Defaults to the entire sequence used during the model fit. |
type |
Type of prediction required. Type '"coefficients"' computes the coefficients at the requested
values for 's'. Type '"nonzero"' returns a list of the indices of the nonzero coefficients for each
value of |
... |
Not used. |
This function extracts coefficients for specified 'lambda' values from a 'hdqr()' object. If 's', the vector of 'lambda' values, contains values not originally used in the model fitting, the 'coef' function employs linear interpolation between the closest 'lambda' values from the original sequence to estimate coefficients at the new 'lambda' values.
Returns a matrix or vector of coefficients corresponding to the specified 'lambda' values.
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) coefs <- coef(fit, s = fit$lambda[3:5])
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) coefs <- coef(fit, s = fit$lambda[3:5])
Retrieves the coefficients at specified values of 'lambda' from a fitted 'nc.hdqr()' model.
## S3 method for class 'nc.hdqr' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
## S3 method for class 'nc.hdqr' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
object |
Fitted 'nc.hdqr()' object. |
s |
Values of the penalty parameter 'lambda' for which coefficients are requested. Defaults to the entire sequence used during the model fit. |
type |
Type of prediction required. Type '"coefficients"' computes the coefficients at the requested
values for 's'. Type '"nonzero"' returns a list of the indices of the nonzero coefficients for each
value of |
... |
Not used. |
This function extracts coefficients for specified 'lambda' values from a 'nc.hdqr()' object. If 's', the vector of 'lambda' values, contains values not originally used in the model fitting, the 'coef' function employs linear interpolation between the closest 'lambda' values from the original sequence to estimate coefficients at the new 'lambda' values.
Returns a matrix or vector of coefficients corresponding to the specified 'lambda' values.
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 lambda <- 10^(seq(1,-4, length.out=30)) nc.fit <- nc.hdqr(x=x, y=y, tau=tau, lambda=lambda, lam2=lam2, pen="scad") nc.coefs <- coef(nc.fit, s = nc.fit$lambda[3:5])
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 lambda <- 10^(seq(1,-4, length.out=30)) nc.fit <- nc.hdqr(x=x, y=y, tau=tau, lambda=lambda, lam2=lam2, pen="scad") nc.coefs <- coef(nc.fit, s = nc.fit$lambda[3:5])
Performs k-fold cross-validation for hdqr
.
cv.hdqr(x, y, lambda = NULL, tau, nfolds = 5L, foldid, ...)
cv.hdqr(x, y, lambda = NULL, tau, nfolds = 5L, foldid, ...)
x |
A numerical matrix with |
y |
Response variable. |
lambda |
Optional; a user-supplied sequence of |
tau |
Quantile level ( |
nfolds |
Number of folds for cross-validation. Defaults to 5. |
foldid |
Optional vector specifying the indices of observations in each fold.
If provided, it overrides |
... |
Additional arguments passed to |
This function computes the average cross-validation error and provides the standard error.
An object with S3 class cv.hdqr
consisting of
lambda |
Candidate |
cvm |
Mean cross-validation error. |
cvsd |
Standard error of the mean cross-validation error. |
cvup |
Upper confidence curve: |
cvlo |
Lower confidence curve: |
lambda.min |
|
lambda.1se |
Largest |
cv.min |
Cross-validation error at |
cv.1se |
Cross-validation error at |
hdqr.fit |
a fitted |
nzero |
Number of non-zero coefficients at each |
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 cv.fit <- cv.hdqr(x = x, y = y, tau = tau)
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 cv.fit <- cv.hdqr(x = x, y = y, tau = tau)
Conducts k-fold cross-validation for the 'nc.hdqr()' function.
cv.nc.hdqr(x, y, lambda = NULL, tau, nfolds = 5L, foldid, ...)
cv.nc.hdqr(x, y, lambda = NULL, tau, nfolds = 5L, foldid, ...)
x |
A numerical matrix with dimensions ( |
y |
Response variable. |
lambda |
Optional user-supplied sequence of |
tau |
The quantile level ( |
nfolds |
Number of folds in the cross-validation, default is 5. |
foldid |
An optional vector that assigns each observation to a specific fold.
If provided, this parameter overrides |
... |
Additional arguments passed to |
This function estimates the average cross-validation error and its standard error across folds. It is primarily used to
identify the optimal lambda
value for fitting nonconvex penalized quantile regression models.
An object of class cv.nc.hdqr
is returned,
which is a list with the ingredients of the cross-validated fit.
lambda |
the values of |
cvm |
the mean cross-validated error - a vector of length |
cvsd |
estimate of standard error of |
cvupper |
upper curve = |
cvlower |
lower curve = |
nzero |
number of non-zero coefficients at each |
name |
a text string indicating type of measure (for plotting purposes). |
nchdqr.fit |
a fitted |
lambda.min |
The optimal value of |
lambda.1se |
The largest value of |
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 lambda <- 10^(seq(1,-4, length.out=10)) cv.nc.fit <- cv.nc.hdqr(y=y, x=x, tau=tau, lambda=lambda, lam2=lam2, pen="scad")
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 lambda <- 10^(seq(1,-4, length.out=10)) cv.nc.fit <- cv.nc.hdqr(y=y, x=x, tau=tau, lambda=lambda, lam2=lam2, pen="scad")
lambda
.Solve the linear quantile regression. The solution path is computed
at a grid of values of tuning parameter lambda
.
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 )
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 )
x |
Matrix of predictors, of dimension (nobs * nvars); each row is an observation. |
y |
Response variable. The length is |
tau |
The quantile level |
nlambda |
The number of |
lambda.factor |
The factor for getting the minimal value
in the |
lambda |
A user-supplied |
lam2 |
Regularization parameter |
hval |
The smoothing index for |
pf |
L1 penalty factor of length |
pf2 |
L2 penalty factor of length |
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 |
pmax |
The maximum number of coefficients allowed ever
to be nonzero along the solution path. For example, once
|
standardize |
Logical flag for variable standardization,
prior to fitting the model sequence. The coefficients are
always returned to the original scale. Default is |
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 |
Note that the objective function in the penalized quantile regression is
where the quantile or check loss
and the penalty is a combination of weighted L1 and L2 terms and
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
.
An object with S3 class hdqr
consisting of
call |
the call that produced this object |
b0 |
intercept sequence of length |
beta |
a |
lambda |
the actual sequence of |
df |
the number of nonzero coefficients for each value
of |
npasses |
the number of iterations for every lambda value |
jerr |
error flag, for warnings and errors, 0 if no error. |
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)
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)
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.
nc.hdqr( x, y, tau, lambda, pen = "scad", aval = NULL, lam2 = 1, ini_beta = NULL, lla_step = 3, ... )
nc.hdqr( x, y, tau, lambda, pen = "scad", aval = NULL, lam2 = 1, ini_beta = NULL, lla_step = 3, ... )
x |
Matrix of predictors, with dimensions (nobs * nvars); each row represents an observation. |
y |
Response variable, with length |
tau |
The quantile level |
lambda |
Optional user-supplied sequence of |
pen |
Specifies the type of nonconvex penalty: "SCAD" or "MCP". |
aval |
The parameter value for the SCAD or MCP penalty. Default is 3.7 for SCAD and 2 for MCP. |
lam2 |
Regularization parameter |
ini_beta |
Optional initial coefficients to start the fitting process. |
lla_step |
Number of Local Linear Approximation (LLA) steps. Default is 3. |
... |
Additional arguments passed to |
An object with S3 class nc.hdqr
consisting of
call |
the call that produced this object |
b0 |
intercept sequence of length |
beta |
a |
lambda |
the actual sequence of |
df |
the number of nonzero coefficients for each value
of |
npasses |
the number of iterations for every lambda value |
jerr |
error flag, for warnings and errors, 0 if no error. |
#'
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 lambda <- 10^(seq(1,-4, length.out=30)) nc.fit <- nc.hdqr(x=x, y=y, tau=tau, lambda=lambda, lam2=lam2, pen="scad")
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 lambda <- 10^(seq(1,-4, length.out=30)) nc.fit <- nc.hdqr(x=x, y=y, tau=tau, lambda=lambda, lam2=lam2, pen="scad")
Generates predictions using a fitted 'cv.hdqr()' object. This function utilizes the stored 'hdqr.fit' object and an optimal value of 'lambda' determined during the cross-validation process.
## S3 method for class 'cv.hdqr' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.hdqr' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
object |
A fitted 'cv.hdqr()' object from which predictions are to be made. |
newx |
Matrix of new predictor values for which predictions are desired. This must be a matrix and is a required argument. |
s |
Specifies the value(s) of the penalty parameter 'lambda' at which predictions are desired. The default is 's = "lambda.1se"', representing the largest value of 'lambda' such that the cross-validation error estimate is within one standard error of the minimum. Alternatively, 's = "lambda.min"' can be used, corresponding to the minimum of the cross-validation error estimate. If 's' is numeric, these are taken as the actual values of 'lambda' to use for predictions. |
... |
Not used. |
Returns a matrix or vector of predicted values corresponding to the specified 'lambda' values.
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 cv.fit <- cv.hdqr(x = x, y = y, tau = tau, lam2 = lam2) predict(cv.fit, newx = x[50:60, ], s = "lambda.min")
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 cv.fit <- cv.hdqr(x = x, y = y, tau = tau, lam2 = lam2) predict(cv.fit, newx = x[50:60, ], s = "lambda.min")
Generates predictions using a fitted 'cv.nc.hdqr()' object. This function utilizes the stored 'nchdqr.fit' object and an optimal value of 'lambda' determined during the cross-validation process.
## S3 method for class 'cv.nc.hdqr' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.nc.hdqr' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
object |
A fitted 'cv.nc.hdqr()' object from which predictions are to be made. |
newx |
Matrix of new predictor values for which predictions are desired. This must be a matrix and is a required argument. |
s |
Specifies the value(s) of the penalty parameter 'lambda' at which predictions are desired. The default is 's = "lambda.1se"', representing the largest value of 'lambda' such that the cross-validation error estimate is within one standard error of the minimum. Alternatively, 's = "lambda.min"' can be used, corresponding to the minimum of the cross-validation error estimate. If 's' is numeric, these are taken as the actual values of 'lambda' to use for predictions. |
... |
Not used. |
Returns a matrix or vector of predicted values corresponding to the specified 'lambda' values.
cv.nc.hdqr
, predict.cv.nc.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 tau <- 0.5 lam2 <- 0.01 lambda <- 10^(seq(1,-4, length.out=10)) cv.nc.fit <- cv.nc.hdqr(x = x, y = y, tau = tau, lambda = lambda, lam2 = lam2) predict(cv.nc.fit, newx = x[50:60, ], s = "lambda.min")
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 lambda <- 10^(seq(1,-4, length.out=10)) cv.nc.fit <- cv.nc.hdqr(x = x, y = y, tau = tau, lambda = lambda, lam2 = lam2) predict(cv.nc.fit, newx = x[50:60, ], s = "lambda.min")
Produces fitted values for new predictor data using a fitted 'hdqr()' object.
## S3 method for class 'hdqr' predict(object, newx, s = NULL, ...)
## S3 method for class 'hdqr' predict(object, newx, s = NULL, ...)
object |
Fitted 'hdqr()' object from which predictions are to be derived. |
newx |
Matrix of new predictor values for which predictions are desired. This must be a matrix and is a required argument. |
s |
Values of the penalty parameter 'lambda' for which predictions are requested. Defaults to the entire sequence used during the model fit. |
... |
Not used. |
This function generates predictions at specified 'lambda' values from a fitted 'hdqr()' object. It is essential to provide a new matrix of predictor values ('newx') at which these predictions are to be made.
Returns a vector or matrix of predicted values corresponding to the specified 'lambda' values.
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) preds <- predict(fit, newx = tail(x), s = fit$lambda[3:5])
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) preds <- predict(fit, newx = tail(x), s = fit$lambda[3:5])
Produces fitted values for new predictor data using a fitted 'nc.hdqr()' object.
## S3 method for class 'nc.hdqr' predict(object, newx, s = NULL, ...)
## S3 method for class 'nc.hdqr' predict(object, newx, s = NULL, ...)
object |
Fitted 'nc.hdqr()' object from which predictions are to be derived. |
newx |
Matrix of new predictor values for which predictions are desired. This must be a matrix and is a required argument. |
s |
Values of the penalty parameter 'lambda' for which predictions are requested. Defaults to the entire sequence used during the model fit. |
... |
Not used. |
This function generates predictions at specified 'lambda' values from a fitted 'nc.hdqr()' object. It is essential to provide a new matrix of predictor values ('newx') at which these predictions are to be made.
Returns a vector or matrix of predicted values corresponding to the specified 'lambda' values.
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 lambda <- 10^(seq(1,-4, length.out=30)) nc.fit <- nc.hdqr(x=x, y=y, tau=tau, lambda=lambda, lam2=lam2, pen="scad") nc.preds <- predict(nc.fit, newx = tail(x), s = nc.fit$lambda[3:5])
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 lambda <- 10^(seq(1,-4, length.out=30)) nc.fit <- nc.hdqr(x=x, y=y, tau=tau, lambda=lambda, lam2=lam2, pen="scad") nc.preds <- predict(nc.fit, newx = tail(x), s = nc.fit$lambda[3:5])