time-dependent-comparison.R 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. library(tidyverse)
  2. csstd <- new.env()
  3. no_tunnel <- new.env()
  4. tunnel9 <- new.env()
  5. tunnel98 <- new.env()
  6. phase_type <- new.env()
  7. system.time(source("time-dependent-CSSTD.R", echo = TRUE, local = csstd))
  8. system.time(source("time-dependent-no-tunnel-states.R", echo = TRUE, local = no_tunnel))
  9. system.time(source("time-dependent-9-tunnel-states.R", echo = TRUE, local = tunnel9))
  10. system.time(source("time-dependent-98-tunnel-states.R", echo = TRUE, local = tunnel98))
  11. system.time(source("time-dependent-phase-type.R", echo = TRUE, local = phase_type))
  12. res <-
  13. tibble(
  14. cycle = csstd$cycles,
  15. diseased.csstd = csstd$state_membership[, 2],
  16. diseased.no_tunnel = no_tunnel$state_membership[, 2],
  17. diseased.tunnel9 = tunnel9$summarised_state_membership[, 2],
  18. diseased.tunnel98 = tunnel98$summarised_state_membership[, 2],
  19. diseased.phase_type = phase_type$summarised_state_membership[, 2],
  20. survival.csstd = 1 - csstd$state_membership[, 3],
  21. survival.no_tunnel = 1 - no_tunnel$state_membership[, 3],
  22. survival.tunnel9 = 1 - tunnel9$summarised_state_membership[, 3],
  23. survival.tunnel98 = 1 - tunnel98$summarised_state_membership[, 3],
  24. survival.phase_type = 1 - phase_type$summarised_state_membership[, 3]) %>%
  25. pivot_longer(cols = -cycle, names_to = c(".value", "method"), names_sep = "\\.") %>%
  26. left_join(
  27. tibble(
  28. method = c("csstd", "no_tunnel", "tunnel9", "tunnel98", "phase_type"),
  29. description = c("CSSTD", "No tunnel states", "Nine tunnel states", "98 tunnel states", "Phase-type")))
  30. ggplot(res, aes(x = cycle, y = diseased, colour = description, linetype = description)) +
  31. geom_line() +
  32. labs(x = "Cycle", y = "Proportion of cohort in Diseased state", colour = NULL, linetype = NULL) +
  33. theme_bw()
  34. ggsave("time-dependent-diseased.png", width = 15.92, height = 15.92 * 3/4, units = "cm", dpi = 600)
  35. ggplot(res, aes(x = cycle, y = survival, colour = description, linetype = description)) +
  36. geom_line() +
  37. labs(x = "Cycle", y = "Proportion of cohort alive", colour = NULL, linetype = NULL) +
  38. theme_bw()
  39. ggsave("time-dependent-survival.png", width = 15.92, height = 15.92 * 3/4, units = "cm", dpi = 600)