Purpose

This workflow analyzes the time until a doctoral student reaches a program milestone. It demonstrates right censoring, Kaplan-Meier estimation, group comparison, Cox proportional hazards regression, model diagnostics, adjusted survival curves, and results reporting.

The included data are entirely synthetic. Run the complete example before adapting it. Define the event, time origin, censoring rules, and unit of analysis in writing before fitting any survival model.

Survival analysis foundations

  • Time origin: when follow-up begins for every participant.
  • Event: the outcome whose timing is modeled.
  • Observed time: time from origin to the event or censoring.
  • Right censoring: follow-up ended before the event was observed.
  • Survival function: probability of remaining event-free beyond time t.
  • Hazard: instantaneous event rate among participants still at risk.
  • Hazard ratio: relative hazard associated with a predictor, conditional on the model.

A hazard ratio is not a risk ratio, odds ratio, or difference in median survival time.

User settings

Simulate and import the example

Rows: 450
Columns: 8
$ participant_id    <chr> "D001", "D002", "D003", "D004", "D005", "D006", "D00~
$ time_months       <dbl> 12.63, 16.66, 6.63, 9.05, 23.16, 34.83, 22.15, 10.60~
$ event             <int> 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0~
$ support_program   <fct> Standard support, Standard support, Enhanced support~
$ part_time         <fct> Full-time, Full-time, Full-time, Part-time, Full-tim~
$ age               <dbl> 24, 47, 37, 41, 39, 41, 33, 23, 23, 37, 44, 39, 30, ~
$ baseline_progress <dbl> 76, 77, 61, 44, 45, 57, 55, 74, 47, 61, 55, 63, 74, ~
$ advisor_support   <dbl> 29, 29, 25, 24, 28, 17, 19, 36, 30, 25, 24, 22, 26, ~

Data audit

Event and follow-up summary

participants events censored event_percent median_follow_up maximum_follow_up
450 290 160 64.4 15.5 36

Missingness

variable missing_n missing_percent
baseline_progress 8 1.8
advisor_support 7 1.6
age 0 0.0
event 0 0.0
part_time 0 0.0
participant_id 0 0.0
support_program 0 0.0
time_months 0 0.0

This example uses complete cases for the adjusted Cox model so the effect of missing predictors is visible. For substantive research, justify complete-case analysis or use a suitable multiple-imputation strategy that includes the event indicator and survival information.

Validity checks

stage n
Imported records 450
Complete cases for adjusted model 435
Records excluded for missing predictors 15

Visualize observed follow-up

Kaplan-Meier estimates

Overall estimate

Call: survfit(formula = survival_object ~ 1, data = raw_data, conf.type = "log-log")

       n events median 0.95LCL 0.95UCL
[1,] 450    290   18.6    16.2    20.1

By support program

Call: survfit(formula = Surv(time_months, event) ~ support_program, 
    data = raw_data, conf.type = "log-log")

                                   n events median 0.95LCL 0.95UCL
support_program=Standard support 220    136   19.6    16.7    20.7
support_program=Enhanced support 230    154   16.8    14.4    19.9

Modern survival curves

Cumulative incidence

Number at risk

group at_risk_0m at_risk_6m at_risk_12m at_risk_18m at_risk_24m at_risk_30m at_risk_36m events_0m events_6m events_12m events_18m events_24m events_30m events_36m
Standard support 220 202 157 89 39 21 10 0 18 46 35 25 10 2
Enhanced support 230 192 147 84 43 23 4 0 38 45 33 24 9 5

Median survival

group records events median_months median_conf_low median_conf_high
Standard support 220 136 19.63 16.69 20.72
Enhanced support 230 154 16.84 14.36 19.91

If the survival curve never crosses 0.50, the median is not estimable within follow-up. Report a milestone-specific survival probability or restricted mean survival time instead of inventing a median.

Log-rank comparison

Call:
survdiff(formula = Surv(time_months, event) ~ support_program, 
    data = raw_data, rho = 0)

                                   N Observed Expected (O-E)^2/E (O-E)^2/V
support_program=Standard support 220      136      147     0.818      1.66
support_program=Enhanced support 230      154      143     0.840      1.66

 Chisq= 1.7  on 1 degrees of freedom, p= 0.2 

The log-rank test compares the full unadjusted survival curves. It does not estimate an adjusted effect and should be interpreted alongside effect estimates and confidence intervals.

Cox proportional hazards models

Unadjusted model

term estimate conf.low conf.high p.value
support_programEnhanced support 1.164 0.924 1.466 0.198

Adjusted model

