Learn R Programming

survivalSL (version 0.98)

tuneCOXlasso: Tune Lasso Cox Regression

Description

This function finds the optimal lambda parameter for a Lasso Cox regression.

Usage

tuneCOXlasso(formula, data, penalty=NULL,
 cv=10, parallel=FALSE, lambda=NULL, seed=NULL)

Value

optimal

The value of lambda that gives the minimum cross-validated deviance.

results

The data frame with the cross-validated deviance for each lambda value.

Arguments

formula

A formula object, with the response on the left of a ~ operator, and the terms on the right. The response must be a survival object as returned by the Surv function.

data

A data frame for training the model with the same covariates as in the formula.

penalty

A numerical vector that allows the covariates not to be penalized. We give the value 0 if we do not want the covariate to be penalized otherwise 1. If NULL, all covariates are penalized.

cv

The value of the number of folds. The default value is 10.

parallel

If TRUE, use parallel foreach to fit each fold. The default is FALSE.

lambda

The values of the regularization parameter lambda optimized over.

seed

A random seed to ensure reproducibility during the cv process. If NULL, a seed is randomly assigned.

Details

The function runs the cv.glmnet function of the glmnet package.

References

Simon et al. (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/

Examples

Run this code
data("dataDIVAT2")

formula<-Surv(times,failures) ~ age + hla + retransplant + ecd

tune.model <- tuneCOXlasso(formula=formula, data=dataDIVAT2,
  cv=5, lambda=seq(0, 10, by=.1))

tune.model$optimal$lambda # the estimated lambda value

# The estimation of the training modelwith the corresponding lambda value
model <- LIB_COXlasso(formula, data=dataDIVAT2,
  lambda=tune.model$optimal$lambda)

# The resulted predicted survival of the first subject of the training sample
plot(y=model$predictions[1,], x=model$times, xlab="Time (years)",
ylab="Predicted survival", col=1, type="l", lty=1, lwd=2, ylim=c(0,1))

Run the code above in your browser using DataLab