Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › A Worked Survival Analysis From Data to Model

Survival Models Review · Tutorial 123 of 697

A Worked Survival Analysis From Data to Model

Work through a small right-censored dataset from data definitions to Kaplan–Meier, Cox, and exponential results, with attention to assumptions and interpretation.

Intermediate 12 min read

What You'll Learn

  • Define follow-up time and event status for a right-censored dataset
  • Calculate Kaplan–Meier survival estimates and identify the estimated median
  • Construct Cox risk sets and interpret a hazard ratio and its uncertainty
  • Estimate group-specific exponential rates from event counts and person-time
  • Compare model assumptions, diagnostics, and limitations

From Follow-Up Records to Survival Results

A survival analysis begins with a clear account of what counts as the event, when follow-up starts, and what is known for each subject. Right censoring means that a subject's event time is not observed: the subject is known to have remained event-free through a recorded time, but the event may occur later. The analysis uses that partial information rather than treating the censoring time as an event time.

This tutorial follows eight hypothetical subjects in two groups. The event is a first clinical event, and time is measured in weeks from a common, defined time origin. Group A is the reference group; \(x=1\) denotes Group B and \(x=0\) Group A. The event indicator \(\delta\) equals 1 when the event is observed and 0 when follow-up is right-censored.

SubjectGroupFollow-up time (weeks)\(\delta\)Record
A1A11Event
A2A31Event
A3A50Censored
A4A70Censored
B1B21Event
B2B41Event
B3B50Censored
B4B80Censored
Definition: For subject \(i\), the observed follow-up time is \(T_i=\min(U_i,C_i)\), where \(U_i\) is the event time and \(C_i\) is the censoring time. The event indicator is \(\delta_i=I(U_i\leq C_i)\). Thus \(\delta_i=1\) records an event at \(T_i\), while \(\delta_i=0\) records that the subject was event-free through \(T_i\). This setup requires a well-defined time origin and event definition, and censoring must be independent of the event process, either unconditionally or conditional on modeled covariates, for the usual estimators to have their intended interpretation.

In these data, there are four events and four right-censored observations. The rows censored at weeks 5, 7, and 8 contribute event-free follow-up through those times; they do not count as failures. The hypothetical dataset alone cannot establish that censoring is independent. That assumption requires a defensible study and follow-up process, not merely a calculation.

Kaplan–Meier Summary

The Kaplan–Meier estimator estimates the probability of remaining event-free beyond time \(t\), denoted \(S(t)\). At each distinct event time \(t_j\), let \(n_j\) be the number at risk immediately before that time and \(d_j\) the number of events at that time. Censoring reduces later risk sets but does not cause a downward step in the survival estimate.

Definition: The Kaplan–Meier estimate is \(\widehat S(t)=\prod_{t_j\leq t}(1-d_j/n_j)\). It is a right-continuous step function: it decreases at observed event times and remains unchanged at censoring times.

Worked Example: Calculating the Overall Kaplan–Meier Estimate

The four distinct event times are weeks 1, 2, 3, and 4. No one is censored before the last of these events, so the successive risk sets contain 8, 7, 6, and 5 subjects. There is one event at each time.

At week 1, \(\widehat S(1)=1(1-1/8)=7/8=0.875\). At week 2, the estimate is \((7/8)(1-1/7)=(7/8)(6/7)=6/8=0.750\). At week 3 it is \((6/8)(1-1/6)=5/8=0.625\), and at week 4 it is \((5/8)(1-1/5)=4/8=0.500\). The later censorings do not alter this value.

The estimated median event-free time is 4 weeks: this is the first time the Kaplan–Meier estimate is at or below 0.5. This is a point estimate from a very small hypothetical sample, not a precise claim about a population median.

The product simplifies here because there are no censorings before the four events. In more typical data, risk sets change when censoring occurs, so one must use the risk set immediately before each event rather than divide by the original sample size at every step.

Fitting and Interpreting a Cox Model

