From fcd2d330aae6dbed3b3210cedaba4cfb42de91b5 Mon Sep 17 00:00:00 2001 From: Jens Sauer Date: Tue, 17 Nov 2020 18:08:45 +0100 Subject: [PATCH] Add secondary malignancy plots This adds some plots to show data for the secondary malignacies. --- .gitignore | 2 +- README.md | 5 ++++ secmal.R | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 secmal.R diff --git a/.gitignore b/.gitignore index ca5938d..f49da9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .RData .Rhistory -survival_* +*.png *.csv diff --git a/README.md b/README.md index 399de6b..282a288 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,11 @@ survival.R Source this file and call one of the plot functions to show plot in R. `sma_plot_file_surv()` will save all plots to files. +secmal.R +-------- +This file contains the secondary malignancy plots. You can call the +functions in R or `sma_plot_file_secmal()` to save them to files. + plot_survival.R --------------- Special script to generate all plots and save them in files. diff --git a/secmal.R b/secmal.R new file mode 100644 index 0000000..157787e --- /dev/null +++ b/secmal.R @@ -0,0 +1,87 @@ +# Secondary malignancies calculations +# +# License: GPL version 3 +# Jens Mathis Sauer (c) 2020 + +source("utils.R") +sma_init() + +# Setup survival object +surv_sec <- Surv(time = secmal$time_at_risk, event = secmal$time_at_risk_status) + +# plot cummulative events +sma_plot_secmal_event <- function() { + ggsurvplot(survfit(surv_sec ~ 1), data = secmal, xscale = "d_y", + title = "Secondary malignacies", + fun = "event", + break.time.by = sma_break.time.by, + surv.median.line = "hv", + risk.table = "nrisk_cumevents", + ggtheme = theme_bw()) +} + +# plot cummulative hazard +sma_plot_secmal_haz <- function() { + ggsurvplot(survfit(surv_sec ~ 1), data = secmal, xscale = "d_y", + title = "Secondary malignacies", + fun = "cumhaz", + break.time.by = sma_break.time.by, + risk.table = "abs_pct", + ggtheme = theme_bw()) +} + +# plot cummulative events per sex +sma_plot_secmal_event_sex <- function() { + ggsurvplot(survfit(surv_sec ~ sex, data = secmal), data = secmal, xscale = "d_y", + title = "Secondary malignacies", + fun = "event", + break.time.by = sma_break.time.by, + surv.median.line = "hv", + risk.table = "nrisk_cumevents", + pval = TRUE, + ggtheme = theme_bw()) +} + +# plot cummulative hazard per sex +sma_plot_secmal_haz_sex <- function() { + ggsurvplot(survfit(surv_sec ~ sex, data = secmal), data = secmal, xscale = "d_y", + title = "Secondary malignacies", + fun = "cumhaz", + surv.median.line = "hv", + break.time.by = sma_break.time.by, + risk.table = "abs_pct", + pval = TRUE, + ggtheme = theme_bw()) +} + +# plot cummulative events per diagnosis +sma_plot_secmal_event_dx <- function() { + ggsurvplot(survfit(surv_sec ~ diagnosis, data = secmal), data = secmal, xscale = "d_y", + title = "Secondary malignacies", + fun = "event", + break.time.by = sma_break.time.by, + risk.table = "nrisk_cumevents", + pval = TRUE, + ggtheme = theme_bw()) +} + +# plot cummulative hazard per diagnosis +sma_plot_secmal_haz_dx <- function() { + ggsurvplot(survfit(surv_sec ~ diagnosis, data = secmal), data = secmal, xscale = "d_y", + title = "Secondary malignacies", + fun = "cumhaz", + break.time.by = sma_break.time.by, + risk.table = "abs_pct", + pval = TRUE, + ggtheme = theme_bw()) +} + +# Write secondary malignancy plots to files +sma_plot_file_secmal <- function() { + sma_plot_file("secmal_event.png", png, sma_plot_secmal_event) + sma_plot_file("secmal_haz.png", png, sma_plot_secmal_haz) + sma_plot_file("secmal_event_sex.png", png, sma_plot_secmal_event_sex) + sma_plot_file("secmal_haz_sex.png", png, sma_plot_secmal_haz_sex) + sma_plot_file("secmal_event_dx.png", png, sma_plot_secmal_event_dx) + sma_plot_file("secmal_haz_dx.png", png, sma_plot_secmal_haz_dx) +}