View source: R/glmnetpostsurv.R
glmnetsurvcv | R Documentation |
Performs k
-fold cross-validation for glmnet
via glmnetsurvcv
, plots
solution path plots, and returns optimal value of lambda
(and optimal alpha if more than one is given).
glmnetsurvcv( formula = formula(data), data = sys.parent(), family = "cox", alpha = 1, lambda = NULL, nfolds = 10, foldid = NULL, refit = TRUE, contrasts.arg = NULL, xlevs = NULL, na.action = na.omit, ... )
formula |
Object of class formula describing
the model. The response and terms are specified
similar to |
data |
optional data frame containing variables specified in the formula. |
family |
currently, only |
alpha |
elasticnet mixing parameter, with
|
lambda |
optional user supplied lambda sequence, |
nfolds |
number of folds. Default is |
foldid |
an optional sequence of values between |
refit |
logical. Whether to return solution path based on optimal lambda and alpha picked by the model. Default is |
contrasts.arg |
an optional list. See
the contrasts.arg of
|
xlevs |
a named list of character vectors
giving the full set of levels to be assumed
for each factor. See |
na.action |
a function which indicates
what should happen when the data contain NAs.
See |
... |
any of the options in |
Performs cross-validation as illustrated in cv.glmnet
but has additional capability to support more than one alpha
.
If more than one alpha
is specified, say code(0.2, 0.5, 1), the glmnetsurvcv
will search for optimal values for alpha with respect to the corresponding lambda values. In this case, optimal alpha and lambda sequence will be returned, i.e., the (alpha, lambda)
pair that corresponds to the lowest predicted cross-validated error (likelihood deviance).
An S3 object of class glmnetsurvcv
:
lambda.min |
the value of lambda that gives minimum cross-validated error. |
lambda.1se |
largest value of lambda such that error is within |
alpha.optimal |
optimal alpha corresponding to |
lambdas.optimal |
the sequence of lambdas containing |
foldids |
the fold assignment used. |
dfs |
list of data frames containing mean cross-validated error summaries and estimated coefficients in each fold. |
fit |
if |
.
plot.glmnetsurvcv
, glmnetsurvcv
, cv.glmnet
data(veteran, package="survival") cv1 <- glmnetsurvcv(Surv(time, status) ~ factor(trt) + karno + diagtime + age + prior , data = veteran , alpha = 1 , refit = FALSE ) print(cv1) # Train model using optimal alpha and lambda fit1 <- glmnetsurv(Surv(time, status) ~ factor(trt) + karno + diagtime + age + prior , data = veteran , alpha = cv1$alpha.optimal , lambda = cv1$lambda.min ) print(fit1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.