Compute quantiles from survival curves.

surv_quantile(x, probs = 0.5, t, surv_cols, by)

Arguments

x

A data.table or data.frame.

probs

A numeric vector of probabilities with values in [0,1].

t

A character scalar of the name of the time column.

surv_cols

A character vector of the names of columns containing survival curves.

by

A character vector of the names of columns to group by.

Value

A data.table of quantiles of each survival curve in surv_cols by each group in by.

Examples

library("data.table")
t <- seq(0, 10, by = .01)
surv1 <- seq(1, .3, length.out = length(t))
surv2 <- seq(1, .2, length.out = length(t))
strategies <- c("Strategy 1", "Strategy 2")
surv <- data.table(strategy = rep(strategies, each = length(t)),
                   t = rep(t, 2), 
                   surv = c(surv1, surv2))
surv_quantile(surv, probs = c(.4, .5), t = "t",
              surv_cols = "surv", by = "strategy")
#>      strategy  prob quantile_surv
#>        <char> <num>         <num>
#> 1: Strategy 1   0.4          5.72
#> 2: Strategy 2   0.4          5.00
#> 3: Strategy 1   0.5          7.15
#> 4: Strategy 2   0.5          6.25