secmalasct/survival.R

60 lines
1.9 KiB
R

# secMalASCT survival calculation
#
# License: GPL version 3
# Jens Mathis Sauer (c) 2020
library(survival)
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() {
plot(survfit(surv_dx ~ 1), mark.time = TRUE, xscale = 365.25,
xlab = "Years", ylab = "Survival")
title("Kaplan-Meier estimate for\nsecMalASCT study",
"Survival after diagnosis")
}
# plot survival after diagnosis per sex
sma_plot_surv_dx_sex <- function() {
plot(survfit(surv_dx ~ sex, data = secmal), mark.time = TRUE,
xscale = 365.25, xlab = "Years", ylab = "Survival",
lty = 2:3)
title("Kaplan-Meier estimate for\nsecMalASCT study",
"Survival after diagnosis")
legend(100, .9, c("Female", "Male"), lty = 2:3)
}
# plot survival after transplantation
sma_plot_surv_asct <- function() {
plot(survfit(surv_asct ~ 1), mark.time = TRUE, xscale = 365.25,
xlab = "Years", ylab = "Survival")
title("Kaplan-Meier estimate for\nsecMalASCT study",
"Survival after transplantation")
}
# plot survival after transplantation per sex
sma_plot_surv_asct_sex <- function() {
plot(survfit(surv_asct ~ sex, data = secmal), mark.time = TRUE,
xscale = 365.25, xlab = "Years", ylab = "Survival",
lty = 2:3)
title("Kaplan-Meier estimate for\nsecMalASCT study",
"Survival after transplantation")
legend(100, .9, c("Female", "Male"), lty = 2:3)
}
#
# 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)
}