Learn R Programming

hdqr (version 1.0.2)

predict.cv.nc.hdqr: Make Predictions from a cv.nc.hdqr Object

Description

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.

Usage

# S3 method for cv.nc.hdqr
predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)

Value

Returns a matrix or vector of predicted values corresponding to the specified `lambda` values.

Arguments

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.

See Also

cv.nc.hdqr, predict.cv.nc.hdqr

Examples

Run this code
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")

Run the code above in your browser using DataLab