Skip to contents

This function has been superseded by bkstat::predict_surv_time. Get the survival time at a given probability of survival. A wrapper for survival:::quantile.survfit(). If the survival curve or its confidence limits do not cross the probability of interest (i.e. they extend out to infinity time without dropping below 0.5 probability), then NA is returned for the time estimate.

Usage

surv_time(df, formula, probs = 0.5, ...)

Arguments

df

A data frame.

formula

Either a survival formula: survival::Surv(time, time2, event) ~ variable or a survival model: survival::coxph().

probs

A vector of the survival probabilities of interest.

...

Optional arguments passed to survival:::quantile.survfit().

Value

data.frame

Examples

#----------------------------------------------------------------------------
# surv_time() examples.
#----------------------------------------------------------------------------
library(survival)
library(bkstat)

plot(survfit(formula = Surv(futime, death) ~ trt, data = myeloid))

surv_time(
  df = myeloid,
  formula = Surv(futime, death) ~ trt,
  probs = c(0.25, 0.5, 0.75)
)
#>   strata prob time lower_ci upper_ci
#> 1  trt=A 0.75  286      253      344
#> 2  trt=B 0.75  411      337      513
#> 3  trt=A 0.50  707      529     1245
#> 4  trt=B 0.50 2283     1220       NA
#> 5  trt=A 0.25   NA       NA       NA
#> 6  trt=B 0.25   NA       NA       NA
surv_time(
  df = myeloid,
  formula = coxph(Surv(futime, death) ~ trt, data = myeloid),
  probs = c(0.25, 0.5, 0.75)
)
#>    strata prob time lower_ci upper_ci
#> 1 Overall 0.75  293      261      355
#> 2 Overall 0.50  748      575     1129
#> 3 Overall 0.25   NA       NA       NA
surv_time(
  df = myeloid,
  formula = Surv(futime, death) ~ 1,
  probs = c(0.25, 0.5, 0.75)
)
#>    strata prob time lower_ci upper_ci
#> 1 Overall 0.75  337      295      385
#> 2 Overall 0.50 1220      826       NA
#> 3 Overall 0.25   NA       NA       NA