Computes the coefficients at the requested value(s) for lambda
from a
sparsegl()
object.
Usage
# S3 method for class 'sparsegl'
coef(object, s = NULL, ...)
Arguments
- object
Fitted
sparsegl()
object.- s
Value(s) of the penalty parameter
lambda
at which coefficients are required. Default is the entire sequence.- ...
Not used.
Details
s
is the new vector of lambda
values at which predictions are requested.
If s
is not in the lambda sequence used for fitting the model, the coef
function will use linear interpolation to make predictions. The new values
are interpolated using a fraction of coefficients from both left and right
lambda
indices.
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)
coef(fit1, s = c(0.02, 0.03))
#> 21 x 2 sparse Matrix of class "dgCMatrix"
#> s1 s2
#> (Intercept) 0.01260826 0.007013546
#> V1 4.91161061 4.809113387
#> V2 4.70205144 4.640598215
#> V3 4.73672003 4.572029571
#> V4 4.86000086 4.742085450
#> V5 4.76470639 4.691196254
#> V6 4.67390340 4.509768389
#> V7 -4.82460910 -4.674258142
#> V8 1.98354148 1.949724063
#> V9 0.06887575 0.106108315
#> V10 -0.13768353 -0.146588081
#> V11 -4.84355149 -4.748980429
#> V12 -4.70936925 -4.596326983
#> V13 -4.84370729 -4.742405135
#> V14 -4.81357902 -4.689338016
#> V15 -4.93502502 -4.864416765
#> V16 . .
#> V17 . .
#> V18 . .
#> V19 . .
#> V20 . .