survdnn

Deep Neural Networks for Survival Analysis Using torch

https://github.com/ielbadisy/survdnn

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.7%) to scientific vocabulary

Keywords

deep-neural-networks survival-analysis
Last synced: 10 months ago · JSON representation

Repository

Deep Neural Networks for Survival Analysis Using torch

Basic Info
  • Host: GitHub
  • Owner: ielbadisy
  • License: other
  • Language: R
  • Default Branch: main
  • Homepage:
  • Size: 7.27 MB
Statistics
  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • Open Issues: 4
  • Releases: 1
Topics
deep-neural-networks survival-analysis
Created 12 months ago · Last pushed 10 months ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---

# survdnn 

> Deep Neural Networks for Survival Analysis Using [torch](https://torch.mlverse.org/)

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)  
[![R-CMD-check](https://github.com/ielbadisy/survdnn/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ielbadisy/survdnn/actions/workflows/R-CMD-check.yaml)

---

`survdnn` implements neural network-based models for right-censored survival analysis using the native `torch` backend in R. It supports multiple loss functions including Cox partial likelihood, L2-penalized Cox, Accelerated Failure Time (AFT) objectives, as well as time-dependent extension such as Cox-Time. The package provides a formula interface, supports model evaluation using time-dependent metrics (e.g., C-index, Brier score, IBS), cross-validation, and hyperparameter tuning.

---

## Features

- Formula interface for `Surv() ~ .` models
- Modular neural architectures: configurable layers, activations, and losses
- Built-in survival loss functions:
  - `"cox"`: Cox partial likelihood
  - `"cox_l2"`: penalized Cox
  - `"aft"`: Accelerated Failure Time
  - `"coxtime"`: deep time-dependent Cox (like DeepSurv)
- Evaluation: C-index, Brier score, Integrated Brier Score (IBS)
- Model selection with `cv_survdnn()` and `tune_survdnn()`
- Prediction of survival curves via `predict()` and `plot()`

---

## Installation

```{r, eval = FALSE}
# Install from CRAN
install.packages("surdnn")


# Install from GitHub
install.packages("remotes")
remotes::install_github("ielbadisy/survdnn")

# Or clone and install locally
git clone https://github.com/ielbadisy/survdnn.git
setwd("survdnn")
devtools::install()
```

---

## Quick Example

```{r, message = FALSE, warning = FALSE}
library(survdnn)
library(survival, quietly = TRUE)
library(ggplot2)

veteran <- survival::veteran

mod <- survdnn(
  Surv(time, status) ~ age + karno + celltype,
  data = veteran,
  hidden = c(32, 16),
  epochs = 100,
  loss = "cox",
  verbose = TRUE
  )
```

```{r}
summary(mod)
```

```{r, eval = FALSE}
plot(mod, group_by = "celltype", times = 1:300)
```

---

## Loss Functions

```{r}
# Cox partial likelihood
mod1 <- survdnn(
  Surv(time, status) ~ age + karno,
  data = veteran,
  loss = "cox",
  epochs = 100
  )
```

```{r}
# Accelerated Failure Time
mod2 <- survdnn(
  Surv(time, status) ~ age + karno,
  data = veteran,
  loss = "aft",
  epochs = 100
  )
```


```{r}
# Deep time-dependent Cox (Coxtime)
mod3 <- survdnn(
  Surv(time, status) ~ age + karno,
  data = veteran,
  loss = "coxtime",
  epochs = 100
  )
```

---

## Cross-Validation

```{r, eval = FALSE}
cv_results <- cv_survdnn(
  Surv(time, status) ~ age + karno + celltype,
  data = veteran,
  times = c(30, 90, 180),
  metrics = c("cindex", "ibs"),
  folds = 3,
  hidden = c(16, 8),
  loss = "cox",
  epochs = 100
  )
print(cv_results)
```

---

## Hyperparameter Tuning

```{r, eval = FALSE}
grid <- list(
  hidden     = list(c(16), c(32, 16)),
  lr         = c(1e-3),
  activation = c("relu"),
  epochs     = c(100, 300),
  loss       = c("cox", "aft", "coxtime")
  )

tune_res <- tune_survdnn(
  formula = Surv(time, status) ~ age + karno + celltype,
  data = veteran,
  times = c(90, 300),
  metrics = "cindex",
  param_grid = grid,
  folds = 3,
  refit = FALSE,
  return = "summary"
  )
print(tune_res)
```

---

## Plot Survival Curves

```{r}
plot(mod1, group_by = "celltype", times = 1:300)
```


```{r}
plot(mod1, group_by = "celltype", times = 1:300, plot_mean_only = TRUE)
```

---

## Documentation

```{r, eval = FALSE}
help(package = "survdnn")
?survdnn
?tune_survdnn
?cv_survdnn
?plot.survdnn
```

---

## Testing

```{r, eval = FALSE}
# Run all tests
devtools::test()
```

---



---


---

## Reproducibility

By default, Torch initializes model weights and shuffles minibatches with random draws, so results may differ at each run.  
Unlike `set.seed()`, which only controls R’s RNG, `{torch}` uses its own RNG implemented in C++/CUDA. To ensure reproducibility, set the Torch seed before training:

```{r}
torch::torch_manual_seed(123)
```

---

## Availability 

The `survdnn` R package is available on CRAN or at: https://github.com/ielbadisy/survdnn  

---

## Contributions

Contributions, issues, and feature requests are welcome.
Open an [issue](https://github.com/ielbadisy/survdnn/issues) or submit a pull request!

---

## License

MIT © [Imad El Badisy](mailto:elbadisyimad@gmail.com)

Owner

  • Name: Imad EL BADISY
  • Login: ielbadisy
  • Kind: user
  • Location: Brest - France
  • Company: IMT Atlantique

Research Engineer in Applied Statistics

GitHub Events

Total
  • Push event: 6
Last Year
  • Push event: 6

Packages

  • Total packages: 1
  • Total downloads:
    • cran 203 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
cran.r-project.org: survdnn

Deep Neural Networks for Survival Analysis Using 'torch'

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 203 Last month
Rankings
Dependent packages count: 25.8%
Forks count: 28.9%
Dependent repos count: 31.7%
Stargazers count: 37.2%
Average: 41.8%
Downloads: 85.6%
Maintainers (1)
Last synced: 10 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/rhub.yaml actions
  • r-hub/actions/checkout v1 composite
  • r-hub/actions/platform-info v1 composite
  • r-hub/actions/run-check v1 composite
  • r-hub/actions/setup v1 composite
  • r-hub/actions/setup-deps v1 composite
  • r-hub/actions/setup-r v1 composite
DESCRIPTION cran
  • R >= 4.1.0 depends
  • cli * imports
  • dplyr * imports
  • ggplot2 * imports
  • glue * imports
  • methods * imports
  • purrr * imports
  • rsample * imports
  • stats * imports
  • survival * imports
  • tibble * imports
  • tidyr * imports
  • torch * imports
  • utils * imports
  • knitr * suggests
  • rmarkdown * suggests
  • testthat >= 3.0.0 suggests