Skip to content

Commit

Permalink
Use [start,end) notation for age groups
Browse files Browse the repository at this point in the history
Fix #15
  • Loading branch information
Bisaloo committed Nov 2, 2024
1 parent ab1cae6 commit 6b440f6
Show file tree
Hide file tree
Showing 24 changed files with 12 additions and 11 deletions.
8 changes: 5 additions & 3 deletions data-raw/contact_matrices_2017.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
owd <- setwd(tempdir())
owd <- getwd()

setwd(tempdir())

fix_names <- function(name) {

Expand Down Expand Up @@ -49,7 +51,7 @@ for (l in locations) {
skip = 1,
.name_repair = "minimal"
))
rownames(df) <- colnames(df) <- sprintf("%02i_%02i", seq(0, 75, 5), seq(5, 80, 5))
rownames(df) <- colnames(df) <- sprintf("[%02i,%02i)", seq(0, 75, 5), seq(5, 80, 5))
c <- fix_names(c)
res[[c]] <- df
}
Expand All @@ -60,7 +62,7 @@ for (l in locations) {
sheet = c,
.name_repair = "minimal"
))
rownames(df) <- colnames(df) <- sprintf("%02i_%02i", seq(0, 75, 5), seq(5, 80, 5))
rownames(df) <- colnames(df) <- sprintf("[%02i,%02i)", seq(0, 75, 5), seq(5, 80, 5))
c <- fix_names(c)
res[[c]] <- df
}
Expand Down
9 changes: 4 additions & 5 deletions data-raw/contact_matrices_2020.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
owd <- setwd(tempdir())

system("svn export https://github.com/kieshaprem/synthetic-contact-matrices/trunk/output/syntheticmatrices")
# Download https://github.com/kieshaprem/synthetic-contact-matrices/tree/master/output/syntheticmatrices
files <- unzip("syntheticmatrices.zip", exdir = "syntheticmatrices", unzip = "internal")

library(fs)

Expand Down Expand Up @@ -28,13 +27,13 @@ for (i in seq_along(fichiers)) {

res <- lapply(eval(parse(text = dataset)), function(df) {

rownames(df) <- colnames(df) <- sprintf("%02i_%02i", seq(0, 75, 5), seq(5, 80, 5))
rownames(df) <- colnames(df) <- sprintf("[%02i,%02i)", seq(0, 75, 5), seq(5, 80, 5))
return(df)

})

names(res) <- countrycode::countrycode(names(res), origin = "iso3c", destination = "cldr.short.en")

saveRDS(res, paste0(owd, "/inst/extdata/", new_names_all[[i]]))
saveRDS(res, paste0("inst/extdata/", new_names_all[[i]]))

}
6 changes: 3 additions & 3 deletions data-raw/population.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ population_byage <- vroom::vroom(file.path("data-raw", "idb5yr.all")) %>%
# we need to sum
group_by(country) %>%
summarise(across(everything(), sum)) %>%
rowwise() %>%
mutate("75+" = sum(`75_79`, `80_84`, `85_89`, `90_94`, `95_99`), .keep = "unused") %>%
tidyr::pivot_longer(-country, names_to = "age", values_to = "population") %>%
mutate(age = gsub("^(\\d)_(\\d)$", "0\\1_0\\2", age)) %>%
tidyr::separate(age, into = c("age_start", "age_end"), sep = "_") %>%
dplyr::mutate(across(c(age_start, age_end), as.integer)) %>%
mutate(age = sprintf("[%02i,%02i)", age_start, age_end+1)) %>%
arrange(country, age) %>%
as.data.frame()

Expand Down
Binary file modified inst/extdata/contact_2017_all_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2017_home_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2017_other_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2017_school_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2017_work_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_all_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_all_rural.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_all_urban.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_home_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_home_rural.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_home_urban.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_other_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_other_rural.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_other_urban.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_school_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_school_rural.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_school_urban.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_work_all.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_work_rural.rds
Binary file not shown.
Binary file modified inst/extdata/contact_2020_work_urban.rds
Binary file not shown.
Binary file modified inst/extdata/population_byage.rds
Binary file not shown.

0 comments on commit 6b440f6

Please sign in to comment.