secmalasct/survival.R
Jens Sauer 3c160c37bb Set global break.time.by value for ggsurvplot
Substitute manual "break.time.by" values with global which can be used
by all plots.
2020-11-17 14:32:59 +01:00

69 lines
2.0 KiB
R

# secMalASCT survival calculation
#
# License: GPL version 3
# Jens Mathis Sauer (c) 2020
library(survival)
library(survminer)
source("utils.R")
secmal <- sma_load_data("current.csv")
# Setup survival object
surv_dx <- Surv(time = secmal$event_time_dx, event = secmal$event_status)
surv_asct <- Surv(time = secmal$event_time_asct, event = secmal$event_status)
# plot survival after diagnosis
sma_plot_surv_dx <- function() {
ggsurvplot(survfit(surv_dx ~ 1), data = secmal, xscale = "d_y",
title = "Survival after diagnosis",
break.time.by = sma_break.time.by,
surv.median.line = "hv",
risk.table = "abs_pct",
ggtheme = theme_bw())
}
# plot survival after diagnosis per sex
sma_plot_surv_dx_sex <- function() {
ggsurvplot(survfit(surv_dx ~ sex, data = secmal), data = secmal,
xscale = "d_y", title = "Survival after diagnosis",
legend.labs = c("Female", "Male"),
break.time.by = sma_break.time.by,
surv.median.line = "hv",
risk.table = "abs_pct",
ggtheme = theme_bw(),
pval = TRUE)
}
# plot survival after transplantation
sma_plot_surv_asct <- function() {
ggsurvplot(survfit(surv_asct ~ 1), data = secmal, xscale = "d_y",
title = "Survival after transplantation",
break.time.by = sma_break.time.by,
surv.median.line = "hv",
risk.table = "abs_pct",
ggtheme = theme_bw())
}
# plot survival after transplantation per sex
sma_plot_surv_asct_sex <- function() {
ggsurvplot(survfit(surv_asct ~ sex, data = secmal), data = secmal,
xscale = "d_y", title = "Survival after transplantation",
legend.labs = c("Female", "Male"),
break.time.by = sma_break.time.by,
surv.median.line = "hv",
risk.table = "abs_pct",
ggtheme = theme_bw(),
pval = TRUE)
}
#
# Write survival plots to files
#
sma_plot_file_surv <- function() {
sma_plot_file("survival_dx.png", png, sma_plot_surv_dx)
sma_plot_file("survival_dx_sex.png", png, sma_plot_surv_dx_sex)
sma_plot_file("survival_asct.png", png, sma_plot_surv_asct)
sma_plot_file("survival_asct_sex.png", png, sma_plot_surv_asct_sex)
}