glmnetsurvcv: Cross-validation for glmnet survival models via glmnetsurv

View source: R/glmnetpostsurv.R

glmnetsurvcvR Documentation

Cross-validation for glmnet survival models via glmnetsurv

Description

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).

Usage

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,
  ...
)

Arguments

formula

Object of class formula describing the model. The response and terms are specified similar to Surv function.

data

optional data frame containing variables specified in the formula.

family

currently, only glmnet "cox" family (survival model) is allowed.

alpha

elasticnet mixing parameter, with 0 <= alpha <= 1. If a vector of alpha is supplied, cross-validation will be performed for each of the alpha and optimal value returned. The default is 1.

lambda

optional user supplied lambda sequence, cv.glmnet.

nfolds

number of folds. Default is 10.

foldid

an optional sequence of values between 1 and nfolds specifying what fold each observation is in. This is important when comparing performance across models. If specified, nfolds can be missing.

refit

logical. Whether to return solution path based on optimal lambda and alpha picked by the model. Default is refit = TRUE.

contrasts.arg

an optional list. See the contrasts.arg of [stats]{model.matrix.default}.

xlevs

a named list of character vectors giving the full set of levels to be assumed for each factor. See [stats]{model.frame}.

na.action

a function which indicates what should happen when the data contain NAs. See [stats]{model.frame}.

...

any of the options in cv.glmnet.

Details

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).

Value

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 1 standard error of the minimum.

alpha.optimal

optimal alpha corresponding to lambda.min.

lambdas.optimal

the sequence of lambdas containing lambda.min.

foldids

the fold assignment used.

dfs

list of data frames containing mean cross-validated error summaries and estimated coefficients in each fold.

fit

if refit = TRUE, summaries corresponding to the optimal alpha and lambdas. This is used to plot solution path

.

See Also

plot.glmnetsurvcv, glmnetsurvcv, cv.glmnet

Examples


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)


CYGUBICKO/glmnetpostsurv documentation built on Sept. 1, 2022, 7:26 p.m.