Cindex.Rd
Computes Harrel's C index for predictions from a "coxnet"
object.
Predictions from a "coxnet"
object
a survival response object - a matrix with two columns "time" and "status"; see documentation for "glmnet"
optional observation weights
Computes the concordance index, taking into account censoring.
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.
cv.glmnet
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")
pred = predict(fit, newx = x)
apply(pred, 2, Cindex, y=y)
#> s0 s1 s2 s3 s4 s5 s6 s7
#> 0.5000000 0.6203213 0.6723115 0.6850065 0.6890813 0.6981203 0.7017850 0.7038614
#> s8 s9 s10 s11 s12 s13 s14 s15
#> 0.7058944 0.7104428 0.7145407 0.7189389 0.7214889 0.7235161 0.7256127 0.7277238
#> s16 s17 s18 s19 s20 s21 s22 s23
#> 0.7286103 0.7295835 0.7300860 0.7305568 0.7308282 0.7311026 0.7313509 0.7317379
#> s24 s25 s26 s27 s28 s29 s30 s31
#> 0.7320700 0.7325061 0.7327457 0.7329104 0.7330403 0.7331241 0.7332540 0.7333435
#> s32 s33 s34 s35 s36 s37 s38 s39
#> 0.7335255 0.7337652 0.7337998 0.7339355 0.7338922 0.7339991 0.7340164 0.7340742
#> s40 s41 s42 s43 s44 s45 s46 s47
#> 0.7341319 0.7341926 0.7342157 0.7342792 0.7343283 0.7342648 0.7342879 0.7342417
#> s48
#> 0.7342243
cv.glmnet(x, y, family = "cox", type.measure = "C")
#>
#> 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.7154 0.01095 8