0

Using a survfit object, I can extract quantiles like this:

library('survival')
fit <- survfit(Surv(time, status) ~ 1, data = aml) 
quantile(fit)[[1]]
#25 50 75 
#12 27 43

Is there a function to perform the inverse? Pass a vector of quantiles, and return the probabilities?

SmokeyShakers
  • 3,372
  • 1
  • 7
  • 18

1 Answers1

3

You can construct the estimated survival function with stepfun:

survfun <- stepfun(fit$time, c(1, fit$surv))

Then survfun is a function which returns the survival probabilities.

Another way is to use the times argument in summary:

summary(fit, times = c(1, 2, 3))

This should give the same as survfun(c(1,2,3)).

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225