coef.autotune_lasso: Extract coefficients for autotune_lasso objects

View source: R/coef.autotune_lasso.R

coef.autotune_lassoR Documentation

Extract coefficients for autotune_lasso objects

Description

This function extracts the regression coefficients estimated by an autotune lasso model, using the stored "autotune_lasso" object

Usage

## S3 method for class 'autotune_lasso'
coef(object, intercept = TRUE, path = FALSE, sparse = TRUE, ...)

## S3 method for class 'autotune_lasso_path'
coef(object, intercept = TRUE, a0 = NULL, ...)

Arguments

object

An "autotune_lasso" object (for coef.autotune_lasso) or "autotune_lasso_path" object (for coef.autotune_lasso_path).

intercept

Logical; include the intercept term? If FALSE, the intercept row is omitted.

path

Logical; if TRUE, return the entire coefficient path across different lambdas.

sparse

Logical; controls the output format of coef.autotune_lasso() when path = FALSE. If TRUE, returns a sparse dgCMatrix (glmnet-style); if FALSE, returns a base numeric vector.

...

Other arguments to coef.

a0

Intercept of the fitted autotune regression. Used only when intercept = TRUE.

Value

  • coef.autotune_lasso(path = FALSE, sparse = TRUE) returns a sparse dgCMatrix of dimension (nvars + 1) \times 1 (or nvars \times 1 if intercept = FALSE).

  • coef.autotune_lasso(path = FALSE, sparse = FALSE) returns a named numeric vector.

  • coef.autotune_lasso(path = TRUE) calls coef.autotune_lasso_path(), which returns a sparse dgCMatrix of dimension (nvars + 1) \times (k + 1) (or nvars \times (k + 1) if intercept = FALSE), with columns named lambda_1, ..., lambda_k, final_lambda.

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)
coef(fit)                    # final solution
coef(fit, path = TRUE)        # coefficient path (sparse)


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