Skip to contents

Computes Harrel's C index for predictions from a "coxnet" object.

Usage

Cindex(pred, y, weights = rep(1, nrow(y)))

Arguments

pred

Predictions from a "coxnet" object

y

a survival response object - a matrix with two columns "time" and "status"; see documentation for "glmnet"

weights

optional observation weights

Details

Computes the concordance index, taking into account censoring.

References

Harrel Jr, F. E. and Lee, K. L. and Mark, D. B. (1996) Tutorial in biostatistics: multivariable prognostic models: issues in developing models, evaluating assumptions and adequacy, and measuring and reducing error, Statistics in Medicine, 15, pages 361–387.

See also

cv.glmnet

Author

Trevor Hastie hastie@stanford.edu

Examples


set.seed(10101)
N = 1000
p = 30
nzc = p/3
x = matrix(rnorm(N * p), N, p)
beta = rnorm(nzc)
fx = x[, seq(nzc)] %*% beta/3
hx = exp(fx)
ty = rexp(N, hx)
tcens = rbinom(n = N, prob = 0.3, size = 1)  # censoring indicator
y = cbind(time = ty, status = 1 - tcens)  # y=Surv(ty,1-tcens) with library(survival)
fit = glmnet(x, y, family = "cox")
#> 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'.
pred = predict(fit, newx = x)
apply(pred, 2, Cindex, y=y)
#>        s0        s1        s2        s3        s4        s5        s6        s7 
#> 0.5000000 0.6203213 0.6724097 0.6850296 0.6891333 0.6981636 0.7017994 0.7038931 
#>        s8        s9       s10       s11       s12       s13       s14       s15 
#> 0.7059060 0.7104746 0.7145898 0.7189649 0.7215120 0.7235392 0.7256127 0.7277411 
#>       s16       s17       s18       s19       s20       s21       s22       s23 
#> 0.7286190 0.7296009 0.7300918 0.7305654 0.7308167 0.7311054 0.7313451 0.7317437 
#>       s24       s25       s26       s27       s28       s29       s30       s31 
#> 0.7320584 0.7325061 0.7327342 0.7329132 0.7330490 0.7331067 0.7332482 0.7333464 
#>       s32       s33       s34       s35       s36       s37       s38       s39 
#> 0.7335053 0.7337681 0.7337969 0.7339298 0.7338836 0.7339933 0.7340164 0.7340568 
#>       s40       s41       s42       s43       s44       s45       s46       s47 
#> 0.7341319 0.7341955 0.7342099 0.7342763 0.7343283 0.7342561 0.7342648 0.7342445 
#>       s48 
#> 0.7342157 
cv.glmnet(x, y, family = "cox", type.measure = "C")
#> 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'.
#> 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'.
#> 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'.
#> 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'.
#> 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'.
#> 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'.
#> 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'.
#> 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'.
#> 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'.
#> 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'.
#> 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'.
#> 
#> Call:  cv.glmnet(x = x, y = y, type.measure = "C", family = "cox") 
#> 
#> Measure: C-index 
#> 
#>      Lambda Index Measure      SE Nonzero
#> min 0.01920    28  0.7269 0.01170      14
#> 1se 0.08509    12  0.7155 0.01094       8