pharmaverse / ggsurvfit

http://www.danieldsjoberg.com/ggsurvfit/
Other
70 stars 19 forks source link

Bug Report: UB and LB Confidence interval labels switched in `tidy_survfit` for multi-state model are wrong #215

Open therimalaya opened 3 months ago

therimalaya commented 3 months ago

I use tidy_survfit mostly for getting tidy tables to create customized plots. I noticed that for a multi-state model, the confidence interval names are switched. It shows lower as upper and vice-versa. The survfit without multi-state does not have the problem. Following is a small reproducible example,


library(ggsurvfit)
#> Loading required package: ggplot2

data(Melanoma, package = "MASS")
head(Melanoma)
#>   time status sex age year thickness ulcer
#> 1   10      3   1  76 1972      6.76     1
#> 2   30      3   1  56 1968      0.65     0
#> 3   35      2   1  41 1977      1.34     0
#> 4   99      3   0  71 1968      2.90     0
#> 5  185      1   1  52 1965     12.08     1
#> 6  204      1   1  28 1971      4.84     1
Melanoma$status <- factor(Melanoma$status, c(2, 1, 3), c("Alive", "Melanoma", "Other"))

sfit1 <- survfit(Surv(time, status == "Melanoma") ~ 1, data = Melanoma)
sfit <- survfit(Surv(time, status, type = "mstate") ~ 1, data = Melanoma)

ggsurvfit::tidy_survfit(sfit, times = 5 * 365.241)[-c(2:6)]
#> # A tibble: 2 × 10
#>    time estimate std.error conf.low conf.high outcome  estimate_type
#>   <dbl>    <dbl>     <dbl>    <dbl>     <dbl> <chr>    <chr>        
#> 1 1826.   0.224     0.0294   0.289     0.173  Melanoma cuminc       
#> 2 1826.   0.0442    0.0144   0.0837    0.0233 Other    cuminc       
#> # ℹ 3 more variables: estimate_type_label <chr>, monotonicity_type <chr>,
#> #   conf.level <dbl>
ggsurvfit::tidy_survfit(sfit1, times = 5 * 365.241)[-c(2:6)]
#> # A tibble: 1 × 9
#>    time estimate std.error conf.high conf.low estimate_type estimate_type_label 
#>   <dbl>    <dbl>     <dbl>     <dbl>    <dbl> <chr>         <chr>               
#> 1 1826.    0.769    0.0395     0.831    0.712 survival      Survival Probability
#> # ℹ 2 more variables: monotonicity_type <chr>, conf.level <dbl>

Created on 2024-06-06 with reprex v2.1.0

ddsjoberg commented 3 months ago

Thanks for the report @therimalaya ! Since we're focused on the visualization, the label of the UB and LB didn't have an effect on the result. But we should address this. Much appreciated