MyNixOS website logo
Description

Survival Distribution Container with Flexible Interpolation Methods.

Efficient containers for storing and managing prediction outputs from survival models, including Cox proportional hazards, random survival forests, and modern machine learning estimators. Provides fast C++ methods to evaluate survival probabilities, hazards, probability densities, and related quantities at arbitrary time points, with support for multiple interpolation methods via 'Rcpp'.

survdistr

Survival distribution container for efficient storage, management, and interpolation of survival model predictions.

r-cmd-check Codecov testcoverage CRANStatus

Installation

Install the development version from GitHub:

# install.packages("pak")
pak::pak("mlr-org/survdistr")

Examples

Linear interpolation of a survival matrix using the survDistr R6 class:

library(survdistr)

# generate survival matrix
mat = matrix(data = c(0.9,0.6,0.4,0.8,0.8,0.7), nrow = 2,
             ncol = 3, byrow = TRUE)
x = survDistr$new(x = mat, times = c(12, 34, 42), method = "linear_surv")
x
## A [2 x 3] survival matrix
## Number of observations: 2
## Number of time points: 3
## Interpolation method: Piecewise Constant Density (Linear Survival)
# stored survival matrix
x$data()
##       12  34  42
## [1,] 0.9 0.6 0.4
## [2,] 0.8 0.8 0.7
# S(t) at requested time points (linear interpolation)
x$survival(times = c(5, 30, 42, 50))
##              5        30  42  50
## [1,] 0.9583333 0.6545455 0.4 0.2
## [2,] 0.9166667 0.8000000 0.7 0.6
# Cumulative hazard H(t)
x$cumhazard(times = c(5, 42))
##               5        42
## [1,] 0.04255961 0.9162907
## [2,] 0.08701138 0.3566749
# Probability density f(t)
x$density(times = c(5, 30, 42))
##                5         30     42
## [1,] 0.008333333 0.01363636 0.0250
## [2,] 0.016666667 0.00000000 0.0125
# Hazard h(t)
x$hazard(times = c(5, 30, 42))
##                5         30         42
## [1,] 0.008695652 0.02083333 0.06250000
## [2,] 0.018181818 0.00000000 0.01785714

Interpolation of a Kaplan-Meier survival curve using exported R function that calls C++ code:

library(survival)

fit = survfit(formula = Surv(time, status) ~ 1, data = veteran)
tab = data.frame(time = fit$time, surv = fit$surv)
head(tab)
##   time      surv
## 1    1 0.9854015
## 2    2 0.9781022
## 3    3 0.9708029
## 4    4 0.9635036
## 5    7 0.9416058
## 6    8 0.9124088
tail(tab)
##     time        surv
## 96   411 0.045022553
## 97   467 0.036018043
## 98   553 0.027013532
## 99   587 0.018009021
## 100  991 0.009004511
## 101  999 0.000000000
# constant S(t) interpolation
interp(
  x = tab$surv,
  times = tab$time,
  eval_times = c(0, 3.5, 995)
)
##           0         3.5         995 
## 1.000000000 0.970802920 0.009004511
# linear S(t) interpolation
interp(
  x = tab$surv,
  times = tab$time,
  eval_times = c(0, 3.5, 995),
  method = "linear_surv"
)
##           0         3.5         995 
## 1.000000000 0.967153285 0.004502255
# exponential S(t) interpolation
interp(
  x = tab$surv,
  times = tab$time,
  eval_times = c(0, 3.5, 995),
  method = "exp_surv"
)
##         0       3.5       995 
## 1.0000000 0.9671464 0.0000000

Code of Conduct

Please note that the survdistr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Metadata

Version

0.0.3

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows