Extract 95% confidence interval values from kaplan meier model

115 Views Asked by At

After computing a kaplan meier model I get the km_fit list below. How can I extract 95% confidence interval values now?

# Plot Kaplan-Meier curves
sg1_survival <- Surv(
  time = sg1$`Time from breast cancer diagnosis to bone metastasis (months) (NA = unknown)`,
  event = sg1$`status (=1 as all pts have bone metastasis and BC)`
)


km_fit <- survfit(sg1_survival ~ sg1$`Molecular type (0=hr+her2+, 1=hr+her2-, 2=hr-her2+, 3=TNBC)`, data = sg1)

# Calculate 95% confidence intervals? fails with "no applicable method"
ci <- confint(km_fit, level = 0.95)
2

There are 2 best solutions below

3
On BEST ANSWER

It's all in km_fit.


km_fit <- survfit(sg1_survival ~ sg1$`Molecular type (0=hr+her2+, 1=hr+her2-, 2=hr-her2+, 3=TNBC)`, data = sg1)
c <- data.frame(km_fit$time, km_fit$lower, km_fit$upper) 
c

 sum.time  sum.lower sum.upper
1  28.37260 0.29950713         1
2  34.15890 0.06727839         1
3 137.32603         NA        NA
4  14.00548 0.12504883         1
5  75.02466         NA        NA

2
On

Please try the broom package as below and check conf.high & conf.low

new_km_fit <- broom::tidy(km_fit)


# A tibble: 5 × 9
   time n.risk n.event n.censor estimate std.error conf.high conf.low strata                         
  <dbl>  <dbl>   <dbl>    <dbl>    <dbl>     <dbl>     <dbl>    <dbl> <chr>                          
1  28.4      3       1        0    0.667     0.408         1   0.300  sg1$`Molecular type (0=hr+her2…
2  34.2      2       1        0    0.333     0.816         1   0.0673 sg1$`Molecular type (0=hr+her2…
3 137.       1       1        0    0       Inf            NA  NA      sg1$`Molecular type (0=hr+her2…
4  14.0      2       1        0    0.5       0.707         1   0.125  sg1$`Molecular type (0=hr+her2…
5  75.0      1       1        0    0       Inf            NA  NA      sg1$`Molecular type (0=hr+her2…