For these data, a Cox proportional-hazards model with group as the sole covariate is \(h(t\mid x)=h_0(t)\exp(\beta x)\). Here \(h(t\mid x)\) is the instantaneous event rate at time \(t\) among subjects still event-free, \(h_0(t)\) is an unspecified baseline hazard for Group A, and \(\exp(\beta)\) is the Group B to Group A hazard ratio. The model assumes this ratio is constant over follow-up, the covariate is correctly specified, event and censoring times are appropriately observed, and censoring is noninformative conditional on the covariate. The four observed event times are distinct, so no tied-event approximation is needed.

The Cox partial likelihood compares the group of each subject who experiences an event with the groups represented in that event's risk set. For \(q=\exp(\beta)\), the probability contribution for a Group B event in a risk set containing \(r_A\) Group A subjects and \(r_B\) Group B subjects is \(r_Bq/(r_A+r_Bq)\). For a Group A event the corresponding contribution is \(r_A/(r_A+r_Bq)\). In the dataset, the risk-set counts at event times 1 through 4 are \((4,4),(3,4),(3,3),(2,3)\), and the event groups are A, B, A, B.

Worked Example: Solving the Cox Partial-Likelihood Score

The score equation sets the observed number of Group B events, which is 2, equal to the sum of the fitted Group B shares across the four event risk sets:

$$ \frac{4q}{4+4q}+\frac{4q}{3+4q}+\frac{3q}{3+3q}+\frac{3q}{2+3q}=2. $$

Numerically solving gives \(q\approx0.8410\), so \(\hat\beta=\log(0.8410)\approx-0.1732\). For example, at \(q=0.8410\), the four terms are approximately \(0.4568,\ 0.5286,\ 0.4568,\ 0.5578\), which sum to 2.000 to rounding. Thus the fitted Group B hazard is about 0.841 times the Group A hazard at a given time under the proportional-hazards model. This is an estimated association, not evidence that group membership caused the difference.

The observed information for \(\beta\) is the sum of \(p_j(1-p_j)\), where \(p_j\) is each fitted Group B share in the risk set. Using the four values above gives approximately \(0.992\), so \(SE(\hat\beta)=1/\sqrt{0.992}\approx1.004\). A Wald statistic is \(-0.1732/1.004=-0.1725\), with a two-sided normal-approximation \(p\)-value of about 0.863. The 95% Wald interval for \(\beta\) is \(-0.1732\pm1.96(1.004)=[-2.141,1.795]\). Exponentiating its endpoints gives a hazard-ratio interval of approximately \([0.118,6.02]\). The data are compatible with a wide range of hazard ratios; the point estimate should not be read as a precise group difference.

A proportional-hazards interpretation is meaningful only if the hazard ratio is reasonably constant over time. The earlier material on Schoenfeld residuals and time-varying effects gives tools for assessing that assumption. With only four events, however, diagnostic plots and tests have little power and can be unstable. Here the main warning is not a particular diagnostic signal but the severe information limitation: one or two event outcomes could materially change the result.

Fitting an Exponential Model

The exponential model is a parametric survival model with a constant hazard rate \(\lambda\) over time. For a group with \(d\) observed events and total observed person-time \(Y=\sum_i T_i\), under independent noninformative censoring its likelihood, omitting factors not involving \(\lambda\), is \(L(\lambda)=\lambda^d\exp(-\lambda Y)\). Maximizing this likelihood yields \(\hat\lambda=d/Y\). This estimator uses the event indicators and all observed follow-up time, including time from censored subjects.

Worked Example: Estimating Exponential Rates by Group

Group A has two events and total observed follow-up of \(1+3+5+7=16\) person-weeks. Its fitted rate is \(\hat\lambda_A=2/16=0.1250\) events per person-week. Group B also has two events, with \(2+4+5+8=19\) person-weeks, giving \(\hat\lambda_B=2/19\approx0.1053\) events per person-week.

The fitted rate ratio for B relative to A is calculated from the exact rates as \((2/19)/(2/16)=16/19\approx0.8421\). Therefore, under the constant-hazard exponential model, Group B's estimated event rate is about 15.8% lower than Group A's, since \(1-0.8421=0.1579\). This is a model-based descriptive contrast from hypothetical data, not a causal conclusion. The constant-hazard assumption is substantial; the crude rates alone do not show that it holds.

