plot.autotune_lasso: Plots for autotune_lasso objects

View source: R/plot.autotune_lasso.R

plot.autotune_lassoR Documentation

Plots for autotune_lasso objects

Description

Plots for autotune_lasso objects

Usage

## S3 method for class 'autotune_lasso'
plot(x, max_preds = NULL, cumulative = TRUE, ...)

Arguments

x

Fitted "autotune_lasso" object.

max_preds

Integer input stating maximum number of predictors to include in the plot. Default NULL (then max_preds is calculated internally). Plotting R-squared involves running max_preds many linear models, in order to reduce the computation, use it with the value v when you want to check whether the dataset satisfies the sparsity assumption with \leq v many predictors or not.

cumulative

Logical input. If TRUE, plots cumulative R-squared; if FALSE, plots adjusted R-squared.

...

Other graphical parameters to plot

Value

Invisibly returns a data frame with columns:

n_predictors

Number of predictors included in the nested linear model.

predictor_index

Index of the predictor added at each step.

has_nonzero_beta

Logical value indicating whether the predictor added at each step has a non-zero coefficient.

r_squared

Cumulative R-squared value.

adj_r_squared

Adjusted R-squared value.

See Also

autotune_lasso

Examples


# Fit autotune lasso
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)

# Basic diagnostic plot
plot(fit)

# Plot adjusted R-squared for first 15 predictors
plot(fit, max_preds = 15, cumulative = FALSE)



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