predictor hazard_ratio conf_low conf_high p_value
support_programEnhanced support 1.079 0.849 1.370 0.534
part_timePart-time 0.824 0.637 1.067 0.142
scale(age) 0.990 0.877 1.118 0.874
scale(baseline_progress) 1.211 1.073 1.366 0.002
scale(advisor_support) 1.188 1.061 1.329 0.003

Continuous predictors are standardized inside the formula, so their hazard ratios represent a one-standard-deviation increase. Positive coefficients indicate a higher event hazard and typically a shorter time to the event; negative coefficients indicate a lower event hazard and typically a longer time to the event.

Model performance

analysis_n events concordance concordance_se likelihood_ratio_chisq likelihood_ratio_df likelihood_ratio_p
435 282 0.577 0.019 21.752 5 0.001

Adjusted survival curves

Model diagnostics

Proportional hazards

term chisq df p
support_program 3.515 1 0.061
part_time 2.480 1 0.115
scale(age) 1.979 1 0.159
scale(baseline_progress) 1.060 1 0.303
scale(advisor_support) 0.106 1 0.745
GLOBAL 7.456 5 0.189

A small p-value suggests that a coefficient may vary over follow-up. Evaluate the global test, term-specific tests, residual patterns, study design, and statistical power together. If proportional hazards is not plausible, consider a time interaction, stratification, or a different estimand.

Scaled Schoenfeld residuals

Functional form

Splines, transformations, or prespecified categories may address nonlinearity. Choose them using subject-matter knowledge and document any data-informed decisions.

Influential observations

participant_id maximum_absolute_dfbeta

Investigate influential records for data errors, unusual covariate patterns, and sensitivity. Do not remove a valid observation solely because it is influential.

Event-based planning

For a balanced binary predictor, Schoenfeld’s approximation estimates the number of events needed to detect a target hazard ratio under proportional hazards.

target_hazard_ratio target_power alpha events_needed anticipated_event_proportion approximate_sample_needed
0.75 0.8 0.05 380 0.65 585

This is a simplified planning calculation. Adjust the design for unequal groups, covariate correlation, attrition, clustering, nonproportional hazards, competing events, and the actual recruitment and follow-up plan.

Dynamic results template

Kaplan-Meier estimates and a Cox proportional hazards model were used to examine time to the doctoral milestone. Among 450 participants, 290 experienced the event and 160 were right censored. The unadjusted log-rank comparison produced chi-square(1) = 1.66, p = .197.

In the adjusted Cox model, enhanced support relative to standard support was associated with a hazard ratio of 1.08, 95% CI [0.85, 1.37], p = .534. The model included enrollment status, age, baseline progress, and advisor support. The concordance statistic was 0.58.

The global proportional-hazards test did not provide evidence against proportionality, p = .189, although graphical and term-specific diagnostics remain important. Continuous-predictor functional form and influential observations were also reviewed. Interpret hazard ratios together with adjusted survival curves, absolute event probabilities, diagnostic results, and the study design.

When this template is not enough

  • Competing risks: another event prevents or changes the probability of the event of interest.
  • Time-varying predictors: exposure values change during follow-up.
  • Delayed entry: participants become at risk after the common time origin.
  • Recurrent events: the same participant can experience the event more than once.
  • Clustered data: participants are nested within programs, clinics, schools, or other units.
  • Interval censoring: the event is known only to occur within an interval.

Each situation requires data structures and estimators beyond the basic one-row-per-participant Cox model used here.

Reporting checklist

  • Define the time origin, event, unit of time, and censoring mechanisms.
  • Report the analysis sample, number of events, censoring proportion, and follow-up.
  • Show Kaplan-Meier curves with confidence intervals and numbers at risk.
  • Report hazard ratios with confidence intervals and clarify reference groups and scaling.
  • State the ties method and missing-data approach.
  • Describe proportional-hazards, functional-form, and influence diagnostics.
  • Report absolute survival or cumulative-incidence estimates when they aid interpretation.
  • Document departures from the prespecified model and any sensitivity analyses.

References

  • Cox, D. R. (1972). Regression models and life-tables. Journal of the Royal Statistical Society: Series B, 34(2), 187-220.
  • Kaplan, E. L., & Meier, P. (1958). Nonparametric estimation from incomplete observations. Journal of the American Statistical Association, 53(282), 457-481.
  • Kleinbaum, D. G., & Klein, M. (2012). Survival Analysis: A Self-Learning Text (3rd ed.). Springer.
  • Therneau, T. M., & Grambsch, P. M. (2000). Modeling Survival Data: Extending the Cox Model. Springer.

Exported files

file
synthetic_survival_data.csv
event_summary.csv
missingness_review.csv
cox_model_results.csv
model_performance.csv
proportional_hazards_test.csv
influence_review.csv
run_settings.csv
package_versions.csv