Learn R Programming

hdqr (version 1.0.2)

predict.hdqr: Make Predictions from a hdqr Object

Description

Produces fitted values for new predictor data using a fitted hdqr object.

Usage

# S3 method for hdqr
predict(object, newx, s = NULL, ...)

Value

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

Arguments

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.

Details

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.

See Also

hdqr, coef.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
fit <- hdqr(x = x, y = y, tau = tau, lam2 = lam2)
preds <- predict(fit, newx = tail(x), s = fit$lambda[3:5])

Run the code above in your browser using DataLab