Piecewise uniform survival curve
pw_unif_surv(p, times, epsilon = 0.1)
Given survival probability constraints
Times at which p
are defined
Length between generated times points
Data frame of time points t
and
survival probabilities S
p <- c(0.8, 0.3, 0.2, 0)
times <- c(10, 20, 30, 40)
surv <- pw_unif_surv(p, times)
plot(surv, type = "l")
# sample times
x <- runif(100)
purrr::map_dbl(x, ~max(surv$t[surv$S > .x]))
#> [1] 17.7 30.2 30.6 13.9 34.8 22.1 38.2 38.9 19.4 17.3 1.9 5.7 18.9 36.3 19.1
#> [16] 22.0 32.2 19.3 14.6 8.6 21.2 11.1 11.2 39.6 9.7 14.7 10.4 0.3 39.6 39.4
#> [31] 5.6 37.7 16.6 1.8 12.6 13.6 5.8 36.6 9.4 12.3 12.3 5.0 10.1 27.7 7.7
#> [46] 34.1 17.7 18.9 16.6 12.9 35.6 16.5 26.3 20.0 39.0 13.9 35.4 18.6 14.0 14.9
#> [61] 3.7 39.0 17.8 12.4 27.5 2.1 27.0 18.0 1.7 13.6 30.1 35.9 36.1 12.5 23.5
#> [76] 18.8 20.3 1.6 10.5 4.4 31.5 19.6 15.5 11.2 2.3 7.7 32.9 31.0 5.8 11.6
#> [91] 2.0 17.4 31.7 34.4 34.7 13.2 8.0 2.8 19.0 34.9