Skip to contents

Returns the median survival with upper and lower confidence limits for the median at 95% confidence levels.

Usage

surv_median(fit, combine = FALSE)

Arguments

fit

A survfit object. Can be also a list of survfit objects.

combine

logical value. Used only when fit is a list of survfit objects. If TRUE, combine the results for multiple fits.

Value

Returns for each fit, a data frame with the following column:

  • strata: strata/group names

  • median: median survival of each group

  • lower: 95% lower confidence limit

  • upper: 95% upper confidence limit

Returns a list of data frames when the input is a list of survfit objects. If combine = TRUE, results are combined into one single data frame.

Examples


library(survival)

# Different survfits
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::
fit.null <- surv_fit(Surv(time, status) ~ 1, data = colon)

fit1 <- surv_fit(Surv(time, status) ~ sex, data = colon)

fit2 <- surv_fit(Surv(time, status) ~ adhere, data = colon)

fit.list <- list(sex = fit1, adhere = fit2)

# Extract the median survival
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::
surv_median(fit.null)
#>   strata median lower upper
#> 1    All   2351  2018  2910

surv_median(fit2)
#>     strata median lower upper
#> 1 adhere=0   2718  2213    NA
#> 2 adhere=1   1272   997  1885

surv_median(fit.list)
#> $sex
#>   strata median lower upper
#> 1  sex=0   2174  1752    NA
#> 2  sex=1   2527  1976  2910
#> 
#> $adhere
#>     strata median lower upper
#> 1 adhere=0   2718  2213    NA
#> 2 adhere=1   1272   997  1885
#> 

surv_median(fit.list, combine = TRUE)
#>       id   strata median lower upper
#> 1    sex    sex=0   2174  1752    NA
#> 2    sex    sex=1   2527  1976  2910
#> 3 adhere adhere=0   2718  2213    NA
#> 4 adhere adhere=1   1272   997  1885

# Grouped survfit
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::
fit.list2 <- surv_fit(Surv(time, status) ~ sex, data = colon,
                     group.by = "rx")
surv_median(fit.list2)
#> $`rx.Obs::sex`
#>   strata median lower upper
#> 1  sex=0   1981  1272    NA
#> 2  sex=1   1539  1195  2284
#> 
#> $`rx.Lev::sex`
#>   strata median lower upper
#> 1  sex=0   1885  1275    NA
#> 2  sex=1   1548  1061  2593
#> 
#> $`rx.Lev+5FU::sex`
#>   strata median lower upper
#> 1  sex=0     NA  2021    NA
#> 2  sex=1     NA    NA    NA
#>