install.packages(c("survival", "tidyverse", "gtsummary", "gt"))Code, data & slides
Everything you need to work through the examples.
Set up R
Use a current R release with RStudio. The examples are checked with R 4.5.3. Chapter 1 uses the survival package; Chapter 2 introduces the tidyverse and descriptive tables with gtsummary. Install packages once, then load them with library() in each new R session.
Later chapters use additional packages:
install.packages(c("broom", "ggsurvfit", "survminer", "tidycmprsk",
"tidymodels", "censored", "glmnet", "ranger", "broom.helpers"))Working data
The German breast cancer study is the running example. Download the data into a folder called data inside your RStudio project. The scripts use paths such as data/gbc.txt relative to that project folder.
| File | Contents |
|---|---|
| gbc_mort.txt | Mortality follow-up, one record per patient |
| gbc.txt | Relapse and mortality records; patients can contribute multiple rows |
| gbc_ms.txt | Companion multistate data |
| Data dictionary | Study provenance, variable descriptions, and coding |
Read the dictionary before choosing the outcome: mortality, relapse-free survival, and competing events answer different questions.
Chapter materials
The scripts for Chapters 1 and 2 follow the book’s worked examples and exercise solutions in order. The later scripts preserve the supplied chapter code and are provided for exploration as their narrative chapters develop.
| Chapter | Slides | R script |
|---|---|---|
| 01 · Survival Analysis in Base R | Download | |
| 02 · Working with Tidy Survival Data | Download | |
| 03 · Nonparametric Estimation | Download | |
| 04 · Regression Models | Download | |
| 05 · Machine Learning | Download |
Saved model fits
The machine-learning examples include saved tuning results. Put these in the same data folder if you want to inspect the supplied results without rerunning the tuning steps: Cox tuning results · Random-forest tuning results.
A note on the materials
The slides preserve the original short-course content and formatting. This book is being developed chapter by chapter; the supplied examples will be reviewed as each narrative chapter is expanded.