From 62a9f9e94b85a5288301a0b22ea7f10dbca82f11 Mon Sep 17 00:00:00 2001 From: Ali Abbas Date: Wed, 6 Nov 2024 18:16:57 +0000 Subject: [PATCH] Mutate all combined dead states with dead --- summary_script.R | 42 ++++++++++++++++++++++++++---------------- tbl.csv | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 tbl.csv diff --git a/summary_script.R b/summary_script.R index b37d86d..583177c 100644 --- a/summary_script.R +++ b/summary_script.R @@ -9,16 +9,25 @@ set.seed(1024) health_base <- read_csv("C:/Users/Ali/RMIT University/JIBE working group - simulationResults/ForUrbanTransition/reference/health/04_death_and_disease/pp_healthDiseaseTracker_2039_fixBug_processed.csv") -health_cyc <- read_csv("C:/Users/Ali/RMIT University/JIBE working group - simulationResults/ForUrbanTransition/cycleIntervention/health/04_death_and_disease/pp_healthDiseaseTracker_2039_new_processed.csv") +health_cyc <- read_csv("C:/Users/Ali/RMIT University/JIBE working group - simulationResults/ForUrbanTransition/cycleIntervention/health/04_death_and_disease/pp_healthDiseaseTracker_2039_new_fixBug_processed.csv") # Set sample size -sample_size <- 100000 +sample_size <- 1000000 # Keep until 2039 -health_base <- health_base |> dplyr::select(1:21) |> slice_sample(n = sample_size) +health_base <- health_base |> dplyr::select(1:21) #|> slice_sample(n = sample_size) + +health_base_dead <- health_base |> pivot_longer(cols = -id) |> filter(str_detect(value, "dead")) |> mutate(value = "dead") |> pivot_wider(id_cols=id) + +health_base <- rows_update(health_base, health_base_dead) # Keep until 2039 -health_cyc <- health_cyc |> dplyr::select(1:21) |> slice_sample(n = sample_size) +health_cyc <- health_cyc |> dplyr::select(1:21) #|> slice_sample(n = sample_size) + +health_cyc_dead <- health_cyc |> pivot_longer(cols = -id) |> filter(str_detect(value, "dead")) |> mutate(value = "dead") |> pivot_wider(id_cols=id) + +health_cyc <- rows_update(health_cyc, health_cyc_dead) + get_expanded_rows <- function(health_base_fr){ health_base_fr |> @@ -30,20 +39,16 @@ get_expanded_rows <- function(health_base_fr){ } -tic() # Expand each row separated by | character health_base_summary <- get_expanded_rows(health_base) -toc() - # Expand each row separated by | character health_cyc_summary <- get_expanded_rows(health_cyc) # States -states_base_sum <- health_base_summary |> +states_base_sum <- health_base_summary |> filter(!is.na(value) & !value %in% c("dead", "null")) |> group_by(name, value)|> - summarise(nv = dplyr::n(), - freq = round(100 * nv / sample_size, 1), scenario = "reference") + summarise(nv = dplyr::n(), scenario = "reference") |> mutate(sumnv = sum(nv), freq = round(100 * nv / sumnv, 1)) ggplot(states_base_sum) + @@ -67,10 +72,9 @@ ggplot(states_base_freq) + # States -states_cyc_sum <- health_cyc_summary |> +states_cyc_sum <- health_cyc_summary |> filter(!is.na(value) & !value %in% c("dead", "null")) |> group_by(name, value)|> - summarise(nv = dplyr::n(), - freq = round(100 * nv / sample_size, 1), scenario = "cycling intervention") + summarise(nv = dplyr::n(), scenario = "cycling intervention") |> mutate(sumnv = sum(nv), freq = round(100 * nv / sumnv, 1)) ggplot(states_cyc_sum) + @@ -103,9 +107,11 @@ plotly::ggplotly(combine_summary %>% theme(axis.text.x = element_text(angle = 90L)) + facet_wrap(vars(value))) -tbl <- combine_summary |> filter(value %in% c("healty", "null")) |> group_by(scenario, name) |> summarise(count = sum(nv)) +tbl <- combine_summary |> filter(!value %in% c("dead", "null")) |> group_by(scenario, name) |> summarise(count = sum(nv)) -ggplot(tbl) + +g <- + + ggplot(tbl) + aes(x = name, y = count, fill = scenario) + geom_col(position = "dodge2") + scale_fill_hue(direction = 1) + @@ -114,4 +120,8 @@ ggplot(tbl) + y = "Count", title = "Cumulative alive people over time" ) + - theme_minimal() + theme_minimal() + + geom_text(aes(label = count), + position = position_dodge(width = .9)) + +plotly::ggplotly(g) diff --git a/tbl.csv b/tbl.csv new file mode 100644 index 0000000..7279949 --- /dev/null +++ b/tbl.csv @@ -0,0 +1,41 @@ +scenario,name,count +reference,2020,2826689 +reference,2021,2250008 +reference,2022,2288800 +reference,2023,2329358 +reference,2024,2371010 +reference,2025,2414320 +reference,2026,2458223 +reference,2027,2503078 +reference,2028,2549193 +reference,2029,2596873 +reference,2030,2645991 +reference,2031,2696058 +reference,2032,2747586 +reference,2033,2801061 +reference,2034,2856383 +reference,2035,2913349 +reference,2036,2972498 +reference,2037,3034245 +reference,2038,3098010 +reference,2039,3164358 +cycling intervention,2020,2826606 +cycling intervention,2021,2253432 +cycling intervention,2022,2292378 +cycling intervention,2023,2333055 +cycling intervention,2024,2375060 +cycling intervention,2025,2418386 +cycling intervention,2026,2462277 +cycling intervention,2027,2507152 +cycling intervention,2028,2553318 +cycling intervention,2029,2601060 +cycling intervention,2030,2649387 +cycling intervention,2031,2699348 +cycling intervention,2032,2750782 +cycling intervention,2033,2804046 +cycling intervention,2034,2859117 +cycling intervention,2035,2916441 +cycling intervention,2036,2975464 +cycling intervention,2037,3037479 +cycling intervention,2038,3100950 +cycling intervention,2039,3168105