View source: R/coef.autotune_lasso.R
| coef.autotune_lasso | R Documentation |
This function extracts the regression coefficients estimated by an autotune
lasso model, using the stored "autotune_lasso" object
## 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, ...)
object |
An |
intercept |
Logical; include the intercept term? If |
path |
Logical; if |
sparse |
Logical; controls the output format of |
... |
Other arguments to coef. |
a0 |
Intercept of the fitted autotune regression. Used only when |
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.