coef: Extract Coefficients for cv.grpnet and grpnet Fits

coefR Documentation

Extract Coefficients for cv.grpnet and grpnet Fits

Description

Obtain coefficients from a cross-validated group elastic net regularized GLM (cv.grpnet) or a group elastic net regularized GLM (grpnet) object.

Usage

## S3 method for class 'cv.grpnet'
coef(object, 
     s = c("lambda.1se", "lambda.min"),
     ...)
     
## S3 method for class 'grpnet'
coef(object, 
     s = NULL,
     ...)

Arguments

object

Object of class "cv.grpnet" or "grpnet"

s

Lambda value(s) at which predictions should be obtained. For "cv.grpnet" objects, default uses the 1se solution. For "grpnet" objects, default uses s = object$lambda. Interpolation is used for s values that are not included in object$lambda.

...

Additional arguments (ignored)

Details

coef.cv.grpnet:
Returns the coefficients that are used by the predict.cv.grpnet function to form predictions from a fit cv.grpnet object.

coef.grpnet:
Returns the coefficients that are used by the predict.grpnet function to form predictions from a fit grpnet object.

Value

For multinomial response variables, returns a list of length length(object$ylev), where the j-th element is a matrix of dimension c(ncoef, length(s)) giving the coefficients for object$ylev[j].

For other response variables, returns a matrix of dimension c(ncoef, length(s)), where the i-th column gives the coefficients for s[i].

Note

The syntax of these functions closely mimics that of the coef.cv.glmnet and coef.glmnet functions in the glmnet package (Friedman, Hastie, & Tibshirani, 2010).

Author(s)

Nathaniel E. Helwig <helwig@umn.edu>

References

Friedman, J., Hastie, T., & Tibshirani, R. (2010). Regularization paths for generalized linear models via coordinate descent. Journal of Statistical Software, 33(1), 1-22. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v033.i01")}

Helwig, N. E. (2024). Versatile descent algorithms for group regularization and variable selection in generalized linear models. Journal of Computational and Graphical Statistics. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/10618600.2024.2362232")}

See Also

print.coef.grpnet for printing coef.grpnet objects

predict.cv.grpnet for predicting from cv.grpnet objects

predict.grpnet for predicting from grpnet objects

Examples

######***######   grpnet   ######***######

# load data
data(auto)

# fit model (formula method, response = mpg)
mod <- grpnet(mpg ~ ., data = auto)

# extract coefs for regularization path (output = 12 x 100 matrix)
coef(mod)

# extract coefs at 3 particular points (output = 12 x 3 matrix)
coef(mod, s = c(1.5, 1, 0.5))


######***######   cv.grpnet   ######***######

# load data
data(auto)

# 5-fold cv (formula method, response = mpg)
set.seed(1)
mod <- cv.grpnet(mpg ~ ., data = auto, nfolds = 5, alpha = 1)

# extract coefs for "min" solution (output = 12 x 1 matrix)
coef(mod)

# extract coefs for "1se" solution (output = 12 x 1 matrix)
coef(mod, s = "lambda.1se")

# extract coefs at 3 particular points (output = 12 x 3 matrix)
coef(mod, s = c(1.5, 1, 0.5))

grpnet documentation built on Oct. 12, 2024, 1:07 a.m.

Related to coef in grpnet...