Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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[1]-fit_df$estimate[2]) / (sqrt( fit_df$std.error[1]^2+ fit_df$std.error[2]^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)
Add Comment
Please, Sign In to add comment