1

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!

Pashtun
  • 123
  • 7
  • It's easier to help you if you include a simple reproducible example: with sample input and desired output that can be used to test and verify possible solutions. – TarJae Sep 18 '21 at 17:54
  • Can you post sample data? Please edit **the question** with the output of `dput(data)`. Or, if it is too big with the output of `dput(head(data, 20))`. – Rui Barradas Sep 18 '21 at 18:11
  • 1
    @TarJae and Rui Barradas just added a reproducible example, hope this is sufficient. If you need more please let me know. – Pashtun Sep 18 '21 at 18:18

1 Answers1

1

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
TarJae
  • 72,363
  • 6
  • 19
  • 66