View source: R/get_lasso_coef.R
| get_lasso_coef | R Documentation |
Get cv.glmnet coefficient as a matrix or a tibble
get_lasso_coef(lassoObj, s = "lambda.min", tibble = FALSE)
lassoObj |
cv.glmnet object |
s |
CV-Lasso lambda |
tibble |
Default to FALSE |
A matrix or a tibble
set.seed(1)
n = 1000
p = 10
x = matrix(rnorm(n * p, mean = 0, sd = 1), nrow = n, ncol = p)
colnames(x) = paste0("X", 1:p)
k = 2
beta = c(rep(1, k), rep(0, p - k))
expit = function(x) 1/(1+exp(-x))
y = rbinom(n, 1, prob = expit(x %*% beta))
lassoObj = glmnet::cv.glmnet(x = x, y = y, family = "binomial")
get_lasso_coef(lassoObj = lassoObj, s = "lambda.min")
get_lasso_coef(lassoObj = lassoObj, s = "lambda.min", tibble = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.