Skip to contents

This function takes an object resulting from a call to survival::survfit() or survival::survfit0() object and calculates a single-year lifetable for each stratum.

Usage

calc_qx_from_surv(obj_survfit, ...)

Arguments

obj_survfit

An object returned from a call to survival::survfit() or survival::survfit0().

...

Additional arguments passed to convert_survfit2tibble().

Value

A tibble with five columns - stratum first, which reports the stratum from the survfit object to which the estimate belongs. The second, third, and fourth columns return standard life table estimates, including person-years (py), mortality rates (mx), and the probability of death (qx).

Examples

library(survival)

obj_surv <- Surv(time = cancer$time, event = cancer$status)
obj_survfit <- survfit(obj_surv ~ sex, data = cancer)
calc_qx_from_surv(obj_survfit, time_in = "days", age_max_years = 90L)
#> # A tibble: 182 × 5
#>    stratum  year    py    mx    qx
#>    <chr>   <dbl> <dbl> <dbl> <dbl>
#>  1 sex=1       0  86.5 0.983 0.626
#>  2 sex=1       1  21   1.14  0.681
#>  3 sex=1       2   4   0.75  0.528
#>  4 sex=1       3   1   0     0    
#>  5 sex=1       4   1   0     0    
#>  6 sex=1       5   1   0     0    
#>  7 sex=1       6   1   0     0    
#>  8 sex=1       7   1   0     0    
#>  9 sex=1       8   1   0     0    
#> 10 sex=1       9   1   0     0    
#> # ℹ 172 more rows