Extract coefficients from a glmnet object
Similar to other predict methods, this functions predicts fitted values,
logits, coefficients and more from a fitted "glmnet" object.
## S3 method for class 'glmnet'
coef(object, s = NULL, exact = FALSE, ...)
## S3 method for class 'glmnet'
predict(
object,
newx,
s = NULL,
type = c("link", "response", "coefficients", "nonzero", "class"),
exact = FALSE,
newoffset,
...
)
## S3 method for class 'relaxed'
predict(
object,
newx,
s = NULL,
gamma = 1,
type = c("link", "response", "coefficients", "nonzero", "class"),
exact = FALSE,
newoffset,
...
)object |
Fitted |
s |
Value(s) of the penalty parameter |
exact |
This argument is relevant only when predictions are made at
values of |
... |
This is the mechanism for passing arguments like |
newx |
Matrix of new values for |
type |
Type of prediction required. Type |
newoffset |
If an offset is used in the fit, then one must be supplied
for making predictions (except for |
gamma |
Single value of |
The shape of the objects returned are different for "multinomial"
objects. This function actually calls NextMethod(), and the
appropriate predict method is invoked for each of the three model types.
coef(...) is equivalent to predict(type="coefficients",...)
The object returned depends on type.
Jerome Friedman, Trevor Hastie and Rob Tibshirani
Maintainer:
Trevor Hastie hastie@stanford.edu
Friedman, J., Hastie, T. and Tibshirani, R. (2008)
Regularization Paths for Generalized Linear Models via Coordinate
Descent, https://web.stanford.edu/~hastie/Papers/glmnet.pdf
Journal of Statistical Software, Vol. 33(1), 1-22 Feb 2010
https://www.jstatsoft.org/v33/i01/
Simon, N., Friedman, J., Hastie,
T., Tibshirani, R. (2011) Regularization Paths for Cox's Proportional
Hazards Model via Coordinate Descent, Journal of Statistical Software, Vol.
39(5) 1-13
https://www.jstatsoft.org/v39/i05/
glmnet, and print, and coef methods, and
cv.glmnet.
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) predict(fit1,newx=x[1:5,],s=c(0.01,0.005)) predict(fit1,type="coef") fit2=glmnet(x,g2,family="binomial") predict(fit2,type="response",newx=x[2:5,]) predict(fit2,type="nonzero") fit3=glmnet(x,g4,family="multinomial") predict(fit3,newx=x[1:3,],type="response",s=0.01)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.