-
Notifications
You must be signed in to change notification settings - Fork 14
/
03_predsurv_extended.Rmd
2776 lines (2339 loc) · 95.7 KB
/
03_predsurv_extended.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Performance assessment of survival prediction models - extended code"
always_allow_html: true
output:
github_document:
toc: true
toc_depth: 5
keep_text: true
pandoc_args: --webtex
---
```{r setup, include=FALSE}
# Knitr options
knitr::opts_chunk$set(
fig.retina = 3,
fig.path = "imgs/03_predsurv_extended/",
echo = FALSE
)
```
## Goals
In this document, we assume that individual data of the development and validation set are both available.
In particular:
1. To develop a risk prediction model with a time-to-event outcome;
2. To assess the prediction performance of a model with a time-to-event outcome;
3. To assess the potential clinical utility of a risk prediction model with time-to-event outcome.
The extended code basically evaluates the prediction performance at a fixed time horizon (e.g. 5 years) and also for the entire follow-up time.
### Load packages and import data
The following libraries are needed to achieve the following goals, if you have not them installed, please use
install.packages('') (e.g. install.packages('survival')) or use the user-friendly approach if you are using RStudio.
```{r, wdlib, message=FALSE,warning=FALSE, echo=TRUE}
# Use pacman to check whether packages are installed, if not load
if (!require("pacman")) install.packages("pacman")
library(pacman)
pacman::p_load(
rio,
survival,
rms,
pec,
survminer,
riskRegression,
timeROC,
plotrix,
splines,
knitr,
kableExtra,
gtsummary,
boot,
tidyverse,
rsample,
gridExtra,
webshot
)
options(show.signif.stars = FALSE)
palette("Okabe-Ito") # color-blind friendly (needs R 4.0)
```
The two primary datasets from the Rotterdam study and the
German Breast Cancer Study Group (GBSG) are
included as example data sets in the ```survival``` package.
The Rotterdam data has separate variables for time to recurrence
of disease and time to death, and these are combined into a single
endpoint of recurrence free survival (RFS), while the gbsg data
set has RFS as its single endpoint.
The follow-up time is converted from days to years, that being a more
natural unit for any plots; it does not change any fits.
A categorical variable for nodes is also added.
### Data preparation and descriptive statistics
<details>
<summary>Click to expand code</summary>
```{r, import,fig.align='center', echo=TRUE, eval=FALSE}
# Data and recoding ----------------------------------
# Development data
rotterdam$ryear <- rotterdam$rtime/365.25 # time in years
rotterdam$rfs <- with(rotterdam, pmax(recur, death)) #The variable rfs is a status indicator, 0 = alive without relapse, 1 = death or relapse.
# Fix the outcome for 43 patients who have died but
# censored at time of recurrence which was less than death time.
# The actual death time should be used rather than the earlier censored recurrence time.
rotterdam$ryear[rotterdam$rfs == 1 &
rotterdam$recur == 0 &
rotterdam$death == 1 &
(rotterdam$rtime < rotterdam$dtime)] <-
rotterdam$dtime[rotterdam$rfs == 1 &
rotterdam$recur == 0 &
rotterdam$death == 1 &
(rotterdam$rtime < rotterdam$dtime)]/365.25
# variables used in the analysis
pgr99 <- quantile(rotterdam$pgr, .99, type = 1) # there is a large outlier of 5000, used type=1 to get same result as in SAS
rotterdam$pgr2 <- pmin(rotterdam$pgr, pgr99) # Winsorized value
nodes99 <- quantile(rotterdam$nodes, .99, type = 1)
rotterdam$nodes2 <- pmin(rotterdam$nodes, nodes99) # NOTE: winsorizing also continuous node?
rotterdam$csize <- rotterdam$size # categorized size
rotterdam$cnode <- cut(rotterdam$nodes,
c(-1,0, 3, 51),
c("0", "1-3", ">3")) # categorized node
rotterdam$grade3 <- as.factor(rotterdam$grade)
levels(rotterdam$grade3) <- c("1-2", "3")
# Save in the data the restricted cubic spline term using Hmisc::rcspline.eval() package
# Continuous nodes variable
rcs3_nodes <- rcspline.eval(rotterdam$nodes2,
knots = c(0, 1, 9))
attr(rcs3_nodes, "dim") <- NULL
attr(rcs3_nodes, "knots") <- NULL
rotterdam$nodes3 <- rcs3_nodes
# PGR
rcs3_pgr <- Hmisc::rcspline.eval(rotterdam$pgr2,
knots = c(0, 41, 486)) # using knots of the original variable (not winsorized)
attr(rcs3_pgr, "dim") <- NULL
attr(rcs3_pgr, "knots") <- NULL
rotterdam$pgr3 <- rcs3_pgr
# Validation data
gbsg$ryear <- gbsg$rfstime/365.25
gbsg$rfs <- gbsg$status # the GBSG data contains RFS
gbsg$cnode <- cut(gbsg$nodes,
c(-1,0, 3, 51),
c("0", "1-3", ">3")) # categorized node
gbsg$csize <- cut(gbsg$size,
c(-1, 20, 50, 500), #categorized size
c("<=20", "20-50", ">50"))
gbsg$pgr2 <- pmin(gbsg$pgr, pgr99) # Winsorized value of PGR
gbsg$nodes2 <- pmin(gbsg$nodes, nodes99) # Winsorized value of continuous nodes
gbsg$grade3 <- as.factor(gbsg$grade)
levels(gbsg$grade3) <- c("1-2", "1-2", "3")
# Restricted cubic spline
# Continuous nodes
rcs3_nodes <- Hmisc::rcspline.eval(gbsg$nodes2, knots = c(0, 1, 9))
attr(rcs3_nodes, "dim") <- NULL
attr(rcs3_nodes, "knots") <- NULL
gbsg$nodes3 <- rcs3_nodes
# PGR
rcs3_pgr <- Hmisc::rcspline.eval(gbsg$pgr2, knots = c(0, 41, 486))
attr(rcs3_pgr, "dim") <- NULL
attr(rcs3_pgr, "knots") <- NULL
gbsg$pgr3 <- rcs3_pgr
# Much of the analysis will focus on the first 5 years: create
# data sets that are censored at 5
temp <- survSplit(Surv(ryear, rfs) ~ ., data = rotterdam, cut = 5,
episode="epoch")
rott5 <- subset(temp, epoch == 1) # only the first 5 years
temp <- survSplit(Surv(ryear, rfs) ~ ., data = gbsg, cut = 5,
episode ="epoch")
gbsg5 <- subset(temp, epoch == 1)
# Relevel
rott5$cnode <- relevel(rotterdam$cnode, "0")
gbsg5$cnode <- relevel(gbsg$cnode, "0")
```
</details>
```{r, import, fig.align='center', warning=FALSE, eval=TRUE}
```
```{r tab1_bis, echo=FALSE}
rsel <- rotterdam[, c("pid", "csize", "nodes", "grade3", "age", "pgr")]
vsel <- gbsg[, c("pid", "csize", "nodes", "grade3", "age", "pgr")]
rsel$dt <- 1
vsel$dt <- 2
cdata <- rbind(rsel, vsel)
cdata$dt <- factor(cdata$dt,
levels = c(1, 2),
labels = c("Development dataset", "Validation dataset")
)
label(cdata$csize) <- "Size"
label(cdata$nodes) <- "Number of nodes"
label(cdata$grade3) <- "Grade of tumor"
label(cdata$age) <- "Age"
label(cdata$pgr) <- "PGR"
label(cdata$dt) <- "Dataset"
units(cdata$csize) <- "mm"
units(cdata$age) <- "years"
units(cdata$pgr) <- "ng/mL"
gtsummary::tbl_summary(
data = cdata |> select(-pid),
label = list(age ~ "Age (years)", csize ~ "Size (cm)",
pgr ~ "PGR (ng/mL)",
grade3 ~ "Grade"),
by = "dt",
type = all_continuous() ~ "continuous2",
statistic = all_continuous() ~ c(
"{mean} ({sd})",
"{median} ({min}, {max})"
),
) |>
gtsummary::as_kable_extra() |>
kableExtra::kable_styling("striped")
```
## Goal 1 - Develop a risk prediction model with a time-to-event outcome
Prediction models are useful to provide the estimated probability of a specific outcome using personal information.
In many studies, especially in medicine, the main outcome under assessment is the time to an event of interest defined generally as survival time. Prognostic models for survival end points, such as recurrence or progression of disease, need to account for drop out during follow-up. Patients who have not experienced the event of interest are censored observations. Cox regression analysis is the most popular statistical model to deal with such data in oncology and other medical research.
### 1.1 Preliminary investigation - survival and censoring curves in the development and validation data
First, we draw the survival and the censoring curves of the development and validation data
<details>
<summary>Click to expand code</summary>
```{r, surv, fig.align='center', fig.width = 8, fig.height = 7, echo=TRUE, eval=FALSE}
# Development set
sfit_rott <- survfit(Surv(ryear, rfs == 1) ~ 1,
data = rotterdam) # survival
sfit_rott_c <- survfit(Surv(ryear, rfs == 0) ~ 1,
data = rotterdam) # censoring
# Plots development data
dev_plots <- list()
# KM plot - development data
dev_plots[[1]] <- survminer::ggsurvplot(sfit_rott, data = rotterdam,
risk.table = TRUE,
risk.table.fontsize = 3.6,
palette = 3,
size = 1.5,
censor = FALSE,
legend = "none",
title = "Failure-free survival",
xlab = "Years",
ylab = "Probability",
tables.theme = theme_cleantable())
dev_plots[[1]]$table <- dev_plots[[1]]$table +
theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
)
# Censoring plot - development data
dev_plots[[2]] <- survminer::ggsurvplot(sfit_rott_c, data = rotterdam,
risk.table = TRUE,
risk.table.fontsize = 3.6,
palette = 2,
size = 1.5,
censor = FALSE,
legend = "none",
title = "Censoring",
xlab = "Years",
ylab = "Probability",
# risk.table.title = "Number at risk",
# risk.table.y.text.col = TRUE,
tables.theme = theme_cleantable())
dev_plots[[2]]$table <- dev_plots[[2]]$table +
theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
)
# Join together
survminer::arrange_ggsurvplots(dev_plots, print = TRUE,
ncol = 2, nrow = 1, risk.table.height = 0.15,
title = "Development data")
# Validation set
sfit_gbsg <- survfit(Surv(ryear, rfs == 1) ~ 1,
data = gbsg) # survival
sfit_gbsg_c <- survfit(Surv(ryear, rfs == 0) ~ 1,
data = gbsg) # censoring
# KM plot - validation data
val_plots <- list()
val_plots[[1]] <- survminer::ggsurvplot(sfit_gbsg, data = gbsg,
risk.table = TRUE,
risk.table.fontsize = 3.6,
palette = 3,
size = 1.5,
censor = FALSE,
legend = "none",
title = "Failure-free survival",
xlab = "Years",
ylab = "Probability",
tables.theme = theme_cleantable())
val_plots[[1]]$table <- val_plots[[1]]$table +
theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
)
# Censoring - validation data
val_plots[[2]] <- survminer::ggsurvplot(sfit_gbsg_c, data = gbsg,
risk.table = TRUE,
risk.table.fontsize = 3.6,
palette = 2,
size = 1.5,
censor = FALSE,
legend = "none",
title = "Censoring",
xlab = "Years",
ylab = "Probability",
tables.theme = theme_cleantable())
val_plots[[2]]$table <- val_plots[[2]]$table +
theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
)
# Join together
survminer::arrange_ggsurvplots(val_plots, print = TRUE,
ncol = 2, nrow = 1,
risk.table.height = 0.15,
title = "Validation data")
```
</details>
```{r, surv, fig.align='center', warning=FALSE, eval=TRUE, fig.width = 8, fig.height = 7}
```
In total, 2982 patients were included to develop the risk prediction model for survival with a median follow-up of 9 years. The 5-year survival was 56% (95% CI: 55-58%).
In total, 686 patients were selected to externally validate the risk prediction model. The median survival in the validation data was 4.5 years. The median survival was 5 years while the 5-year survival was 49% (95% CI: 45-54%).
### 1.2 Secondary investigation - check non-linearity of continuous predictors
The potential non-linear relation between continuous predictors (i.e. progesterone level) and the outcome should be investigated before developing a risk prediction model. Non-linearity of continuous predictors can be checked using splines.
Physically, a spline is a flexible wood or metal strip, which is passed through a set of fixed points (knots) in order to approximate a curve. The most common computational approximation to this is a cubic smoothing spline which is cubic between the knot points, and constrained to be linear beyond the two end knots.
For the restricted cubic spline using `rms::rcs()` R package::function(), the position of the knots are defined at 10<sup>th</sup>,50<sup>th</sup> and 90<sup>th</sup> quantile of the continuous predictor distribution. For more details see Frank Harrell's book 'Regression Model Strategies' on page 27 (second edition).
The user can specify the positions of the knots instead of using the default calculation of the knots proposed in the book of Frank Harrell.
To deal with very large influential value, we winzorize progesterone level to the 90<sup>th</sup> percentile.
<details>
<summary>Click to expand code</summary>
```{r,ff, warning=FALSE, fig.align='center', echo=TRUE, eval=FALSE}
dd <- datadist(rotterdam)
options(datadist = "dd")
fit_pgr <- rms::cph(Surv(ryear, rfs) ~ rcs(pgr2),
data = rotterdam, x = T, y = T, surv = T)
fit_nodes <- rms::cph(Surv(ryear, rfs) ~ rcs(nodes2),
data = rotterdam, x = T, y = T, surv = T)
oldpar <- par(mfrow = c(2, 2), mar = c(5, 5, 1, 1))
plot(rms::Predict(fit_pgr))
plot(rms::Predict(fit_nodes))
options(datadist = NULL)
par(oldpar)
```
</details>
```{r, ff, fig.align='center', warning=FALSE, eval=TRUE}
```
We should model the progesterone level using a three-knot restricted cubic spline. We save the spline in the development and validation data.
### 1.3 Model development - first check - the proportional hazard (PH) assumption
We now examine the fits in a more careful way by checking the proportionality of the hazards of the Cox regression model.
Firstly, we fit the first prediction model in the development data using size, node, grade. Then, we check the PH assumption.
<details>
<summary>Click to expand code</summary>
```{r,ph, message=FALSE, warning=FALSE,fig.align='center', echo=TRUE, eval=FALSE}
fit1_ph <- coxph(Surv(ryear, rfs) ~ csize + rcs(nodes2, 3) + grade3,
data = rotterdam, x = T, y = T)
zp1 <- cox.zph(fit1_ph, transform = "identity")
kable(round(zp1$table, 3)) |> kable_styling("striped", position = "center")
oldpar <- par(mfrow = c(2, 2), mar = c(5, 5, 1, 1))
for (i in 1:3) {
plot(zp1[i], resid = F)
abline(0, 0, lty = 3)
}
par(oldpar)
```
</details>
```{r, ph, fig.align='center', warning=FALSE, eval=TRUE}
```
The statistical tests show strong evidence of non-proportionality. Since the number of death is large the formal tests are quite sensitive, however, and it is important to also examine the graphs.
These show an estimated coefficient as a function of time. As a further follow-up we will divide the data into 3 epochs of 0-5, 5-10, and 10+ years, fitting a separate model to each.
<details>
<summary>Click to expand code</summary>
```{r, epoch, warning=FALSE, echo=TRUE, eval=FALSE}
# Development
edata <- survSplit(Surv(ryear, rfs) ~ .,
data = rotterdam, cut = c(5, 10),
episode = "epoch"
)
efit1 <- coxph(Surv(ryear, rfs) ~ csize + nodes2 + nodes3 + grade3,
data = edata[edata$epoch == 1, ], x = T, y = T
)
efit2 <- coxph(Surv(ryear, rfs) ~ csize + nodes2 + nodes3 + grade3,
data = edata[edata$epoch == 2, ], x = T, y = T
)
efit3 <- coxph(Surv(ryear, rfs) ~ csize + nodes2 + nodes3 + grade3,
data = edata[edata$epoch == 3, ], x = T, y = T
)
```
</details>
```{r, epoch, fig.align='center', warning=FALSE, eval=TRUE}
```
```{r,ph_table, echo=FALSE}
res_efit <- round(rbind(e1 = coef(efit1),
e2 = coef(efit2),
e3 = coef(efit3)), 2)
rownames(res_efit) <- c("Epoch 1: 0-5 years",
"Epoch 2: 5-10 years",
"Epoch 3: >10 years")
kable(res_efit) |> kable_styling("striped", position = "center")
options(prType = "html")
tt1 <- table(edata$epoch, edata$rfs, dnn = c("Epoch", "Status"))
rownames(tt1) <- c("Epoch 1: 0-5 years",
"Epoch 2: 5-10 years",
"Epoch 3: >10 years")
kable(tt1,
col.names = c("Censored", "Event"),
row.names = TRUE
) |> kable_styling("striped", position = "center")
```
A drastic change in the size coefficients across all epochs is apparent, along with a major reduction in the nodes coefficient in epoch 3. As an ameleoration of this we will refit the model using only the first epoch, which includes most of the recurrences and deaths.
We applied the administrative censoring at 5 years in the development data and we assessed the prediction performance of the prognostic model at 5 years. The 5-year horizon was chosen because it is also a common prediction time horizon in clinical practice. The hazards in the development data seem not totally proportional within 5 years but minor deviation of proportionality were considered acceptable.
### 1.4 Model development - fit the risk prediction models
We develop the risk prediction model in the development data considering the first 5-year follow-up to minimize the violation of proportional hazard including size, nodel and grade. The second model also includes the progesterone level modelled using a 3-knot restricted cubic spline.
We also administratively censored the validation data at 5 years.
<details>
<summary>Click to expand code</summary>
```{r, model_development, fig.align='center', echo=TRUE, eval=FALSE}
# Consider the first 5-year epoch in the development set
# Refit the model
efit1 <- coxph(Surv(ryear, rfs) ~ csize + nodes2 + nodes3 + grade3,
data = rott5, x = T, y = T
)
# Additional marker
efit1_pgr <- update(efit1, . ~ . + pgr2 + pgr3)
# Baseline at 5 years
bh <- basehaz(efit1, centered = FALSE) # uncentered
bh$surv <- exp(-bh$hazard) # baseline survival
S0_t5 <- bh$surv[bh$time == 5]
# NOTE: this can be used to calculate S(t = 5) = S0(t = 5)**exp(X*beta)
bh_c <- basehaz(efit1, centered = TRUE)
bh_c$surv_c <- exp(-bh_c$hazard) # baseline survival
S0_t5_c <- bh_c$surv[bh_c$time == 5]
```
</details>
```{r, model_development, fig.align='center', warning=FALSE, eval=TRUE}
```
Below the results of the models:
+ Classical model:
```{r, summary_m1, fig.align='center',warning=FALSE, echo = FALSE}
dd <- datadist(rott5)
options(datadist = "dd")
options(prType = "html")
fit_cph_rott5 <- rms::cph(Surv(ryear, rfs) ~ csize +
rcs(nodes2, c(0, 1, 9)) + grade3,
data = rott5, x = T, y = T, surv = T
)
print(fit_cph_rott5)
```
+ Extended model:
```{r, summary_m2, fig.align='center',warning=FALSE , echo = FALSE}
options(prType = "html")
fit_cph_rott5_pgr <- update(fit_cph_rott5, . ~ .
+ rcs(pgr2, c(0, 41, 486)))
print(fit_cph_rott5_pgr)
options(datadist = NULL)
```
The coefficients of the models indicated that higher size, higher number of positive lymph nodes and higher grade is more associate with poorer prognosis. The association of the progesterone biomarker and the outcome is non-linear as investigated previously.
### 1.5 Histograms of predictions with and without the additional marker
<details>
<summary>Click to expand code</summary>
```{r, hist_pred, fig.align='center', echo=TRUE, eval=FALSE}
# Refit the model
efit1 <- coxph(Surv(ryear, rfs) ~ csize + nodes2 + nodes3 + grade3,
data = rott5, x = T, y = T
)
# Additional marker
efit1_pgr <- update(efit1, . ~ . + pgr2 + pgr3)
# Development data
t_horizon <- 5
rott5$pred <- riskRegression::predictRisk(efit1,
newdata = rott5,
times = t_horizon)
rott5$pred_pgr <- riskRegression::predictRisk(efit1_pgr,
newdata = rott5,
times = t_horizon)
# par(mgp=c(4,1,0), mar=c(6,5,2,2))
# oldpar <- par(mfrow = c(1, 2), las = 1)
par(las = 1)
xlab <- c(paste0('Basic model\nvariance = ',
round(var(rott5$pred), 3)),
paste0('Extended model with PGR\nvariance = ',
round(var(rott5$pred_pgr), 3)))
Hmisc::histbackback(rott5$pred,
rott5$pred_pgr,
brks = seq(0.01, 0.99, by = 0.02),
xlab = xlab,
ylab = 'Predicted probability')
title("Development data")
# Validation data
gbsg5$pred <- riskRegression::predictRisk(efit1,
newdata = gbsg5,
times = t_horizon)
gbsg5$pred_pgr <- riskRegression::predictRisk(efit1_pgr,
newdata = gbsg5,
times = t_horizon)
par(las = 1)
xlab <- c(paste0('Basic model\nvariance = ',
round(var(gbsg5$pred), 3)),
paste0('Extended model with PGR\nvariance = ',
round(var(gbsg5$pred_pgr), 3)))
Hmisc::histbackback(gbsg5$pred,
gbsg5$pred_pgr,
brks = seq(0.01, 0.99, by = 0.02),
xlab = xlab,
ylab = 'Predicted probability')
title("Validation data")
```
</details>
```{r, hist_pred, fig.align='center', eval=TRUE}
```
## Goal 2 - Assessing performance in survival prediction models
The performance of a risk prediction models may be evaluated through:
+ discrimination: the ability of the model to correctly rank patients with and without the outcome by a certain time point. This requires the coefficients (or the log of the hazard ratios) of the developed Cox prediction model to be evaluated;
+ calibration: the agreement between observed and predicted probabilities. It additionally requires the baseline (cumulative) hazard or survival;
+ overall performance measures: a combination of discrimination and calibration.
It is common that physicians focus on one or more clinically relevant time horizons to inform subjects about their risk.
We aim to assess the prediction performance of a risk prediction model with time-to-event outcome in a new data when information at a fixed time horizon(s) (here at 5 years) of a developed prediction model were provided.
### 2.1 Discrimination measures
Discrimination is the ability to differentiate between subjects who have the outcome by a certain time point and subjects who do not.
Concordance can be assessed over several different time intervals:
+ the entire range of the data. Two concordance measures are suggested:
+ Harrell's C quantifies the degree of concordance as the proportion of evaluable pairs where the patient with a longer survival time has better predicted survival;
+ Uno's C uses a time dependent weighting that more fully adjusts for censoring;
+ a 5 year window corresponding to our target assessment point. Uno's cumulative/dynamic time-dependent Area Under the Curve (AUC) is suggested. Uno's time-dependent AUC summarizes discrimination at specific fixed time points. At any time point of interest, _t_, a patient is classified as having an event if the patient experienced the event between baseline and _t_ (5 years in our case study), and as a non-event if the patient remained event-free at _t_. The time-dependent AUC evaluates whether predicted probabilities were higher for cases than for non-cases.
There is some uncertainty in the literature about the original Harrell
formulation versus Uno's suggestion to re-weight the time scale by the
factor $1/G^2(t)$ where $G$ is the censoring distribution.
There is more detailed information in the concordance vignette found in the
survival package.
For all three measures, values close to 1 indicate good discrimination ability, while values close to 0.5 indicated poor discrimination ability.
<details>
<summary>Click to expand code</summary>
```{r, concordance, message=FALSE ,warning=FALSE, echo=TRUE, eval=FALSE}
# Models
efit1 <- coxph(Surv(ryear, rfs) ~ csize + nodes2 + nodes3 + grade3,
data = rott5, x = T, y = T
)
# Additional marker
efit1_pgr <- update(efit1, . ~ . + pgr2 + pgr3)
## Save elements needed to estimate concordance indexes
# Development data
rott5$lp <- predict(efit1, newdata = rott5)
rott5$lp_pgr <- predict(efit1_pgr, newdata = rott5)
# Validation data
gbsg5$lp <- predict(efit1, newdata = gbsg5)
gbsg5$lp_pgr <- predict(efit1_pgr, newdata = gbsg5)
# Harrell C - development
harrell_C_rott5 <- concordance(Surv(ryear, rfs) ~ lp,
rott5,
reverse = TRUE)
harrell_C_rott5_pgr <- concordance(Surv(ryear, rfs) ~ lp_pgr,
rott5,
reverse = TRUE)
# Harrell C - validation
harrell_C_gbsg5 <- concordance(Surv(ryear, rfs) ~ lp,
gbsg5,
reverse = TRUE)
harrell_C_gbsg5_pgr <- concordance(Surv(ryear, rfs) ~ lp_pgr,
gbsg5,
reverse = TRUE)
# Uno's C - development
Uno_C_rott5 <- concordance(Surv(ryear, rfs) ~ lp,
rott5,
reverse = TRUE,
timewt = "n/G2")
Uno_C_rott5_pgr <- concordance(Surv(ryear, rfs) ~ lp_pgr,
rott5,
reverse = TRUE,
timewt = "n/G2")
# Uno's C - validation
Uno_C_gbsg5 <- concordance(Surv(ryear, rfs) ~ lp,
gbsg5,
reverse = TRUE,
timewt = "n/G2")
Uno_C_gbsg5_pgr <- concordance(Surv(ryear, rfs) ~ lp_pgr,
gbsg5,
reverse = TRUE,
timewt = "n/G2")
```
</details>
```{r, concordance, fig.align='center', warning=FALSE, eval=TRUE}
```
```{r, int_val_01, echo=FALSE, warning=FALSE}
source(here::here('Functions/internal_cv.R'))
# See legend of the argument in the Functions folder
```
Internal validation using bootstrap optimism-corrected cross-validation
<details>
<summary>Click to expand code</summary>
```{r, int_val_calc_01, warning=FALSE, message=FALSE, echo=TRUE, eval=FALSE}
# Models
efit1 <- coxph(Surv(ryear, rfs) ~ csize + nodes2 + nodes3 + grade3,
data = rott5, x = T, y = T
)
# Additional marker
efit1_pgr <- update(efit1, . ~ . + pgr2 + pgr3)
int_val <- bootstrap_cv(db = rott5,
B = 10,
time = "ryear",
status = "rfs",
formula_model = "Surv(ryear, rfs) ~ csize +
nodes2 + nodes3 +
grade3",
formula_ipcw = "Surv(ryear, rfs) ~ 1",
pred.time = 4.99)
int_val_pgr <- bootstrap_cv(db = rott5,
B = 10,
time = "ryear",
status = "rfs",
formula_model = "Surv(ryear, rfs) ~ csize +
nodes2 + nodes3 +
grade3 + pgr2 + pgr3",
formula_ipcw = "Surv(ryear, rfs) ~ 1",
pred.time = 4.99)
```
</details>
```{r, int_val_calc_01, fig.align='center', warning=FALSE, eval=TRUE}
```
NOTE: we use only B = 10 bootstrap samples. You can increase B although it is computationally more demanding.
```{r, res_UnoC, echo=FALSE}
alpha <- .05
k <- 2
res_C <- matrix(c(
harrell_C_rott5$concordance,
harrell_C_rott5$concordance -
qnorm(1 - alpha / 2) * sqrt(harrell_C_rott5$var) ,
harrell_C_rott5$concordance +
qnorm(1 - alpha / 2) * sqrt(harrell_C_rott5$var),
int_val["Harrell C corrected", ],
NA,
NA,
harrell_C_rott5_pgr$concordance,
harrell_C_rott5_pgr$concordance -
qnorm(1 - alpha / 2) * sqrt(harrell_C_rott5_pgr$var) ,
harrell_C_rott5_pgr$concordance +
qnorm(1 - alpha / 2) * sqrt(harrell_C_rott5_pgr$var),
int_val_pgr["Harrell C corrected", ],
NA,
NA,
harrell_C_gbsg5$concordance,
harrell_C_gbsg5$concordance -
qnorm(1 - alpha / 2) * sqrt(harrell_C_gbsg5$var) ,
harrell_C_gbsg5$concordance +
qnorm(1 - alpha / 2) * sqrt(harrell_C_gbsg5$var),
harrell_C_gbsg5_pgr$concordance,
harrell_C_gbsg5_pgr$concordance -
qnorm(1 - alpha / 2) * sqrt(harrell_C_gbsg5_pgr$var) ,
harrell_C_gbsg5_pgr$concordance +
qnorm(1 - alpha / 2) * sqrt(harrell_C_gbsg5_pgr$var),
Uno_C_rott5$concordance,
harrell_C_rott5$concordance -
qnorm(1 - alpha / 2) * sqrt(harrell_C_rott5$var) ,
harrell_C_rott5$concordance +
qnorm(1 - alpha / 2) * sqrt(harrell_C_rott5$var),
int_val["Harrell C corrected", ],
NA,
NA,
Uno_C_rott5_pgr$concordance,
Uno_C_rott5_pgr$concordance -
qnorm(1 - alpha / 2) * sqrt(Uno_C_rott5_pgr$var) ,
Uno_C_rott5_pgr$concordance +
qnorm(1 - alpha / 2) * sqrt(Uno_C_rott5_pgr$var),
int_val_pgr["Uno C corrected", ],
NA,
NA,
Uno_C_gbsg5$concordance,
Uno_C_gbsg5$concordance -
qnorm(1 - alpha / 2) * sqrt(Uno_C_gbsg5$var) ,
Uno_C_gbsg5$concordance +
qnorm(1 - alpha / 2) * sqrt(Uno_C_gbsg5$var),
Uno_C_gbsg5_pgr$concordance,
Uno_C_gbsg5_pgr$concordance -
qnorm(1 - alpha / 2) * sqrt(Uno_C_gbsg5_pgr$var) ,
Uno_C_gbsg5_pgr$concordance +
qnorm(1 - alpha / 2) * sqrt(Uno_C_gbsg5_pgr$var)
),
nrow = 2,
ncol = 18,
byrow = T,
dimnames = list(
c("Harrell C", "Uno C"),
rep(c("Estimate", "Lower .95 ", "Upper .95"), 6)
)
)
res_C <- round(res_C, 3) # Digits
kable(res_C) |>
kable_styling("striped", position = "center") |>
add_header_above(c(" " = 1,
"Apparent" = 3,
"Internal" = 3,
"Apparent + PGR" = 3,
"Internal + PGR" = 3,
"External" = 3,
"External + PGR" = 3))
```
Concordance varied between 0.67 and 0.69 in the apparent, internal and external validation using the basic and extended model.
<details>
<summary>Click to expand code</summary>
```{r, AUC, message=FALSE, warning=FALSE, echo=TRUE, eval=FALSE}
# Models
efit1 <- coxph(Surv(ryear, rfs) ~ csize + nodes2 + nodes3 + grade3,
data = rott5, x = T, y = T
)
# Additional marker
efit1_pgr <- update(efit1, . ~ . + pgr2 + pgr3)
# Time-dependent AUC (in Table 3 called Uno's TD AUC at 5 years) ###
# Uno's time-dependent Area Under the Curve
# Development
Uno_rott5 <-
timeROC::timeROC(
T = rott5$ryear,
delta = rott5$rfs,
marker = predict(efit1, newdata = rott5),
cause = 1,
weighting = "marginal",
times = 4.99,
iid = TRUE
)
Uno_rott5_pgr <-
timeROC::timeROC(
T = rott5$ryear,
delta = rott5$rfs,
marker = predict(efit1_pgr, newdata = rott5),
cause = 1,
weighting = "marginal",
times = 4.99,
iid = TRUE
)
# Validation
Uno_gbsg5 <-
timeROC::timeROC(
T = gbsg5$ryear,
delta = gbsg5$rfs,
marker = predict(efit1, newdata = gbsg5),
cause = 1,
weighting = "marginal",
times = 4.99,
iid = TRUE
)
Uno_gbsg5_pgr <-
timeROC::timeROC(
T = gbsg5$ryear,
delta = gbsg5$rfs,
marker = predict(efit1_pgr, newdata = gbsg5),
cause = 1,
weighting = "marginal",
times = 4.99,
iid = TRUE
)
# NOTE: if you have a lot of data n > 2000, standard error computation may be really long.
# In that case, please use bootstrap percentile to calculate confidence intervals.
```
</details>
```{r, AUC, fig.align='center', warning=FALSE, eval=TRUE}
```
```{r, res_AUC, echo=FALSE}
# Save results
alpha <- .05
k <- 2
res_AUC <- matrix(c(
Uno_rott5$AUC["t=4.99"],
Uno_rott5$AUC["t=4.99"] -
qnorm(1 - alpha / 2) * Uno_rott5$inference$vect_sd_1["t=4.99"],
Uno_rott5$AUC["t=4.99"] +
qnorm(1 - alpha / 2) * Uno_rott5$inference$vect_sd_1["t=4.99"],
int_val["AUC corrected", ],
NA,
NA,
Uno_rott5_pgr$AUC["t=4.99"],
Uno_rott5_pgr$AUC["t=4.99"] -
qnorm(1 - alpha / 2) * Uno_rott5_pgr$inference$vect_sd_1["t=4.99"],
Uno_rott5_pgr$AUC["t=4.99"] +
qnorm(1 - alpha / 2) * Uno_rott5_pgr$inference$vect_sd_1["t=4.99"],
int_val_pgr["AUC corrected", ],
NA,
NA,
Uno_gbsg5$AUC["t=4.99"],
Uno_gbsg5$AUC["t=4.99"] -
qnorm(1 - alpha / 2) * Uno_gbsg5$inference$vect_sd_1["t=4.99"],
Uno_gbsg5$AUC["t=4.99"] +
qnorm(1 - alpha / 2) * Uno_gbsg5$inference$vect_sd_1["t=4.99"],
Uno_gbsg5_pgr$AUC["t=4.99"],
Uno_gbsg5_pgr$AUC["t=4.99"] -
qnorm(1 - alpha / 2) * Uno_gbsg5_pgr$inference$vect_sd_1["t=4.99"],
Uno_gbsg5_pgr$AUC["t=4.99"] +
qnorm(1 - alpha / 2) * Uno_gbsg5_pgr$inference$vect_sd_1["t=4.99"]
),
nrow = 1,
ncol = 18,
byrow = T,
dimnames = list(
c("Uno AUC"),
rep(c("Estimate", "Lower .95 ", "Upper .95"), 6)
)
)
res_AUC <- round(res_AUC, 3) # Digits
kable(res_AUC) |>
kable_styling("striped", position = "center") |>
add_header_above(c(" " = 1,
"Apparent" = 3,
"Internal" = 3,
"Apparent + PGR" = 3,
"Internal + PGR" = 3,
"External" = 3,
"External + PGR" = 3))
```
Time-dependent AUC at 5 years was between 0.68 and 0.72 in the apparent, internal and external validation for the basic and extended model.
We also provide here the plot of the discrimination measures over the time.
<details>
<summary>Click to expand code</summary>
```{r, discr_time, message=FALSE ,warning=FALSE, echo=TRUE, eval=FALSE}
# Models
efit1 <- coxph(Surv(ryear, rfs) ~ csize + nodes2 + nodes3 + grade3,
data = rott5, x = T, y = T
)
# Additional marker
efit1_pgr <- update(efit1, . ~ . + pgr2 + pgr3)
# Save PI for development and validation data
# Development data
lp_dev <- predict(efit1, newdata = rott5)
lp_dev_pgr <- predict(efit1_pgr, newdata = rott5)
# Validation data
lp_val <- predict(efit1, newdata = gbsg5)
lp_val_pgr <- predict(efit1_pgr, newdata = gbsg5)
mtime <- c((6:59) / 12, 4.99) # From 0.5 years to 4.99
# Weights to estimate Uno's AUC in the development and validation data
gwt_dev <- rttright(Surv(ryear, rfs) ~ 1, rott5, times= mtime)
gwt_val <- rttright(Surv(ryear, rfs) ~ 1, gbsg5, times= mtime)
cstat <- matrix(0, length(mtime), 24) # Uno, Harrell, AUROC, then se of each
for (i in 1:length(mtime)) {
# Harrell C - development data (basic + extended model)
c0_dev <- concordance(efit1, ymax = mtime[i]) # dev data - basic + ext model
c0_dev_pgr <- concordance(efit1_pgr, ymax = mtime[i])
# Harrell C - validation data (basic + extended model)
c0_val <- concordance(efit1, newdata = gbsg5, ymax = mtime[i])
c0_val_pgr <- concordance(efit1_pgr, newdata = gbsg5, ymax = mtime[i])
# Uno C - development data (basic + extended model)
c1_dev <- concordance(efit1,
ymax = mtime[i],
timewt= "n/G2")
c1_dev_pgr <- concordance(efit1_pgr,
ymax = mtime[i],
timewt= "n/G2")
# Uno C - validation data (basic + extended model)
c1_val <- concordance(efit1,
newdata = gbsg5,
ymax = mtime[i],
timewt= "n/G2")
c1_val_pgr <- concordance(efit1_pgr,
newdata = gbsg5,
ymax = mtime[i],
timewt= "n/G2")
# AUC - development data
yy_dev <- with(rott5, ifelse(ryear <= mtime[i] & rfs == 1, 1, 0))
c2_dev <- concordance(yy_dev ~ lp_dev,
weight = gwt_dev[,i],
subset = (gwt_dev[,i] > 0))
c2_dev_pgr <- concordance(yy_dev ~ lp_dev_pgr,
weight = gwt_dev[,i],
subset = (gwt_dev[,i] > 0))
# AUC - validation data