This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
README.Rmd
83 lines (58 loc) · 3.73 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
title: "survivalmodels"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(survivalmodels)
set.seed(42)
```
[![survivalmodels status badge](https://raphaels1.r-universe.dev/badges/survivalmodels)](https://raphaels1.r-universe.dev)
[![tic](https://github.com/RaphaelS1/survivalmodels/workflows/tic/badge.svg)](https://github.com/RaphaelS1/survivalmodels/actions)
[![CodeFactor](https://www.codefactor.io/repository/github/raphaels1/survivalmodels/badge)](https://www.codefactor.io/repository/github/raphaels1/survivalmodels)
[![Repo Status](https://www.repostatus.org/badges/latest/active.svg)](https://github.com/RaphaelS1/survivalmodels)
[![Lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://github.com/RaphaelS1/survivalmodels)
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/grand-total/survivalmodels)](https://cran.r-project.org/package=survivalmodels)
[![codecov](https://app.codecov.io/gh/RaphaelS1/survivalmodels/branch/master/graph/badge.svg)](https://app.codecov.io/gh/RaphaelS1/survivalmodels)
[![dependencies](https://tinyverse.netlify.com/badge/survivalmodels)](https://CRAN.R-project.org/package=survivalmodels)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
## What is survivalmodels?
`survivalmodels` implements models for survival analysis that are either not already implemented in R, or novel implementations for speed improvements. Currently implemented are five neural networks from the Python packages [pycox](https://github.com/havakv/pycox), DNNSurv,
and the Akritas non-parametric conditional estimator. Further updates will include implementations of novel survival models.
For a hands-on demonstration of model training, tuning, and comparison see [this article](https://towardsdatascience.com/neural-networks-for-survival-analysis-in-r-1e0421584ab?source=friends_link&sk=e978a1b30a4da3370bea930e169326f3) I wrote, which uses the [mlr3proba](https://github.com/mlr-org/mlr3proba) interface with models from `survivalmodels`.
## Basic Usage
```{r}
# load dependencies
library(survival)
train <- simsurvdata(100)
test <- simsurvdata(50
)
fit <- akritas(Surv(time, status) ~ ., data = train)
predict(fit, newdata = test)
# Use distr6 = TRUE to return a distribution
predict_distr <- predict(fit, newdata = test, distr6 = TRUE)
predict_distr$survival(100)
# Return a relative risk ranking with type = "risk"
predict(fit, newdata = test, type = "risk")
Or both survival probabilities and a rank
predict(fit, newdata = test, type = "all", distr6 = TRUE)
```
## Python Models
`survivalmodels` implements models from Python using [reticulate](https://cran.r-project.org/package=reticulate). In order to use these models, the required Python packages must be installed following with [reticulate::py_install](https://rstudio.github.io/reticulate/reference/py_install.html). `survivalmodels` includes a helper function to install the required `pycox` function (with pytorch if also required). Before running any models in this package, if you have not already installed `pycox` please run
```{r eval=FALSE}
install_pycox(pip = TRUE, install_torch = FALSE)
```
With the arguments changed as you require, see [?install_pycox](https://raphaels1.github.io/survivalmodels/reference/install_pycox.html) for more.
For `DNNSurv` the model depends on `keras` and `tensorflow`, which require installation via:
```{r eval=FALSE}
install_keras(pip = TRUE, install_tensorflow = FALSE)
```
## Installation
Install the latest release from CRAN:
```{r eval=FALSE}
install.packages("survivalmodels")
```
Install the development version from GitHub:
```{r eval=FALSE}
remotes::install_github("RaphaelS1/survivalmodels")
```