predict.autotune_lasso: Predict from a autotune_lasso fit

View source: R/predict.autotune_lasso.R

predict.autotune_lassoR Documentation

Predict from a autotune_lasso fit

Description

Predict from a autotune_lasso fit

Usage

## S3 method for class 'autotune_lasso'
predict(
  object,
  newx = NULL,
  type = c("response", "coefficients"),
  path = NULL,
  ...
)

Arguments

object

An object of class autotune_lasso.

newx

Numeric matrix of new x (rows = observations, columns = predictors) at which predictions are required. This argument is not used for type="coefficients").

type

Character; one of "response", "coefficients".

path

For type = "coefficients", NULL returns the final coefficients and TRUE returns the full coefficient path. This argument is ignored for type = "response".

...

Further arguments passed from the generic.

Value

If type = "response", returns the prediction at the x provided for prediction.

If type = "coefficients", returns the fitted coefficients.

Examples

set.seed(10)
n = 300
p = 500
s = 10
beta = c(rep(1, s), rep(0, p - s))
x = matrix(rnorm(n * p), ncol = p)
# Maunal sigma allocation
# y = x %*% beta + rnorm(n, sd = 1)
# Dynamic sigma allocation with snr specified
snr = 2
y = x %*% beta + rnorm(n, sd = sqrt(var(x%*%beta)/snr))
fit <- autotune_lasso(x, y)
predict(fit, newx = x[1:5, , drop = FALSE])
predict(fit, type = "coefficients")

predict(fit, type = "coefficients", path = TRUE)


autotune documentation built on Aug. 21, 2026, 5:18 p.m.