glmnet_offset {offsetreg} | R Documentation |
Fit Penalized Generalized Linear Models with an Offset
Description
This function is a wrapper around glmnet::glmnet()
that uses a column from
x
as an offset.
Usage
glmnet_offset(
x,
y,
family,
offset_col = "offset",
weights = NULL,
lambda = NULL,
alpha = 1
)
Arguments
x |
Input matrix |
y |
Response variable |
family |
A function or character string describing the link function and error distribution. |
offset_col |
Character string. The name of a column in |
weights |
Optional weights to use in the fitting process. |
lambda |
A numeric vector of regularization penalty values |
alpha |
A number between zero and one denoting the proportion of L1 (lasso) versus L2 (ridge) regularization.
|
Details
Outside of the tidymodels
ecosystem, glmnet_offset()
has no advantages
over glmnet::glmnet()
since that function allows for offsets to be
specified in its offset
argument.
Within tidymodels
, glmnet_offset()
provides an advantage because it will
ensure that offsets are included in the data whenever resamples are created.
The x
, y
, family
, lambda
, alpha
and weights
arguments have the
same meanings as glmnet::glmnet()
. See that function's documentation for
full details.
Value
A glmnet
object. See glmnet::glmnet()
for full details.
See Also
Examples
us_deaths$off <- log(us_deaths$population)
x <- model.matrix(~ age_group + gender + off, us_deaths)[, -1]
glmnet_offset(x, us_deaths$deaths, family = "poisson", offset_col = "off")