
Introduction to Survival Analysis
Statistical Concepts in Survival analysis
- Survival analysis lets you analyze the rates of occurrence of events over time, without assuming the rates are constant.
- Generally, survival analysis lets you model the time until an event occurs, In the medical world, we typically think of survival analysis literally ,tracking time until death.
- But, it’s more general that survival analysis models time until an event occurs (any event).
Examples
Special features of survival data
- Survival times are generally not symmetrically distributed.
- Usually the data is positively skewed and it will be unreasonable to assume that of this type have a normal distribution.
- Survival times are frequently censored.
The survival time of an individual is said to be censored when the end-point of interest has not been observed for that individual.
Example of the distribution of follow-up times according to event status:
- Censoring is a type of missing data problem unique to survival analysis.
- This happens when you track the sample/subject through the end of the study and the event never occurs.
- This could also happen due to the sample/subject dropping out of the study for reasons other than death, or some other loss to followup.
- The sample is censored in that you only know that the individual survived up to the loss to followup, but you don’t know anything about survival after that.

A subject may be censored due to:
Loss to follow-up
Withdrawal from study
No event by end of fixed study period
Specifically these are examples of right censoring.
- Left censoring and interval censoring are also possible, and methods exist to analyze these types of data, but this tutorial will be focus on right censoring.
illustrating the impact of censoring:

