Fit a generalized linear model via penalized maximum likelihood for a single
value of lambda. Can deal with any GLM family. This version should be called if
x
is a sparse matrix.
spglmnet.fit(x, xm, xs, y, weights, lambda, alpha = 1, offset = rep(0,
nobs), family = gaussian(), intercept = TRUE, thresh = 1e-10,
maxit = 1e+05, penalty.factor = rep(1, nvars), exclude = c(),
lower.limits = -Inf, upper.limits = Inf, warm = NULL,
from.glmnet.path = FALSE, save.fit = FALSE, trace.it = 0)
Input matrix, of dimension nobs x nvars
; each row is an
observation vector.
Vector of length nvars
: xm(j)
is the centering factor
for variable j.
Vector of length nvars
: xs(j)
is the scaling factor
for variable j.
Quantitative response variable.
Observation weights. spglmnet.fit
does NOT standardize
these weights.
A single value for the lambda
hyperparameter.
The elasticnet mixing parameter, with \(0 \le \alpha \le 1\).
The penalty is defined as $$(1-\alpha)/2||\beta||_2^2+\alpha||\beta||_1.$$
alpha=1
is the lasso penalty, and alpha=0
the ridge penalty.
A vector of length nobs
that is included in the linear
predictor. Useful for the "poisson" family (e.g. log of exposure time), or
for refining a model by starting at a current fit. Default is NULL. If
supplied, then values must also be supplied to the predict
function.
A description of the error distribution and link function to be
used in the model. This is the result of a call to a family function. Default
is gaussian()
. (See family
for details on
family functions.)
Should intercept be fitted (default=TRUE) or set to zero (FALSE)?
Convergence threshold for coordinate descent. Each inner
coordinate-descent loop continues until the maximum change in the objective
after any coefficient update is less than thresh times the null deviance.
Default value is 1e-10
.
Maximum number of passes over the data; default is 10^5
.
(If a warm start object is provided, the number of passes the warm start object
performed is included.)
Separate penalty factors can be applied to each
coefficient. This is a number that multiplies lambda
to allow differential
shrinkage. Can be 0 for some variables, which implies no shrinkage, and that
variable is always included in the model. Default is 1 for all variables (and
implicitly infinity for variables listed in exclude). Note: the penalty
factors are internally rescaled to sum to nvars
.
Indices of variables to be excluded from the model. Default is none. Equivalent to an infinite penalty factor.
Vector of lower limits for each coefficient; default
-Inf
. Each of these must be non-positive. Can be presented as a single
value (which will then be replicated), else a vector of length nvars
.
Vector of upper limits for each coefficient; default
Inf
. See lower.limits
.
A glmnetfit
object which can be used as a warm start.
Default is NULL
, indicating no warm start. For internal use only.
Was spglmnet.fit()
called from glmnet.path()
?
Default is FALSE.This has implications for computation of the penalty factors.
Return the warm start object? Default is FALSE.
Controls how much information is printed to screen. If
trace.it=2
, some information about the fitting procedure is printed to
the console as the model is being fitted. Default is trace.it=0
(no information printed). (trace.it=1
not used for compatibility with
glmnet.path
.)
An object with class "glmnetfit" and "glmnet". The list returned contains more keys than that of an "glmnet" object.
Intercept value.
A nvars x 1
matrix of coefficients, stored in sparse matrix
format.
The number of nonzero coefficients.
Dimension of coefficient matrix.
Lambda value used.
The fraction of (null) deviance explained. The deviance calculations incorporate weights if present in the model. The deviance is defined to be 2*(loglike_sat - loglike), where loglike_sat is the log-likelihood for the saturated model (a model with a free parameter per observation). Hence dev.ratio=1-dev/nulldev.
Null deviance (per observation). This is defined to be 2*(loglike_sat -loglike(Null)). The null model refers to the intercept model.
Total passes over the data.
Error flag, for warnings and errors (largely for internal debugging).
A logical variable indicating whether an offset was included in the model.
The call that produced this object.
Number of observations.
If save.fit=TRUE
, output of FORTRAN routine, used for
warm starts. For internal use only.
Family used for the model.
A logical variable: was the algorithm judged to have converged?
A logical variable: is the fitted value on the boundary of the attainable values?
Objective function value at the solution.
WARNING: Users should not call spglmnet.fit
directly. Higher-level functions
in this package call spglmnet.fit
as a subroutine. If a warm start object
is provided, some of the other arguments in the function may be overriden.
spglmnet.fit
solves the elastic net problem for a single, user-specified
value of lambda. spglmnet.fit
works for any GLM family. It solves the
problem using iteratively reweighted least squares (IRLS). For each IRLS
iteration, spglmnet.fit
makes a quadratic (Newton) approximation of the
log-likelihood, then calls spelnet.fit
to minimize the resulting
approximation.
In terms of standardization: spglmnet.fit
does not standardize x
and weights
. penalty.factor
is standardized so that they sum up
to nvars
.