I am using
survfit object from package
survminer to draw a survival curve in ggplot. Now I am trying to understand how I can use that same object from method
survfit and calculate the P-value up to a specific time (e.g. 365 days, instead of the whole 2500+ days curve).
On stackoverflow I posted the following very similar question R draw survival curve and calculate P-value at specific times!
The answer helped me to draw a vertical line at 365 for indicative purpose and calculate the z-score / z-test up at 365 days.
fit1 <- survfit(Surv(dat$diff_in_days, dat$survivalstat)~Schedule,data = dat) #turn into df df <- broom::tidy(fit1) fit_df <- df %>% #group by strata group_by(strata) %>% #get day of interest or day before it filter(time <= 365) %>% arrange(time) %>% # pull last date do(tail(.,1)) #calculate z score based on 2 sample test at that time point z <- (fit_df$estimate-fit_df$estimate) / (sqrt( fit_df$std.error^2+ fit_df$std.error^2)) #get probability of z score pz <- pnorm(abs(z)) #get p value pvalue <- round(2 * (1-pz),2) ggsurv <- ggsurvplot( fit1, data = dat, pval = TRUE, pval.size = 4, pval.method = TRUE, pval.method.size = 3, log.rank.weights = "1", conf.int = TRUE, conf.int.style = "ribbon", conf.int.alpha = 0.2, xlab = "Time in days", tables.theme = theme_cleantable(), ggtheme = theme_bw() ) ggsurv$plot <- ggsurv$plot + geom_vline(aes(xintercept=365))+ geom_text(aes(x = 500,y=.8,label = paste0("p = " ,pvalue) )) print(ggsurv)
I am relatively new to R and especially statistics. How can I calculate the log-rank (external requirement) of the survival curve upto 365 days? instead of the z-score in above's code.
Aim is to see if there is a difference in survival between different treatment schedules. Some parts of the curve seem to deviate but later come together. I want to see if the difference at certain points is statistically significant instead of the entire curve. patients with x treatment at 1 year have a higher survival probability than patients with x treatment.