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!