library(tidyverse) csstd <- new.env() no_tunnel <- new.env() tunnel9 <- new.env() tunnel98 <- new.env() phase_type <- new.env() system.time(source("time-dependent-CSSTD.R", echo = TRUE, local = csstd)) system.time(source("time-dependent-no-tunnel-states.R", echo = TRUE, local = no_tunnel)) system.time(source("time-dependent-9-tunnel-states.R", echo = TRUE, local = tunnel9)) system.time(source("time-dependent-98-tunnel-states.R", echo = TRUE, local = tunnel98)) system.time(source("time-dependent-phase-type.R", echo = TRUE, local = phase_type)) res <- tibble( cycle = csstd$cycles, diseased.csstd = csstd$state_membership[, 2], diseased.no_tunnel = no_tunnel$state_membership[, 2], diseased.tunnel9 = tunnel9$summarised_state_membership[, 2], diseased.tunnel98 = tunnel98$summarised_state_membership[, 2], diseased.phase_type = phase_type$summarised_state_membership[, 2], survival.csstd = 1 - csstd$state_membership[, 3], survival.no_tunnel = 1 - no_tunnel$state_membership[, 3], survival.tunnel9 = 1 - tunnel9$summarised_state_membership[, 3], survival.tunnel98 = 1 - tunnel98$summarised_state_membership[, 3], survival.phase_type = 1 - phase_type$summarised_state_membership[, 3]) %>% pivot_longer(cols = -cycle, names_to = c(".value", "method"), names_sep = "\\.") %>% left_join( tibble( method = c("csstd", "no_tunnel", "tunnel9", "tunnel98", "phase_type"), description = c("CSSTD", "No tunnel states", "Nine tunnel states", "98 tunnel states", "Phase-type"))) ggplot(res, aes(x = cycle, y = diseased, colour = description, linetype = description)) + geom_line() + labs(x = "Cycle", y = "Proportion of cohort in Diseased state", colour = NULL, linetype = NULL) + theme_bw() ggsave("time-dependent-diseased.png", width = 15.92, height = 15.92 * 3/4, units = "cm", dpi = 600) ggplot(res, aes(x = cycle, y = survival, colour = description, linetype = description)) + geom_line() + labs(x = "Cycle", y = "Proportion of cohort alive", colour = NULL, linetype = NULL) + theme_bw() ggsave("time-dependent-survival.png", width = 15.92, height = 15.92 * 3/4, units = "cm", dpi = 600)