For this one binary covariate, the exponential model's rate ratio is close to the Cox model's fitted hazard ratio, 0.8421 versus 0.8410. That numerical similarity is specific to this small dataset and does not make the models equivalent: the Cox model leaves the baseline hazard unspecified, whereas the exponential model constrains it to be constant.

How to Check the Analysis and Choose a Model

A coherent analysis follows a sequence that keeps the data definition, assumptions, and interpretation connected.

1
Define the record.
Specify event, time origin, time units, and censoring indicator; verify that a censoring time is not mislabeled as an event.
2
Summarize before modeling.
Check event counts, censoring patterns, follow-up ranges, and Kaplan–Meier estimates, including the sizes of the risk sets.
3
Fit only under stated assumptions.
For Cox regression, assess proportional hazards and covariate specification; for an exponential model, assess whether constant hazards are defensible as well.
4
Report uncertainty and scope.
Give the estimate, units or scale, interval, and assumptions. Distinguish a weakly estimated contrast from evidence of no difference.

Kaplan–Meier estimation is a nonparametric summary of survival and can display stepwise differences without imposing a specific hazard shape. It does not, by itself, adjust for covariates. Cox regression estimates covariate hazard ratios without specifying the baseline hazard, but relies on proportional hazards for a single constant ratio. An exponential model can provide a simple rate and a fully specified survival curve, but assumes a constant hazard. More flexible parametric distributions can represent changing hazard shapes, at the cost of choosing and checking a distributional form.

Useful checks include verifying that event times are recorded in the intended units, inspecting risk-set counts and censoring times, and comparing fitted survival behavior with Kaplan–Meier estimates. Cox–Snell residuals can help assess overall parametric fit; Schoenfeld residuals can help assess proportional hazards. These tools do not repair poor event definitions, dependent censoring, or sparse information. In this dataset, all model estimates are necessarily imprecise because only four events occurred.

Common Mistakes and Limitations

  • Counting censoring as an event. A subject censored at week 5 is known to be event-free through week 5; this is not an event at week 5. The correction is to use \(\delta=0\) and retain the subject in risk sets only through the censoring time.
  • Using the original sample size in every Kaplan–Meier factor. Each denominator is the risk set just before that event, after accounting for earlier events and censorings.
  • Calling a hazard ratio a probability ratio. The Cox coefficient compares instantaneous hazards among subjects still at risk; it is not a ratio of event probabilities or survival probabilities.
  • Treating a large \(p\)-value as proof of no effect. Here the estimate is uncertain and its interval is wide. The \(p\)-value does not give the probability that the null hypothesis is true.
  • Choosing an exponential model because it is convenient. A constant hazard is a substantive assumption, not a consequence of observing event and censoring times. Check fit and consider alternatives when the hazard shape is not plausible.
Key takeaway: A defensible survival analysis connects the event and censoring definitions to the risk sets, states model assumptions before interpreting fitted quantities, and reports uncertainty. Kaplan–Meier, Cox, and exponential analyses answer related but distinct questions.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. For a subject censored at week 5, what can be concluded about the event time, and what is the value of \(\delta\)?
  2. Using the overall data, what is the Kaplan–Meier estimate immediately after the event at week 3?
  3. For the exponential model, calculate Group A's estimated rate and state its units.
  4. What does the Cox hazard ratio compare, and which assumption is needed for a single group hazard ratio to apply over time?

Solutions. (1) The subject is known to have remained event-free through week 5, but the later event time is unknown; \(\delta=0\). (2) The estimate is \((7/8)(6/7)(5/6)=5/8=0.625\). (3) Group A has 2 events over 16 person-weeks, so \(\hat\lambda_A=2/16=0.1250\) events per person-week. (4) The Cox hazard ratio compares instantaneous event rates among subjects still event-free at a given time. The proportional-hazards assumption requires that this group hazard ratio remain constant over follow-up.

Clinical Biostats