Skip to content

KonNik88/r-survival-mini-kit

Repository files navigation

R Survival Mini‑Kit — Kaplan–Meier, Cox PH, LASSO‑Cox (RMarkdown)

R RMarkdown tidyverse License: MIT Reproducible: renv Domain: Survival Analysis

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.


What’s inside

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

Quick start

  1. Open the folder in RStudio (or any R environment).
  2. Install packages (first run):
install.packages(c(
  "survival","glmnet","timeROC","broom","tidyverse","gt","rmarkdown","riskRegression"
))
  1. 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.


Reproducibility

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()

Why this project?

  • 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

Suggested repo metadata

  • 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

License

MIT — see LICENSE.

About

Compact survival analysis in R: Kaplan–Meier, log-rank, Cox PH, LASSO-Cox, time-dependent ROC. Includes clean RMarkdown report and reproducible project structure

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages