A compact, portfolio‑ready R project that showcases clinical survival analysis the R way:
- Kaplan–Meier curves with log‑rank tests
- Cox Proportional Hazards (PH) model
- Regularized Cox (LASSO) with
glmnet - Risk stratification by linear predictor quantiles
- Time‑dependent ROC (adaptive horizons with fallback)
- Clean RMarkdown report for presentation
The goal is to demonstrate practical R skills in a domain where R is naturally strong (clinical/biostat). It's intentionally small and reproducible.
r-survival-mini-kit/
├─ R/
│ ├─ prep.R # load/clean the dataset (lung/ovarian)
│ ├─ km_plots.R # KM curves + log-rank
│ ├─ cox_models.R # Cox PH + glmnet LASSO-Cox
│ └─ eval.R # risk strata, timeROC + fallback to riskRegression
├─ report.Rmd # main HTML report (render this)
├─ report.html # rendered report (kept in repo for convenience)
├─ README.md
├─ .gitignore
├─ .Rprofile # optional: auto-activate renv if present
└─ DESCRIPTION # minimal project metadata
- Open the folder in RStudio (or any R environment).
- Install packages (first run):
install.packages(c(
"survival","glmnet","timeROC","broom","tidyverse","gt","rmarkdown","riskRegression"
))- Knit the report:
rmarkdown::render("report.Rmd", output_format = "html_document")The output HTML will be saved alongside the Rmd.
Optional: use renv to lock dependencies later (
install.packages("renv"); renv::init()), but it’s not required for the first run.
This report is deterministic:
- We fix the global RNG seed at the start of the report:
# in report.Rmd setup chunk set.seed(42)
- The report was rendered on R 4.3.x (see the Session info section in the HTML).
Using a different R version may cause minor differences in CV splits/plots.
Recommended options (optional):
- Pin package versions via renv:
install.packages("renv") renv::init() # snapshot current package versions # later on another machine: renv::restore() # reproduce the environment
- Capture exact session metadata in the report footer (already included):
sessionInfo()
- R in its native habitat (clinical stats) — no “forcing R through the window”
- Crisp and short: suitable as a side project and a clean GitHub repo
- Clear structure with reusable functions (
R/folder) and a single presentable report
- Name:
r-survival-mini-kit - Description: Compact survival analysis in R: KM, log‑rank, Cox PH, LASSO‑Cox, time‑ROC. Clean RMarkdown report.
- Topics:
r,survival-analysis,cox,glmnet,clinical-data,tidyverse,rmarkdown,portfolio-project
MIT — see LICENSE.