How would we compute the proportion who are event-free at 10 years?
whats happening
Subjects 6 and 7 were event-free at 10 years.
Subjects 2, 9, and 10 had the event before 10 years.
Subjects 1, 3, 4, 5, and 8 were censored before 10 years, so we don’t know whether they had the event or not at 10 years. But we know something about them
that they were each followed for a certain amount of time without the event of interest prior to being censored.
Theoretical Rationale
To analyze survival data, we need to know the observed time \(Y_i\) and the event indicator \(\delta_i\). For subject \(i\):
- Observed time \(Y_i = \min(T_i, C_i)\) where \(T_i\) = event time and \(C_i\) = censoring time
- Event indicator \(\delta_i\) = 1 if event observed (i.e. \(T_i \leq C_i\)), = 0 if censored (i.e. \(T_i > C_i\))
The actual survival time of an individual, t, can be regarded as the observed value of a variable, T, that can take any non-negative value. The different values that T can take have a probability distribution, and we call T the random variable associated with the survival time. Now suppose that this random variable has a probability distribution with underlying probability density function \(f(t)\). The distribution function of \(T\) is then given by
\[F(t)=P(T\le t)=\int_{t}^{\infty}f(u)\]
and represents the probability that the survival time is less than some value t. This function is also called the cumulative incidence function, since it summarises the cumulative probability of death occurring before time t.
probability that an individual survives beyond any given time
\[ S(t) = Pr(T>t) \]
\(S(t)\) monotonically decreasing function with \(S(0) = 1\) and \(S(\infty) = \text{lim}_{t \rightarrow \infty} S(t) = 0\).
Suppose we have \(R (t)\) (set at risk) that has individuals who are prone to dying by time \(t\), the chances of an individual in that set to die in a given interval \([t, t + \delta t)\) is given by the following formula, where \(h(t)\) is the hazard rate and is defined as:
\[h(t) = \lim_{\delta t \rightarrow 0} \frac{P(t < T \le t+\delta t | T > t)}{\delta t}\] The hazard function’s shape can be any strictly positive function and it changes based on the specific survival data provided.
we know that \(f(t) = - \frac{d}{dt} S(t)\) hence equation simplifies to
\[h(t)=\frac{f(t)}{S(t)} =\frac{- \frac{d}{dt} S(t)}{S(t)}= - \frac{d}{dt} [\log S(t)]\]
Taking intergrals both sides the above reduces to: \[H(t)= -\log S(t)\]
where \(H(t)=\int_{t}^{t} h(u) du\) ,is the cumulative risk of a individual dying by time t. Since the event is death, then H(t) summarises the risk of death up to time t, assuming that death has not occurred before t. The survival function is also approximately simplified as follows. \[ S(t) = e^{-H(t)} \approx 1 -H(t) \text{ when H(t) is small. }\]
Estimating the survivor function
One complication in the management of patients with a malignant bone tumour, or osteosarcoma, is that the tumour often spreads to the lungs. This pulmonary metastasis is life-threatening. In a study concerned with the treatment of pulmonary metastasis arising from osteosarcoma, Burdette and Gehan (1970) give the following survival times, in months, of eleven male patients.
\[\hat{S}(t)= \frac{Number~of~individuals~with~survival~time > t}{Number~of~individuals~in~the~dataset}\]
\[11~ 13~ 13 ~13 ~13 ~13~ 14~ 14~ 15~ 15 ~17\] \[\hat{S}(0)=\frac{11}{11}=1\]
\[\hat{S}(11)=\frac{10}{11}=0.9090909\]
\[\hat{S}(13)=\frac{4}{11}=0.4545455\]
\[\hat{S}(14)=\frac{3}{11}=0.2727273\]
\[\hat{S}(15)=\frac{1}{11}=0.09090909\]
If there are \(r\) times of deaths among individuals, such that \(r\leq n\) and \(n\) is the number of individuals with observed survival times. Arranging these times in from the smallest to the largest,the \(j\)-th death time is noted by \(t_{(j)}\) , for \(j = 1, 2, \cdots , r\), such that the \(r\) death times ordred are \[ t_{1}<t_{2}< \cdots < t_{m}\] .
Let \(n_j\), for \(j = 1, 2, \ldots, r\), denote the number of individuals who are still alive before time \(t(j)\), including the ones that are expected to die at that time. Additionally, let \(d_j\) denote the number of individuals who die at time \(t(j)\). The estimate for the product limit can be expressed in the following form:
\[\hat{S}(t) = \prod_{j=1}^k \, \left(1-\frac{d_j}{r_j}\right)\]
To survive until time \(t\), an individual must start by surviving till \(t(1)\), and then continue to survive until each subsequent time point \(t(2), \ldots, t(r)\). It is assumed that there are no deaths between two consecutive time points \(t(j-1)\) and \(t(j)\). The conditional probability of surviving at time \(t(i)\), given that the individual has managed to survive up to \(t(i-1)\), is the complement of the proportion of the individuals who die at time \(t(i)\), denoted by \(d_i\), to the new individuals who are alive just before \(t(i)\), denoted by \(n_i\). Therefore, the probability that is conditional of surviving at time \(t(i)\) is given by \(1 - \frac{d_i}{n_i}\).
The variance of the estimator is given by \[\text{var}(\hat{S}(t)) = [\hat{S}(t)]^2 \sum_{j=1}^k \frac{d_j}{(r_j-d_j) r_j}\]
The corresponding standard deviation is therefore given by: \[\text{s.e}(\hat{S}(t)) = [\hat{S}(t)]\left[\sum_{j=1}^k \frac{d_j}{(r_j-d_j) r_j}\right]^{\frac{1}{2}}\]
The Kaplan-Meier curve illustrates the survival function. It’s a step function illustrating the cumulative survival probability over time. The curve is horizontal over periods where no event occurs, then drops vertically corresponding to a change in the survival function at each time an event occurs.
Example
In trials involving contraceptives, prevention of pregnancy is an obvious criterion for acceptability. However, modern contraceptives have very low failure rates, and so the occurrence of bleeding disturbances, such as amenorrhoea (the prolonged absence of bleeding), irregular or prolonged bleeding, become important in the evaluation of a particular method of contraception. To promote research into methods for analysing menstrual bleeding data from women in contraceptive trials, the World Health Organisation made available data from clinical trials involving a number of different types of contraceptive (WHO, 1987). Part of this data set relates to the time from which a woman commences use of a particular method until discontinuation, with the discontinuation reason being recorded when known. The data in Table 1.1 refer to the number of weeks from the commencement of use of a particular type of intrauterine device (IUD), known as the Multiload 250, until discontinuation because of menstrual bleeding problems. Data are given for 18 women, all of whom were aged between 18 and 35 years and who had experienced two previous pregnancies. Discontinuation times that are censored are labelled with an asterisk. In this example, the time origin corresponds to the first day in which a woman uses the IUD, and the end-point is discontinuation because of bleeding problems. Some women in the study ceased using the IUD because of the desire for pregnancy, or because they had no further need for a contraceptive, while others were simply lost to follow-up. These reasons account for the censored discontinuation times of 13, 18, 23, 38, 54 and 56 weeks. The study protocol called for the menstrual bleeding experience of each woman to be documented for a period of two years from the time origin. For practical reasons, each woman could not be examined exactly two years after recruitment to determine if they were still using the IUD, and this is why there are three discontinuation times greater than 104 weeks that are right-censored.

