-
Notifications
You must be signed in to change notification settings - Fork 10
/
intro-to-survival-analysis.qmd
1962 lines (1520 loc) · 44.1 KB
/
intro-to-survival-analysis.qmd
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
# Introduction to Survival Analysis
{{< include shared-config.qmd >}}
## Overview
### Time-to-event outcomes {.smaller}
**Survival analysis** is a framework for modeling *time-to-event* outcomes. It is used in:
- clinical trials, where the event is often death or
recurrence of disease.
- engineering reliability analysis, where the event is
failure of a device or system.
- insurance, particularly life insurance, where the
event is death.
:::{.callout-note}
The term *survival analysis* is a bit misleading. Survival outcomes can sometimes be analyzed using binomial models (logistic regression). *Time-to-event models* or *survival time analysis* might be a better name.
:::
## Time-to-event outcome distributions
### Distributions of Time-to-Event Data {.smaller}
- The distribution of event times is asymmetric and can be
long-tailed, and starts at 0 (that is, $P(T<0) = 0$).
- The base distribution is not normal, but exponential.
- There are usually **censored** observations, which are ones in which
the failure time is not observed.
- Often, these are **right-censored**, meaning that we know that the
event occurred after some known time $t$, but we don't know the
actual event time, as when a patient is still alive at the end of
the study.
- Observations can also be **left-censored**, meaning we know the
event has already happened at time $t$, or **interval-censored**,
meaning that we only know that the event happened between times
$t_1$ and $t_2$.
- Analysis is difficult if censoring is associated with treatment.
### Right Censoring
- Patients are in a clinical trial for cancer, some on a new treatment
and some on standard of care.
- Some patients in each group have died by the end of the study. We
know the survival time (measured for example from time of
diagnosis---each person on their own clock).
- Patients still alive at the end of the study are right censored.
- Patients who are lost to follow-up or withdraw from the study may be
right-censored.
### Left and Interval Censoring
- An individual tests positive for HIV.
- If the event is infection with HIV, then we only know that it has
occurred before the testing time $t$, so this is left censored.
- If an individual has a negative HIV test at time $t_1$ and a
positive HIV test at time $t_2$, then the infection event is
interval censored.
## Distribution functions for time-to-event variables
### The Probability Density Function (PDF) {.smaller}
For a time-to-event variable $T$ with a continuous distribution, the
**probability density function** is defined as usual (see @sec-prob-dens).
::: notes
In most time-to-event models, this density is assumed to be 0 for all $t<0$;
that is, $f(t) = 0, \forall t<0$.
In other words, the support of $T$ is typically $[0,\infty)$.
:::
---
:::{#exm-exp-pdf}
#### exponential distribution
Recall from Epi 202: the pdf of the exponential distribution family of
models is:
$$p(T=t) = \1{t \ge 0} \cdot \lambda \ef{-\lambda t}$$
where $\lambda > 0$.
---
Here are some examples of exponential pdfs:
```{r, echo = FALSE}
library(ggplot2)
ggplot() +
geom_function(
aes(col = "0.5"),
fun = \(x) dexp(x, rate = 0.5)) +
geom_function(
aes(col = "p = 1"),
fun = \(x) dexp(x, rate = 1)) +
geom_function(
aes(col = "p = 1.5"),
fun = \(x) dexp(x, rate = 1.5)) +
geom_function(
aes(col = "p = 5"),
fun = \(x) dexp(x, rate = 5)) +
theme_bw() +
ylab("p(T=t)") +
guides(col = guide_legend(title = expr(lambda))) +
xlab("Time (t)") +
xlim(0, 2.5) +
theme(
axis.title.x =
element_text(
angle = 0,
vjust = 1,
hjust = 1),
axis.title.y =
element_text(
angle = 0,
vjust = 1,
hjust = 1))
```
:::
### The Cumulative Distribution Function (CDF)
The **cumulative distribution function** is defined as:
$$
\begin{aligned}
F(t) &\eqdef \Pr(T \le t)\\
&=\int_{u=-\infty}^t f(u) du
\end{aligned}
$$
:::{#exm-exp-cdf}
##### exponential distribution
Recall from Epi 202: the cdf of the exponential distribution family of
models is:
$$
P(T\le t) = \mathbb{1}_{t \ge 0} \cdot (1- \text{e}^{-\lambda t})
$$ where $\lambda > 0$.
:::
Here are some examples of exponential cdfs:
```{r, echo = FALSE}
library(ggplot2)
ggplot() +
geom_function(
aes(col = "0.5"),
fun = \(x) pexp(x, rate = 0.5)) +
geom_function(
aes(col = "p = 1"),
fun = \(x) pexp(x, rate = 1)) +
geom_function(
aes(col = "p = 1.5"),
fun = \(x) pexp(x, rate = 1.5)) +
geom_function(
aes(col = "p = 5"),
fun = \(x) pexp(x, rate = 5)) +
theme_bw() +
ylab("p(T<=t)") +
guides(col = guide_legend(title = expr(lambda))) +
xlab("Time (t)") +
xlim(0, 2.5) +
theme(
axis.title.x =
element_text(
angle = 0,
vjust = 1,
hjust = 1),
axis.title.y =
element_text(
angle = 0,
vjust = 1,
hjust = 1))
```
### The Survival Function
For survival data, a more important quantity is the **survival
function**:
$$
\begin{aligned}
S(t) &\eqdef \Pr(T > t)\\
&=\int_{u=t}^\infty p(u) du\\
&=1-F(t)\\
\end{aligned}
$$
---
:::{#def-surv-fn}
#### Survival function
:::: notes
Given a random time-to-event variable $T$,
the **survival function** or **survivor function**,
denoted $S(t)$,
is the probability
that the event time is later than $t$.
If the event in a clinical trial is death,
then $S(t)$ is the expected fraction
of the original population at time 0
who have survived up to time $t$
and are still alive at time $t$; that is:
::::
$$S(t) \eqdef \Pr(T > t)$${#eq-def-surv}
:::
---
:::{#exm-exp-survfn}
##### exponential distribution
Since $S(t) = 1 - F(t)$, the survival function of the exponential
distribution family of models is:
$$
P(T> t) = \left\{ {{\text{e}^{-\lambda t}, t\ge0} \atop {1, t \le 0}}\right.
$$ where $\lambda > 0$.
@fig-exp-survfuns shows some examples of exponential survival functions.
:::
---
```{r, echo = FALSE}
#| fig-cap: "Exponential Survival Functions"
#| label: fig-exp-survfuns
library(ggplot2)
ggplot() +
geom_function(
aes(col = "0.5"),
fun = pexp,
args = list(lower = FALSE, rate = 0.5)) +
geom_function(
aes(col = "p = 1"),
fun = pexp,
args = list(lower = FALSE, rate = 1)) +
geom_function(
aes(col = "p = 1.5"),
fun = pexp,
args = list(lower = FALSE, rate = 1.5)) +
geom_function(
aes(col = "p = 5"),
fun = pexp,
args = list(lower = FALSE, rate = 5)) +
theme_bw() +
ylab("S(t)") +
guides(col = guide_legend(title = expr(lambda))) +
xlab("Time (t)") +
xlim(0, 2.5) +
theme(
legend.position = "bottom",
axis.title.x =
element_text(
angle = 0,
vjust = 1,
hjust = 1),
axis.title.y =
element_text(
angle = 0,
vjust = 1,
hjust = 1))
```
---
:::{#thm-surv-fn-as-mean-status}
If $A_t$ represents survival status at time $t$, with $A_t = 1$ denoting alive at time $t$ and $A_t = 0$ denoting deceased at time $t$, then:
$$S(t) = \Pr(A_t=1) = \Expp[A_t]$$
:::
---
:::{#thm-surv-and-mean}
If $T$ is a nonnegative random variable, then:
$$\Expp[T] = \int_{t=0}^{\infty} S(t)dt$$
:::
---
:::{.proof}
See <https://statproofbook.github.io/P/mean-nnrvar.html> or
:::
### The Hazard Function
Another important quantity is the **hazard function**:
{{< include _def-hazard.qmd >}}
---
{{< include def-incidence-rate.qmd >}}
---
::: notes
The hazard function has an important relationship to the density and survival functions,
which we can use to derive the hazard function for a given probability distribution (@thm-hazard-dens-surv).
:::
:::::{#lem-joint-prob-same-var}
#### Joint probability of a variable with itself
$$p(T=t, T\ge t) = p(T=t)$$
::::::{.proof}
Recall from Epi 202:
if $A$ and $B$ are statistical events and $A\subseteq B$, then $p(A, B) = p(A)$.
In particular, $\{T=t\} \subseteq \{T\geq t\}$, so $p(T=t, T\ge t) = p(T=t)$.
::::::
:::::
---
:::{#thm-hazard-dens-surv}
#### Hazard equals density over survival
$$h(t)=\frac{f(t)}{S(t)}$$
:::
---
::::{.proof}
$$
\begin{aligned}
h(t) &=p(T=t|T\ge t)\\
&=\frac{p(T=t, T\ge t)}{p(T \ge t)}\\
&=\frac{p(T=t)}{p(T \ge t)}\\
&=\frac{f(t)}{S(t)}
\end{aligned}
$$
::::
---
:::{#exm-exp-haz}
##### exponential distribution
The hazard function of the exponential distribution family of models is:
$$
\begin{aligned}
P(T=t|T \ge t)
&= \frac{f(t)}{S(t)}\\
&= \frac{\mathbb{1}_{t \ge 0}\cdot \lambda \text{e}^{-\lambda t}}{\text{e}^{-\lambda t}}\\
&=\mathbb{1}_{t \ge 0}\cdot \lambda
\end{aligned}
$$
@fig-exp-hazard shows some examples of exponential hazard functions.
:::
---
```{r, echo = FALSE}
#| fig-cap: "Examples of hazard functions for exponential distributions"
#| label: fig-exp-hazard
library(ggplot2)
ggplot() +
geom_hline(
aes(col = "0.5",yintercept = 0.5)) +
geom_hline(
aes(col = "p = 1", yintercept = 1)) +
geom_hline(
aes(col = "p = 1.5", yintercept = 1.5)) +
geom_hline(
aes(col = "p = 5", yintercept = 5)) +
theme_bw() +
ylab("h(t)") +
ylim(0,5) +
guides(col = guide_legend(title = expr(lambda))) +
xlab("Time (t)") +
xlim(0, 2.5) +
theme(
axis.title.x =
element_text(
angle = 0,
vjust = 1,
hjust = 1),
axis.title.y =
element_text(
angle = 0,
vjust = 1,
hjust = 1))
```
---
We can also view the hazard function as the derivative of the negative of the logarithm of the survival function:
:::{#thm-h-logS}
#### transform survival to hazard
$$h(t) = \deriv{t}\cb{-\log{S(t)}}$$
:::
---
::::{.proof}
$$
\begin{aligned}
h(t)
&= \frac{f(t)}{S(t)}\\
&= \frac{-S'(t)}{S(t)}\\
&= -\frac{S'(t)}{S(t)}\\
&=-\deriv{t}\log{S(t)}\\
&=\deriv{t}\cb{-\log{S(t)}}
\end{aligned}
$$
::::
### The Cumulative Hazard Function
Since $h(t) = \deriv{t}\cb{-\log{S(t)}}$ (see @thm-h-logS), we also have:
:::{#cor-surv-int-haz}
$$S(t) = \exp{-\int_{u=0}^t h(u)du}$${#eq-surv-int-haz}
:::
---
::: notes
The integral in @eq-surv-int-haz is important enough to have its own name: **cumulative hazard**.
:::
:::{#def-cuhaz}
##### cumulative hazard
The **cumulative hazard function** $H(t)$ is defined as:
$$H(t) \eqdef \int_{u=0}^t h(u) du$$
:::
As we will see below, $H(t)$ is tractable to estimate, and we can then
derive an estimate of the hazard function using an approximate derivative
of the estimated cumulative hazard.
---
:::{#exm-exp-cumhaz}
The cumulative hazard function of the exponential distribution family of
models is:
$$
H(t) = \mathbb{1}_{t \ge 0}\cdot \lambda t
$$
@fig-cuhaz-exp shows some examples of exponential cumulative hazard functions.
:::
---
```{r, echo = FALSE}
#| fig-cap: "Examples of exponential cumulative hazard functions"
#| label: fig-cuhaz-exp
library(ggplot2)
ggplot() +
geom_abline(
aes(col = "0.5",intercept = 0, slope = 0.5)) +
geom_abline(
aes(col = "p = 1", intercept = 0, slope = 1)) +
geom_abline(
aes(col = "p = 1.5", intercept = 0, slope = 1.5)) +
geom_abline(
aes(col = "p = 5", intercept = 0, slope = 5)) +
theme_bw() +
ylab("H(t)") +
ylim(0,5) +
guides(col = guide_legend(title = expr(lambda))) +
xlab("Time (t)") +
xlim(0, 2.5) +
theme(
axis.title.x =
element_text(
angle = 0,
vjust = 1,
hjust = 1),
axis.title.y =
element_text(
angle = 0,
vjust = 1,
hjust = 1))
```
### Some Key Mathematical Relationships among Survival Concepts
#### Diagram:
$$
h(t) \xrightarrow[]{\int_{u=0}^t h(u)du} H(t)
\xrightarrow[]{\exp{-H(t)}} S(t)
\xrightarrow[]{1-S(t)} F(t)
$$
$$
h(t) \xleftarrow[\deriv{t}H(t)]{} H(t)
\xleftarrow[-\log{S(t)}]{} S(t)
\xleftarrow[1-F(t)]{} F(t)
$$
---
#### Identities:
$$
\begin{aligned}
S(t) &= 1 - F(t)\\
&= \text{exp}\left\{-H(t)\right\}\\
S'(t) &= -f(t)\\
H(t) &= -\text{log}\left\{S(t)\right\}\\
H'(t) &= h(t)\\
h(t) &= \frac{f(t)}{S(t)}\\
&= -\deriv{t}\log{S(t)} \\
f(t) &= h(t)\cdot S(t)\\
\end{aligned}
$$
---
Some proofs (others left as exercises):
$$
\begin{aligned}
S'(t) &= \deriv{t}(1-F(t))\\
&= -F'(t)\\
&= -f(t)\\
\end{aligned}
$$
---
$$
\begin{aligned}
\deriv{t}\log{S(t)}
&= \frac{S'(t)}{S(t)}\\
&= -\frac{f(t)}{S(t)}\\
&= -h(t)\\
\end{aligned}
$$
---
$$
\begin{aligned}
H(t)
&\eqdef \int_{u=0}^t h(u) du\\
&= \int_0^t -\deriv{u}\text{log}\left\{S(u)\right\} du\\
&= \left[-\text{log}\left\{S(u)\right\}\right]_{u=0}^{u=t}\\
&= \left[\text{log}\left\{S(u)\right\}\right]_{u=t}^{u=0}\\
&= \text{log}\left\{S(0)\right\} - \text{log}\left\{S(t)\right\}\\
&= \text{log}\left\{1\right\} - \text{log}\left\{S(t)\right\}\\
&= 0 - \text{log}\left\{S(t)\right\}\\
&=-\text{log}\left\{S(t)\right\}
\end{aligned}
$$
---
Corollary:
$$S(t) = \text{exp}\left\{-H(t)\right\}$$
---
#### Example: Time to death the US in 2004
The first day is the most dangerous:
```{r}
#| fig-cap: "Daily Hazard Rates in 2004 for US Females"
#| fig-pos: "H"
#| fig-height: 6
#| label: fig-haz-female-US
#| echo: true
# download `survexp.rda` from:
# paste0(
# "https://github.com/therneau/survival/raw/",
# "f3ac93704949ff26e07720b56f2b18ffa8066470/",
# "data/survexp.rda")
#(newer versions of `survival` don't have the first-year breakdown; see:
# https://cran.r-project.org/web/packages/survival/news.html)
fs::path(
here::here(),
"data",
"survexp.rda") |>
load()
s1 <- survexp.us[,"female","2004"]
age1 <- c(
0.5/365.25,
4/365.25,
17.5/365.25,
196.6/365.25,
1:109+0.5)
s2 <- 365.25*s1[5:113]
s2 <- c(s1[1], 6*s1[2], 22*s1[3], 337.25*s1[4], s2)
cols <- rep(1,113)
cols[1] <- 2
cols[2] <- 3
cols[3] <- 4
plot(age1,s1,type="b",lwd=2,xlab="Age",ylab="Daily Hazard Rate",col=cols)
text(10,.003,"First Day",col=2)
text(18,.00030,"Rest of First Week",col=3)
text(18,.00015,"Rest of First month",col=4)
```
---
:::{#exr-compare-mf}
Hypothesize why the male and female hazard functions in @fig-haz-mf differ where they do?
:::
```{r}
#| fig-cap: "Daily Hazard Rates in 2004 for US Males and Females 1-40"
#| fig-pos: "H"
#| label: fig-haz-mf
#| echo: true
yrs=1:40
s1 <- survexp.us[5:113,"male","2004"]
s2 <- survexp.us[5:113,"female","2004"]
age1 <- 1:109
plot(age1[yrs],s1[yrs],type="l",lwd=2,xlab="Age",ylab="Daily Hazard Rate")
lines(age1[yrs],s2[yrs],col=2,lwd=2)
legend(5,5e-6,c("Males","Females"),col=1:2,lwd=2)
```
---
:::{#exr-surv-vs-haz}
Compare and contrast @fig-surv-US-females with @fig-haz-female-US.
:::
---
```{r}
#| fig-cap: "Survival Curve in 2004 for US Females"
#| label: fig-surv-US-females
#| fig-pos: "H"
#| echo: true
s1 <- survexp.us[,"female","2004"]
s2 <- 365.25*s1[5:113]
s2 <- c(s1[1], 6*s1[2], 21*s1[3], 337.25*s1[4], s2)
cs2 <- cumsum(s2)
age2 <- c(1/365.25, 7/365.25, 28/365.25, 1:110)
plot(age2,exp(-cs2),type="l",lwd=2,xlab="Age",ylab="Survival")
```
---
### Likelihood with censoring
If an event time $T$ is observed exactly as $T=t$, then the likelihood
of that observation is just its probability density function:
$$
\begin{aligned}
\mathcal L(t)
&= p(T=t)\\
&\eqdef f_T(t)\\
&= h_T(t)S_T(t)\\
\ell(t)
&\eqdef \text{log}\left\{\mathcal L(t)\right\}\\
&= \text{log}\left\{h_T(t)S_T(t)\right\}\\
&= \text{log}\left\{h_T(t)\right\} + \text{log}\left\{S_T(t)\right\}\\
&= \text{log}\left\{h_T(t)\right\} - H_T(t)\\
\end{aligned}
$$
---
If instead the event time $T$ is censored and only known to be after
time $y$, then the likelihood of that censored observation is instead
the survival function evaluated at the censoring time:
$$
\begin{aligned}
\mathcal L(y)
&=p_T(T>y)\\
&\eqdef S_T(y)\\
\ell(y)
&\eqdef \text{log}\left\{\mathcal L(y)\right\}\\
&=\text{log}\left\{S(y)\right\}\\
&=-H(y)\\
\end{aligned}
$$
---
::: notes
What's written above is incomplete. We also observed whether or not the
observation was censored. Let $C$ denote the time when censoring would
occur (if the event did not occur first); let $f_C(y)$ and $S_C(y)$ be
the corresponding density and survival functions for the censoring
event.
Let $Y$ denote the time when observation ended (either by censoring or
by the event of interest occurring), and let $D$ be an indicator
variable for the event occurring at $Y$ (so $D=0$ represents a censored
observation and $D=1$ represents an uncensored observation). In other
words, let $Y \eqdef \min(T,C)$ and
$D \eqdef \mathbb 1{\{T<=C\}}$.
Then the complete likelihood of the observed data $(Y,D)$ is:
:::
$$
\begin{aligned}
\mathcal L(y,d)
&= p(Y=y, D=d)\\
&= \left[p(T=y,C> y)\right]^d \cdot
\left[p(T>y,C=y)\right]^{1-d}\\
\end{aligned}
$$
---
::: notes
Typically, survival analyses assume that $C$ and $T$ are mutually
independent; this assumption is called "non-informative" censoring.
Then the joint likelihood $p(Y,D)$ factors into the product
$p(Y), p(D)$, and the likelihood reduces to:
:::
$$
\begin{aligned}
\mathcal L(y,d)
&= \left[p(T=y,C> y)\right]^d\cdot
\left[p(T>y,C=y)\right]^{1-d}\\
&= \left[p(T=y)p(C> y)\right]^d\cdot
\left[p(T>y)p(C=y)\right]^{1-d}\\
&= \left[f_T(y)S_C(y)\right]^d\cdot
\left[S(y)f_C(y)\right]^{1-d}\\
&= \left[f_T(y)^d S_C(y)^d\right]\cdot
\left[S_T(y)^{1-d}f_C(y)^{1-d}\right]\\
&= \left(f_T(y)^d \cdot S_T(y)^{1-d}\right)\cdot
\left(f_C(y)^{1-d} \cdot S_C(y)^{d}\right)
\end{aligned}
$$
---
::: notes
The corresponding log-likelihood is:
:::
$$
\begin{aligned}
\ell(y,d)
&= \text{log}\left\{\mathcal L(y,d) \right\}\\
&= \text{log}\left\{
\left(f_T(y)^d \cdot S_T(y)^{1-d}\right)\cdot
\left(f_C(y)^{1-d} \cdot S_C(y)^{d}\right)
\right\}\\
&= \text{log}\left\{
f_T(y)^d \cdot S_T(y)^{1-d}
\right\}
+
\text{log}\left\{
f_C(y)^{1-d} \cdot S_C(y)^{d}
\right\}\\
\end{aligned}
$$ Let
- $\theta_T$ represent the parameters of $p_T(t)$,
- $\theta_C$ represent the parameters of $p_C(c)$,
- $\theta = (\theta_T, \theta_C)$ be the combined vector of all
parameters.
---
::: notes
The corresponding score function is:
:::
$$
\begin{aligned}
\ell'(y,d)
&= \deriv{\theta}
\left[
\text{log}\left\{
f_T(y)^d \cdot S_T(y)^{1-d}
\right\}
+
\text{log}\left\{
f_C(y)^{1-d} \cdot S_C(y)^{d}
\right\}
\right]\\
&=
\left(
\deriv{\theta}
\text{log}\left\{
f_T(y)^d \cdot S_T(y)^{1-d}
\right\}
\right)
+
\left(
\deriv{\theta}
\text{log}\left\{
f_C(y)^{1-d} \cdot S_C(y)^{d}
\right\}
\right)\\
\end{aligned}
$$
---
::: notes
As long as $\theta_C$ and $\theta_T$ don't share any parameters, then if
censoring is non-informative, the partial derivative with respect to
$\theta_T$ is:
:::
$$
\begin{aligned}
\ell'_{\theta_T}(y,d)
&\eqdef \deriv{\theta_T}\ell(y,d)\\
&=
\left(
\deriv{\theta_T}
\text{log}\left\{
f_T(y)^d \cdot S_T(y)^{1-d}
\right\}
\right)
+
\left(
\deriv{\theta_T}
\text{log}\left\{
f_C(y)^{1-d} \cdot S_C(y)^{d}
\right\}
\right)\\
&=
\left(
\deriv{\theta_T}
\text{log}\left\{
f_T(y)^d \cdot S_T(y)^{1-d}
\right\}
\right) + 0\\
&=
\deriv{\theta_T}
\text{log}\left\{
f_T(y)^d \cdot S_T(y)^{1-d}
\right\}\\
\end{aligned}
$$
---
::: notes
Thus, the MLE for $\theta_T$ won't depend on $\theta_C$, and we can
ignore the distribution of $C$ when estimating the parameters of
$f_T(t)=p(T=t)$.
:::
Then:
$$
\begin{aligned}
\mathcal L(y,d)
&= f_T(y)^d \cdot S_T(y)^{1-d}\\
&= \left(h_T(y)^d S_T(y)^d\right) \cdot S_T(y)^{1-d}\\
&= h_T(y)^d \cdot S_T(y)^d \cdot S_T(y)^{1-d}\\
&= h_T(y)^d \cdot S_T(y)\\
&= S_T(y) \cdot h_T(y)^d \\
\end{aligned}
$$
::: notes
That is, if the event occurred at time $y$ (i.e., if $d=1$), then the
likelihood of $(Y,D) = (y,d)$ is equal to the hazard function at $y$
times the survival function at $y$. Otherwise, the likelihood is equal
to just the survival function at $y$.
:::
---
::: notes
The corresponding log-likelihood is:
:::
$$
\begin{aligned}
\ell(y,d)
&=\text{log}\left\{\mathcal L(y,d)\right\}\\
&= \text{log}\left\{S_T(y) \cdot h_T(y)^d\right\}\\
&= \text{log}\left\{S_T(y)\right\} + \text{log}\left\{h_T(y)^d\right\}\\
&= \text{log}\left\{S_T(y)\right\} + d\cdot \text{log}\left\{h_T(y)\right\}\\
&= -H_T(y) + d\cdot \text{log}\left\{h_T(y)\right\}\\
\end{aligned}
$$
::: notes
In other words, the log-likelihood contribution from a single
observation $(Y,D) = (y,d)$ is equal to the negative cumulative hazard
at $y$, plus the log of the hazard at $y$ if the event occurred at time
$y$.
:::
## Parametric Models for Time-to-Event Outcomes
### Exponential Distribution
- The exponential distribution is the base distribution for survival
analysis.
- The distribution has a constant hazard $\lambda$
- The mean survival time is $\lambda^{-1}$
---
#### Mathematical details of exponential distribution
$$
\begin{aligned}
f(t) &= \lambda \text{e}^{-\lambda t}\\
E(t) &= \lambda^{-1}\\
Var(t) &= \lambda^{-2}\\
F(t) &= 1-\text{e}^{-\lambda x}\\
S(t)&= \text{e}^{-\lambda x}\\
\ln(S(t))&=-\lambda x\\
h(t) &= -\frac{f(t)}{S(t)} = -\frac{\lambda \text{e}^{-\lambda t}}{\text{e}^{-\lambda t}}=\lambda
\end{aligned}
$$
---
#### Estimating $\lambda$ {.smaller}
- Suppose we have $m$ exponential survival times of
$t_1, t_2,\ldots,t_m$ and $k$ right-censored values at
$u_1,u_2,\ldots,u_k$.
- A survival time of $t_i=10$ means that subject $i$ died at time 10.
A right-censored time $u_i=10$ means that at time 10, subject $i$
was still alive and that we have no further follow-up.
- For the moment we will assume that the survival distribution is
exponential and that all the subjects have the same parameter
$\lambda$.
We have $m$ exponential survival times of $t_1, t_2,\ldots,t_m$ and $k$
right-censored values at $u_1,u_2,\ldots,u_k$. The log-likelihood of an
observed survival time $t_i$ is $$
\text{log}\left\{\lambda \text{e}^{-\lambda t_i}\right\} =
\text{log}\left\{\lambda\right\}-\lambda t_i
$$ and the likelihood of a censored value is the probability of that
outcome (survival greater than $u_j$) so the log-likelihood is
$$
\ba
\ell_j(\lambda) &= \text{log}\left\{\lambda \text{e}^{u_j}\right\}
\\ &= -\lambda u_j
\ea
$$
---
:::{#thm-mle-exp}
Let $T=\sum t_i$ and $U=\sum u_j$. Then:
$$
\hat{\lambda}_{ML} = \frac{m}{T+U}