This function etracts coefficients from a
cross-validated sparsegl()
model, using the stored "sparsegl.fit"
object, and the optimal value chosen for lambda
.
Arguments
- object
Fitted
cv.sparsegl()
object.- s
Value(s) of the penalty parameter
lambda
at which coefficients are desired. Default is the single values = "lambda.1se"
stored in the CV object (corresponding to the largest value oflambda
such that CV error estimate is within 1 standard error of the minimum). Alternativelys = "lambda.min"
can be used (corresponding to the minimum of cross validation error estimate). Ifs
is numeric, it is taken as the value(s) oflambda
to be used.- ...
Not used.
Examples
n <- 100
p <- 20
X <- matrix(rnorm(n * p), nrow = n)
eps <- rnorm(n)
beta_star <- c(rep(5, 5), c(5, -5, 2, 0, 0), rep(-5, 5), rep(0, (p - 15)))
y <- X %*% beta_star + eps
groups <- rep(1:(p / 5), each = 5)
fit1 <- sparsegl(X, y, group = groups)
cv_fit <- cv.sparsegl(X, y, groups)
coef(cv_fit, s = c(0.02, 0.03))
#> 21 x 2 sparse Matrix of class "dgCMatrix"
#> s1 s2
#> (Intercept) 0.23832573 0.31515438
#> V1 4.70065228 4.61231894
#> V2 4.89000933 4.82578854
#> V3 4.78764378 4.70398207
#> V4 4.64572033 4.51399572
#> V5 4.64049673 4.47952627
#> V6 4.82997559 4.66365908
#> V7 -4.33582168 -4.11167381
#> V8 1.76136889 1.65380262
#> V9 0.02243789 0.05316397
#> V10 0.04610199 0.10186359
#> V11 -4.76159866 -4.65991534
#> V12 -4.90272249 -4.80827862
#> V13 -4.74953262 -4.56960092
#> V14 -4.94328922 -4.87745351
#> V15 -4.87918420 -4.78884130
#> V16 . .
#> V17 . .
#> V18 . .
#> V19 . .
#> V20 . .