Tools for clustering individualized survival curves using the
Partitioning Around Medoids (PAM) algorithm, with monotonic enforcement,
optional smoothing, weighted distances (L1/L2), automatic K selection via
silhouette width, prediction for new curves, basic stability checks, and
plotting helpers. The method is described in El Badisy (2026)
unsurv provides tools for unsupervised clustering of individualized
survival curves using a medoid-based (PAM) algorithm. It is designed
for applications where each observation is represented by a full
survival probability trajectory over time, such as:
The package provides:
unsurv_compare()install.packages("remotes")
remotes::install_github("ielbadisy/unsurv")
install.packages("unsurv")
The core function is:
unsurv()
which clusters survival curves represented as an n × m matrix:
library(unsurv)
set.seed(123)
n <- 100
Q <- 50
times <- seq(0, 5, length.out = Q)
rates <- c(0.2, 0.5, 0.9)
group <- sample(1:3, n, TRUE)
S <- sapply(times, function(t)
exp(-rates[group] * t)
)
S <- S + matrix(rnorm(n * Q, 0, 0.01), nrow = n)
S[S < 0] <- 0
S[S > 1] <- 1
fit <- unsurv(S, times, K = NULL, K_max = 6)
fit
#> unsurv (PAM) fit
#> K:3
#> distance:L2 silhouette_mean:0.915
#> n:100 Q:50
plot(fit)

Each line represents the medoid survival curve for a cluster.
predict(fit, S[1:5, ])
#> [1] 1 1 1 2 1
Cluster stability can be evaluated using resampling:
stab <- unsurv_stability(
S, times, fit,
B = 20,
frac = 0.7,
mode = "subsample"
)
stab$mean
#> [1] 0.9384743
Higher values indicate more stable clustering.
library(ggplot2)
library(unsurv)
autoplot(fit)

Given survival curves:
$$ S_i(t_1), S_i(t_2), \dots, S_i(t_m) $$
the algorithm:
Cluster medoids represent prototype survival profiles.
fit <- unsurv(S, times)
clusters <- fit$clusters
pred <- predict(fit, new_S)
stab <- unsurv_stability(S, times, fit)
A full walkthrough (simulated mechanics plus the paper’s METABRIC worked example with deep-learning survival predictions) is available in the vignette:
vignette("unsurv-intro", package = "unsurv")
unsurv is useful for:
Unlike clustering on covariates, unsurv clusters on the survival function itself, enabling:
Core functions:
| Function | Description |
|---|---|
| unsurv | fit clustering model |
| predict | assign new curves |
| plot | visualize medoids |
| summary | summarize clustering |
| unsurv_stability | evaluate stability |
| unsurv_compare | compare partitions vs. outcomes |
| autoplot | ggplot visualization |
If you use unsurv, please cite:
citation("unsurv")
#> To cite package 'unsurv' in publications use:
#>
#> El Badisy I (2026). "unsurv: clustering individualized survival
#> curves." _Bioinformatics Advances_, *6*(1), vbag218.
#> doi:10.1093/bioadv/vbag218 <https://doi.org/10.1093/bioadv/vbag218>.
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Article{,
#> title = {unsurv: clustering individualized survival curves},
#> author = {Imad {El Badisy}},
#> journal = {Bioinformatics Advances},
#> year = {2026},
#> volume = {6},
#> number = {1},
#> pages = {vbag218},
#> doi = {10.1093/bioadv/vbag218},
#> publisher = {Oxford University Press},
#> }
MIT License © Imad El Badisy