Skip to content

Instantly share code, notes, and snippets.

@statwonk
Created July 11, 2019 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statwonk/03bee60af71173ac2ee66cba7be00c6e to your computer and use it in GitHub Desktop.
Save statwonk/03bee60af71173ac2ee66cba7be00c6e to your computer and use it in GitHub Desktop.
Time to 10% ending / converting / failure.
library(tidyverse)
library(survival)
rweibull_cens <- function(n, shape, scale) {
# http://statwonk.com/weibull.html
a_random_death_time <- rweibull(n, shape = shape, scale = scale)
a_random_censor_time <- rweibull(n, shape = shape, scale = scale)
observed_time <- pmin(a_random_censor_time, a_random_death_time)
censor <- observed_time == a_random_death_time
tibble(time = observed_time, censor = censor)
}
rweibull_cens(1e3, 1, scale = 1e3) %>%
survfit(Surv(time, censor) ~ 1, data = .) %>%
quantile(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment