glmnet(x, y, family=c("gaussian","binomial","multinomial"), weights, alpha = 1,
nlambda = 100, lambda.min = ifelse(nobs
"dgCMatrix"
as in package Matrix
)family="gaussian"
. For family="binomial"
should be either a factor with two levels, or a two-column matrix of counts or proportions. For family="multinomial"
, can be a nc>=2<
alpha=1
is the lasso penalty; Currently alpha<0.01< code=""> not reliable,
unless you supply 0.01<>
\alpha\le>
lambda
values - default is 100.lambda
, as a fraction of
lambda.max
, the (data derived) entry value (i.e. the smallest
value for which all coefficients are zero). The default depends on the
sample size nobs
relative to thlambda
sequence. Typical usage
is to have the
program compute its own lambda
sequence based on
nlambda
and lambda.min
. Supplying a value of
lambda
overrides standardize=TRUE
thresh
. Defaults value is 1E-4
.nvars
, if a partial path is desired.lambda
to allow
differential shrinkage. Can be 0 for some variables, which implies
no shrinkage, and that variable is always included in"binomial"
or "multinomial"
families. Default is 100."binomial"
or
"multinomial"
families.
If FALSE
(the default), an upper-bound approximation is made to the
hessian, which is not recalculated at each outer loop.family="gaussian"
. The default type="covariance"
saves all
inner-products ever computed, and can be much faster than
type="naive"
. The latter can be more effic"glmnet","*"
, where "*"
is
"elnet"
, "lognet"
or
"multnet"
for the three types of models.length(lambda)
"elnet"
and "lognet"
models, a nvars x
length(lambda)
matrix of coefficients, stored in sparse column
format ("dgCMatrix"
). For "multnet"
, a list of nc
such
matrices, one for each class.lambda
values used"elnet"
, this
is the R-square).lambda
. For "multnet"
, this is the number of variables
with a nonzero coefficient for any class."multnet"
only. A matrix consisting of the
number of nonzero coefficients per classlambda
is fit by coordinate
descent. For family="gaussian"
this is the lasso sequence if
alpha=1
, else it is the elasticnet sequence.
For family="binomial"
or family="multinomial"
, this is a lasso or elasticnet regularization path
for fitting the linear logistic or multinomial logistic regression
paths. Sometimes the sequence is truncated before nlambda
values of lambda
have been used, because of instabilities in
the logistic or multinomial models near a saturated fit. glmnet(...,family="binomial")
fits a traditional logistic regression model for the
log-odds. glmnet(...,family="multinomial")
fits a symmetric multinomial model, where
each class is represented by a linear model (on the log-scale). The
penalties take care of redundancies. A two-class "multinomial"
model
will produce the same fit as the corresponding "binomial"
model,
except the pair of coefficient matrices will be equal in magnitude and
opposite in sign, and half the "binomial"
values.
Note that the objective function for "gaussian"
is $$1/(2*nobs)RSS + \lambda*penalty$$, and for the logistic models it is $$1/nobs -loglik + \lambda*penalty$$print
, predict
and coef
methods.x=matrix(rnorm(100*20),100,20)
y=rnorm(100)
g2=sample(1:2,100,replace=TRUE)
g4=sample(1:4,100,replace=TRUE)
fit1=glmnet(x,y)
print(fit1)
coef(fit1,s=0.01) # extract coefficients at a single value of lambda
predict(fit1,newx=x[1:10,],s=c(0.01,0.005)) # make predictions
fit2=glmnet(x,g2,family="binomial")
fit3=glmnet(x,g4,family="multinomial")
Run the code above in your browser using DataCamp Workspace