Computes time-dependent ROC curve for survival models using the `timeROC` package. Evaluates predictive accuracy at a specified time quantile.
Examples
if (requireNamespace("glmnet", quietly = TRUE) &&
requireNamespace("survival", quietly = TRUE) &&
requireNamespace("timeROC", quietly = TRUE)) {
library(survival)
dat <- na.omit(lung[, c("time", "status", "age", "sex", "ph.ecog")])
dat$status <- dat$status - 1
x <- as.matrix(dat[, c("age", "sex", "ph.ecog")])
y <- Surv(dat$time, dat$status)
fit <- glmnet::glmnet(x, y, family = "cox")
actual_outcome <- data.frame(time = dat$time, status = dat$status)
roc_info <- CalculateTimeROC(
model = fit, newx = x, s = 0.01, acture.y = actual_outcome,
modelname = "glmnet Cox Model", time_prob = 0.5
)
print(roc_info$AUC)
}
#> Warning: Starting in glmnet 5.1, the default Cox tie-handling method will change from 'breslow' to 'efron' (matching survival::coxph). To silence this message and lock in the v5.0 default, pass cox.ties = 'breslow' explicitly. To preview the v5.1 behavior, pass cox.ties = 'efron'.
#> t=0 t=259
#> NA 0.6791684