Survival Analysis in R

Biostatistics

The complete, practical guide to survival analysis in R — censoring and time-to-event data, Kaplan-Meier curves, the log-rank test, and the Cox proportional-hazards model, with publication-ready survminer visuals. Recipe-first, reproducible, clinician-friendly.

LearnBiostatistics › Survival Analysis

Survival analysis answers a question ordinary statistics can’t: how long until something happens — and what changes that time? Time to death, to relapse, to discharge, to a part failing. The catch is censoring: when the study ends, many patients are still alive, so you know they survived at least this long but not their true event time. A t-test or a linear model throws that information away; survival methods use it. This is the complete, modernized guide to time-to-event analysis in R — every method as a recipe you can run, with publication-ready survminer curves you can paste straight into a paper.

How this guide is organized

A · Fundamentals

Censoring · hazard & survival functions

B · Curves (KM)

Kaplan-Meier · median survival · publication curves

C · Comparing groups

Log-rank · stratified & weighted tests

D · Cox regression

Hazard ratios · PH assumptions · model building

E · Advanced

Competing risks · RMST · parametric & frailty

The guide follows the same journey as a survival-analysis course, in order:

  1. Fundamentals — start with what survival analysis is: what censoring means, why ordinary methods fail on time-to-event data, and how the survival and hazard functions describe time until an event.
  2. Curves & estimation (Kaplan-Meier) — estimate survival probabilities and read the median survival from a Kaplan-Meier curve — the signature ggsurvplot with a risk table, confidence band, and the median line.
  3. Comparing groups — test whether survival differs between groups (treatment vs control, biomarker-high vs -low) with the log-rank test, and plot the curves with the p-value on the panel.
  4. Cox regression — model how covariates change the hazard with the Cox proportional-hazards model: hazard ratios, 95% CIs, and a ggforest plot — the workhorse of clinical survival analysis.
  5. Advanced & applied — extend to PH-assumption diagnostics, competing risks, parametric models, and regulatory time-to-event work as later chapters land.

Which method should I use?

The right tool depends on what you’re asking and what you have measured:

Your question Method Start here
What does my time-to-event data even mean? Concepts (censoring, hazard, survival) What is survival analysis?
What’s the survival probability over time / the median? Kaplan-Meier estimation Kaplan-Meier
Do two or more groups survive differently? Log-rank test Log-rank test
How do covariates (age, sex, dose, biomarker) change the hazard? Cox proportional-hazards Cox regression

Whatever you choose, the workflow is the same: build the Surv(time, status) object → estimate (KM or Cox) → draw the publication ggsurvplot (curves + risk table + CI + p-value) → interpret in plain language (median survival, log-rank p, hazard ratio with its 95% CI) → check assumptions → report.

All lessons

No matching items
Note

This guide is filling in wave by wave — the high-demand free hooks first: what survival analysis is, Kaplan-Meier estimation, the log-rank test, and the Cox proportional-hazards model. Coming next: PH-assumption diagnostics, median survival and life tables, the survminer publication studio, stratified and parametric Cox models, and advanced topics (competing risks, restricted mean survival time, regulatory time-to-event).

🟢 With an AI agent

Ask Prova “compare survival between my two groups and fit a Cox model on my data” — it answers with survival + survminer code you can run on your own data, then helps you read the Kaplan-Meier curve, the log-rank p-value, and the hazard ratios. The runtime is the judge. Ask Prova →

Was this page helpful?

Prove you can do it. Master the whole Survival Analysis in R series — track your path, build projects, and earn a certificate.

Start free →

Go Pro — unlimited Prova on your own data and a verifiable certificate that proves the skill.

from $15/mo billed yearly

Go Pro →

✓ You're Pro — keep going. The runtime is the judge.

Get new R & Python lessons by email

Practical, reproducible, no spam. Unsubscribe anytime.

Double opt-in. We never share your email.

Share this pageXLinkedInRedditHN

Citation

BibTeX citation:
@online{untitled,
  author = {},
  title = {Survival {Analysis} in {R}},
  url = {https://www.datanovia.com/learn/biostatistics/survival-analysis/},
  langid = {en}
}
For attribution, please cite this work as:
“Survival Analysis in R.” n.d. https://www.datanovia.com/learn/biostatistics/survival-analysis/.