View source: R/plot.autotune_lasso.R
| plot.autotune_lasso | R Documentation |
Plots for autotune_lasso objects
## S3 method for class 'autotune_lasso'
plot(x, max_preds = NULL, cumulative = TRUE, ...)
x |
Fitted |
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 |
cumulative |
Logical input. If TRUE, plots cumulative R-squared; if FALSE, plots adjusted R-squared. |
... |
Other graphical parameters to plot |
Invisibly returns a data frame with columns:
n_predictorsNumber of predictors included in the nested linear model.
predictor_indexIndex of the predictor added at each step.
has_nonzero_betaLogical value indicating whether the predictor added at each step has a non-zero coefficient.
r_squaredCumulative R-squared value.
adj_r_squaredAdjusted R-squared value.
autotune_lasso
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.