GLMnet | R Documentation |
Fit glmnet models via a formula and a data set for use with predictRisk
.
GLMnet(
formula,
data,
lambda = NULL,
alpha = 1,
cv = TRUE,
nfolds = 10,
type.measure = "deviance",
selector = "min",
family,
...
)
formula |
Formula where the left hand side specifies either a single variable (continuous, binary or categorical),
or as a survival outcome (time, event), and the right hand side specifies the linear predictor.
Survival outcome can either be specified via Surv or via Hist.
Variables on the right hand side of the formula can be marked as |
data |
The data used to fit the model. |
lambda |
A hyperparameter passed to glmnet. If set to NULL, then lambda is chosen by cross-validation, via the function cv.glmnet |
alpha |
The elasticnet mixing parameter, with 0<=alpha<= 1. |
cv |
Whether to use cross-validation or not. Default is TRUE. |
nfolds |
Passed on to cv.glmnet. Number of folds for cross-validation. The default is 10. |
type.measure |
Passed on to cv.glmnet. Loss to use for cross-validation. Default is deviance. |
selector |
On of |
family |
Passed on to glmnet and cv.glmnet. For binary outcome the default is |
... |
Additional arguments that are passed on to glmnet and cv.glmnet. |
A glmnet object enhanced with the call, the terms to create the design matrix, and in the survival case with the Breslow estimate of the baseline hazard function.
glmnet
library(survival)
set.seed(8)
d <- sampleData(87,outcome="survival")
test <- sampleData(5,outcome="survival")
# penalized logistic regression
g <- GLMnet(X2~X1+X8,data=d)
predictRisk(g,newdata=test)
## Not run:
g1 <- GLMnet(X2~X1+X8,data=d,lambda=0,gamma=0.5)
g2 <- GLMnet(X2~X1+X8,data=d,relax=TRUE)
## End(Not run)
# penalized Cox regression
f0 <- GLMnet(Surv(time,event)~X1+X2+X8+X9,data=d,lambda=0)
predictRisk(f0,newdata=test,times=3)
f <- GLMnet(Surv(time,event)~X1+X2+X8+X9,data=d)
f
predictCox(f,newdata=test,times=5,product.limit=TRUE)
predictRisk(f,newdata=test,times=1)
f1 <- GLMnet(Surv(time,event)~X1+X2+unpenalized(X8)+X9,data=d)
predictRisk(f1,newdata=test,times=1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.