The broom package exports a tidier for "survfit"
objects.
This function adds on top of that and returns more information.
The function also utilizes additional information stored when the
survfit object is created with survfit2()
.
It's recommended to always use this function with survfit2()
.
Usage
tidy_survfit(x, times = NULL, type = c("survival", "risk", "cumhaz"))
Arguments
- x
a 'survfit' object created with
survfit2()
- times
numeric vector of times. Default is
NULL
, which returns all observed times.- type
type of statistic to report. Available for Kaplan-Meier estimates only. Default is
"survival"
. Must be one of the following:type transformation "survival"
x
"risk"
1 - x
"cumhaz"
-log(x)
Examples
survfit2(Surv(time, status) ~ factor(ph.ecog), data = df_lung) %>%
tidy_survfit()
#> # A tibble: 220 × 16
#> time n.risk n.event n.censor cum.e…¹ cum.c…² estim…³ std.e…⁴ conf.…⁵ conf.…⁶
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0 63 0 0 0 0 1 0 1 1
#> 2 0.164 63 1 0 1 0 0.984 0.0160 1 0.954
#> 3 0.361 62 1 0 2 0 0.968 0.0228 1 0.926
#> 4 0.493 61 1 0 3 0 0.952 0.0282 1 0.901
#> 5 1.02 60 1 0 4 0 0.937 0.0328 0.999 0.878
#> 6 1.74 59 1 0 5 0 0.921 0.0370 0.990 0.856
#> 7 2.14 58 1 0 6 0 0.905 0.0409 0.980 0.835
#> 8 2.66 57 1 0 7 0 0.889 0.0445 0.970 0.815
#> 9 4.83 56 1 0 8 0 0.873 0.0480 0.959 0.795
#> 10 5.45 55 1 0 9 0 0.857 0.0514 0.948 0.775
#> # … with 210 more rows, 6 more variables: strata <fct>, estimate_type <chr>,
#> # estimate_type_label <chr>, monotonicity_type <chr>, strata_label <chr>,
#> # conf.level <dbl>, and abbreviated variable names ¹cum.event, ²cum.censor,
#> # ³estimate, ⁴std.error, ⁵conf.high, ⁶conf.low