Skip to content

Commit

Permalink
v0.14.4 - fix bug in data processing to mage sure we get the same res…
Browse files Browse the repository at this point in the history
…ults in every operating mode of the dashboard.
  • Loading branch information
mpascariu committed Dec 19, 2023
1 parent 1f44fc2 commit c4ed4a1
Show file tree
Hide file tree
Showing 5 changed files with 556 additions and 543 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: lemur
Title: Life expectancy monitor upscaled in R
Version: 0.14.3
Version: 0.14.4
Authors@R: c(
person("Marius D.", "Pascariu", role = c("aut", "cre", "cph"), email = "rpascariu@outlook.com", comment = c(ORCID = "0000-0002-2568-6489")),
person("Jose Manuel", "Aburto", role = "aut", comment = c(ORCID = "0000-0002-2926-6879")),
Expand Down
41 changes: 23 additions & 18 deletions R/app_process_data.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -------------------------------------------------------------- #
# Author: Marius D. PASCARIU
# Last Update: Tue Dec 5 22:08:41 2023
# Last Update: Tue Dec 19 22:08:15 2023
# -------------------------------------------------------------- #

# somebody should merge these functions in 1?

# ----------------------------------------------------------------------------
# PROCESS DATA

Expand All @@ -16,6 +18,8 @@ prepare_data_mode_cod <- function(cod,
sex,
cod_change) {

region <- NULL

# Select cod and lt for 1 region
# If no risk change is applied the tables before and after are the same
# not change in LE no decomposition
Expand Down Expand Up @@ -56,25 +60,25 @@ prepare_data_mode_cntr <- function(cod,
region <- NULL

# select cod and lt tables for 2 regions
c1 <- cod[cod$region == region1 & cod$sex == sex, ]
c2 <- cod[cod$region == region2 & cod$sex == sex, ]
l1 <- lt[lt$region == region1 & lt$sex == sex, ]
l2 <- lt[lt$region == region2 & lt$sex == sex, ]
c1_init <- c1 <- cod[cod$region == region1 & cod$sex == sex, ]
c2_init <- c2 <- cod[cod$region == region2 & cod$sex == sex, ]
l1_init <- l1 <- lt[lt$region == region1 & lt$sex == sex, ]
l2_init <- l2 <- lt[lt$region == region2 & lt$sex == sex, ]

# IF we look at 2 regions and we change the risks
# we need to adjust the cod and lt tables for both regions
logic <- any(cod_change != 0)
if (logic) {
c1 <- modify_cod_table(c1, cod_change)
c2 <- modify_cod_table(c2, cod_change)
l1 <- modify_life_table(l1, c1, cod_change)
l2 <- modify_life_table(l2, c2, cod_change)
c1 <- modify_cod_table(c1_init, cod_change)
c2 <- modify_cod_table(c2_init, cod_change)
l1 <- modify_life_table(l1_init, c1_init, cod_change)
l2 <- modify_life_table(l2_init, c2_init, cod_change)
}

lv <- if (region1 == region2) region1 else c(region1, region2)
c1 <- mutate(c1, region = factor(region, levels = lv))
c2 <- mutate(c2, region = factor(region, levels = lv))

out <- list(
cod_initial = c1,
cod_final = c2,
Expand All @@ -96,21 +100,22 @@ prepare_data_mode_sex <- function(cod,
cod_change){

region <- NULL
sex <- NULL

# select cod and lt tables for the 2 sexes
c1 <- cod[cod$region == region1 & cod$sex == "male" , ]
c2 <- cod[cod$region == region1 & cod$sex == "female", ]
l1 <- lt[lt$region == region1 & lt$sex == "male", ]
l2 <- lt[lt$region == region1 & lt$sex == "female", ]
c1_init <- c1 <- cod[cod$region == region1 & cod$sex == "male" , ]
c2_init <- c2 <- cod[cod$region == region1 & cod$sex == "female", ]
l1_init <- l1 <- lt[lt$region == region1 & lt$sex == "male", ]
l2_init <- l2 <- lt[lt$region == region1 & lt$sex == "female", ]

# IF we look at 2 gender and we change the risks
# we need to adjust the cod and lt tables for both populations
logic <- any(cod_change != 0)
if (logic) {
c1 <- modify_cod_table(c1, cod_change)
c2 <- modify_cod_table(c2, cod_change)
l1 <- modify_life_table(l1, c1, cod_change)
l2 <- modify_life_table(l2, c2, cod_change)
c1 <- modify_cod_table(c1_init, cod_change)
c2 <- modify_cod_table(c2_init, cod_change)
l1 <- modify_life_table(l1_init, c1_init, cod_change)
l2 <- modify_life_table(l2_init, c2_init, cod_change)
}

out <- list(
Expand Down
Loading

0 comments on commit c4ed4a1

Please sign in to comment.