get_lasso_coef: Get cv.glmnet coefficient as a matrix or a tibble

View source: R/get_lasso_coef.R

get_lasso_coefR Documentation

Get cv.glmnet coefficient as a matrix or a tibble

Description

Get cv.glmnet coefficient as a matrix or a tibble

Usage

get_lasso_coef(lassoObj, s = "lambda.min", tibble = FALSE)

Arguments

lassoObj

cv.glmnet object

s

CV-Lasso lambda

tibble

Default to FALSE

Value

A matrix or a tibble

Examples

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)

kevinwang09/top documentation built on April 20, 2022, 3:01 a.m.