\[ \begin{align} \hat{S}(t_j) &=\prod_{j=1}^k \, \left(1-\frac{d_j}{r_j}\right)\\ &= S(t_{j-1})\left(1-\frac{d_j}{r_j}\right)\\ \end{align} \] \[ \begin{align} \hat{S}(0) &= 1*\left(1-\frac{0}{18}\right)=1\\ \end{align} \]
\[ \begin{align} \hat{S}(10) &= 1*\left(1-\frac{1}{18}\right)=0.9444444\\ \end{align} \]
\[ \begin{align} \hat{S}(19) &= 0.9444444*\left(1-\frac{1}{15}\right)=0.8814814\\ \end{align} \]
\[.............\]
quietly import delimited sample
stset time , failure(status)
sts list
## Survival-time data settings
##
## Failure event: status!=0 & status<.
## Observed time interval: (0, time]
## Exit on or before: failure
##
## --------------------------------------------------------------------------
## 18 total observations
## 0 exclusions
## --------------------------------------------------------------------------
## 18 observations remaining, representing
## 9 failures in single-record/single-failure data
## 1,046 total analysis time at risk and under observation
## At risk from t = 0
## Earliest observed entry t = 0
## Last observed exit t = 107
##
##
## Failure _d: status
## Analysis time _t: time
##
## Kaplan–Meier survivor function
##
## At Survivor Std.
## Time risk Fail Lost function error [95% conf. int.]
## ------------------------------------------------------------------------
## 10 18 1 0 0.9444 0.0540 0.6664 0.9920
## 13 17 0 1 0.9444 0.0540 0.6664 0.9920
## 18 16 0 1 0.9444 0.0540 0.6664 0.9920
## 19 15 1 0 0.8815 0.0790 0.6019 0.9691
## 23 14 0 1 0.8815 0.0790 0.6019 0.9691
## 30 13 1 0 0.8137 0.0978 0.5241 0.9363
## 36 12 1 0 0.7459 0.1107 0.4536 0.8970
## 38 11 0 1 0.7459 0.1107 0.4536 0.8970
## 54 10 0 1 0.7459 0.1107 0.4536 0.8970
## 56 9 0 1 0.7459 0.1107 0.4536 0.8970
## 59 8 1 0 0.6526 0.1303 0.3438 0.8432
## 75 7 1 0 0.5594 0.1412 0.2564 0.7804
## 93 6 1 0 0.4662 0.1452 0.1830 0.7097
## 97 5 1 0 0.3729 0.1430 0.1209 0.6310
## 104 4 0 1 0.3729 0.1430 0.1209 0.6310
## 107 3 1 2 0.2486 0.1392 0.0468 0.5313
## ------------------------------------------------------------------------The lifetable method is very common in actuary and demography. It is particularly suitable for grouped data.
\[\hat S(t_j)=\prod_{l \le j}\hat p_l\]
with \(\hat p_j=1− \hat q_j\) (conditional probability of surviving), \(\hat q_j=\frac{d_j}{r′_j}\) (conditional probability of dying), and \(r′_j=r_j−\frac{c_j}{2}\)
In order to show this method on the actual example, we need first to create aggregated data, i.e. divide the follow-up in groups and calculate in each strata the number of people at risk, events, and censored.
Let’s see what is happening here
Based on the grouped data, we will estimate the survival curve using the lifetab() in the KMsurv package. See the help page ?lifetab for a description of the arguments and example
- \(n'_j\) adjusted number of subjects that were at risk within a time interval
- \(n_j\)= number of subjects that were enrolled at time interval i
- \(c_j\) = number of subjects that were censored within the time interval
- \(d_j\) = number of subjects that experienced the event during the time interval
\[S(t_i) = S(t_{j-1})(1-\frac{d_j}{n_j})\]

Log rank test
Given the problem of contrasting two or more survival functions,for instance survival times between male and female individuals in the ICU. Let \[ t_{1}<t_{2}< \cdots < t_{r}\]
Let \(t_i\) be the unique times of death observed among the individuals, found by joining all groups of interest. For group \(j\),\ let \(d_{ij}\) denote the number of deaths at time \(t_i\), and\ let \(n_{ij}\) denote the number at risk at time \(t_i\) in that group. Let \(d_i\) denote the total number of deaths at time \(t_i\) across all groups, and\
the expected number of deaths in group \(j\) at time \(t_i\) is: ,
\[E(d_{ij}) = \frac{n_{ij} \, d_i}{n_i} = n_{ij} \left(\frac{d_i}{n_i}\right) \]
At time \(t_i\), suppose there are \(d_i\) deaths and \(n_i\) individuals at risk in total, with \(d_{i0}\) and \(d_{i1}\) deaths and \(n_{i0}\) and \(n_{i1}\) individuals at risk in groups 0 and 1, respectively, such that \(d_{i0} + d_{i1} = d_i\) and \(n_{i0} + n_{i1} = n_i\). Such data can be summarized in a \(2 \times 2\) table at each death time \(t_i\).
Given that the null hypothesis is true, the number of deaths is expected to follow the hypergeometric distribution, and therefore: \[E(d_{i0}) =e_{i0}= \frac{n_{i0} \, d_i}{n_i} = n_{i0} \left(\frac{d_i}{n_i}\right)\]
\[\text{Var}(d_{i0}) = \frac{n_{i0} \, n_{i1} \, d_i(n_i-d_i)}{n_{i}^2 (n_{i}-1)}\]
the statistic \(U_L\) is given by \[U_L=\sum^r_{i=1}(d_{i0}-e_{i0})\] so that the variance of \(U_L\) is \[Var(U_L)=\sum^r_{j=1}v_{i0}=V_L\] which then follows that : \[\frac{U_L}{\sqrt{V_L}} \sim N(0,1)\] and squaring results in \[\frac{U^2_L}{V_L}\sim \chi^2_1\]
Statistical Software for Survival Analysis
The core functions we’ll use out of the survival package include:
Surv(): Creates a survival object.survfit(): Fits a survival curve using either a formula, of from a previously fitted Cox model.coxph(): Fits a Cox proportional hazards regression model.
Other optional functions you might use include:
cox.zph(): Tests the proportional hazards assumption of a Cox regression model.survdiff(): Tests for differences in survival between two groups using a log-rank / Mantel-Haenszel test.1
Surv() creates the response variable, and typical usage takes the time to event,[^time2] and whether or not the event occured (i.e., death vs censored). survfit() creates a survival curve that you could then display or plot. coxph() implements the regression analysis, and models specified the same way as in regular linear models, but using the coxph() function.
- stset– Declaresdatainmemorytobesurvivaldata.Usedto define the “time-to-event” variable, the “status” variable, and other relevant survival variables. Other Stata Com mands beginning with st utilize these defined variables.
- sts list – Produces Kaplan-Meier (KM) or Cox-adjusted survival estimates in the output window. The default is KMsurvival estimates.
- **sts graph88– Produces plots of Kaplan-Meier (KM) survival estimates. This command can also be used to produce Cox-adjusted survival plots.
- sts generate – Creates a variable in the working dataset that contains Kaplan-Meier or Cox adjusted survival estimates.
- sts test – Used to perform statistical tests for the equality of survival functions across strata.
- stphplot –Produces plots of log-logsurvival against the log of time for the assessment of the proportional hazards (PH) assumption. The user can request KM log-log sur vival plots or Cox adjusted log-log survival plots.
- stcoxkm – Produces KM survival plots and Cox adjusted survival plots on the same graph.
- stcox – Used to run a Cox proportional hazard model, a stratified Cox model, or an extended Cox model (i.e., containing time varying covariates).
- stphtest – Performs statistical tests on the PH assumption based on Schoenfeld residuals. Use of this command requires that a Cox model be previously run with the command stcox and the schoenfeld() option.
- streg – Used to run parametric survival models.
- Following the word stset comes the name of the “time-to event” variable. Options for Stata Commands follow a comma.
- The first option used is to define the variable and value that indicates an event (or failure) rather than a censorship. Without this option, Stata assumes that all observations had an event (i.e., no censorships)
The stset command will add four new variables to the dataset. Stata interprets these variables as follows:
- **_t** – The “time-to-event” variable
- **_d** – The “status variable” (coded 1 for an event and 0 for a censorship)
- **_t0** – The beginning “time variable.” All observations start at time 0 by default
- **_st** – Indicates which variables are used in the analysis. All observations are used (coded 1) by default
Footnotes
Cox regression and the logrank test from
survdiffare going to give you similar results most of the time. The log-rank test is asking if survival curves differ significantly between two groups. Cox regression is asking which of many categorical or continuous variables significantly affect survival.↩︎