Search code examples
rsurvival-analysis

How to calculate confidence intervals for drug retention rates using survival analysis


I am new to survival analysis in R. I saw that my collegues managed to find drug retention rates at specific time intervals (6 month, 12 month, 24 month) with 95% CI. How would I do this?

Here is a reproducible example:

library(survival) 
library(survminer)
gender <- as.factor(c("Female", "Male", "Female", "Male", "Male", "Male", "Female", "Female", "Female", "Male"))
country <- as.factor(c("US", "US", "GB", "GB", "GB", "US", "GB", "US", "GB", "US"))
time <- c(5, 10, 12, 15, 20, 9, 14, 18, 24, 20)
event <- c(1, 1, 1, 1, 1, 0, 0, 1, 0, 1)
df <- data.frame(gender, country, time, event)
km.model <- survfit(Surv(time = df$time, event = df$event) ~ gender, data = df)
km.model
ggsurvplot (km.model, data = df, conf.int = TRUE, risk.table = "abs_pct", xlab = "Time in months")

Thanks in advance!


Solution

  • You could use summary with the needed time intervals: this will give the needed CI's.

    summary(km.model, times = seq(0, 24, 6))
    

    output:

      gender=Female 
     time n.risk n.event survival std.err lower 95% CI upper 95% CI
        0      5       0      1.0   0.000       1.0000            1
        6      4       1      0.8   0.179       0.5161            1
       12      4       1      0.6   0.219       0.2933            1
       18      2       1      0.3   0.239       0.0631            1
       24      1       0      0.3   0.239       0.0631            1
    
                    gender=Male 
     time n.risk n.event survival std.err lower 95% CI upper 95% CI
        0      5       0     1.00   0.000        1.000            1
        6      5       0     1.00   0.000        1.000            1
       12      3       1     0.75   0.217        0.426            1
       18      2       1     0.50   0.250        0.188            1