Skip to content

Commit ff7cecb

Browse files
committed
upload - able to create age specific calendar impact
1 parent 7e44aba commit ff7cecb

File tree

3 files changed

+35
-39
lines changed

3 files changed

+35
-39
lines changed

DESCRIPTION

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Package: vimpact
22
Title: Vaccine Impact Calculation
3-
Version: 0.1.3
3+
Version: 0.1.4
44
Authors@R:
5-
c(person(given = "Rich",
6-
family = "FitzJohn",
5+
c(person(given = "Xiang",
6+
family = "Li",
77
role = c("aut", "cre"),
8-
email = "[email protected]"),
8+
email = "[email protected]"),
99
person("Imperial College of Science, Technology and Medicine",
1010
role = "cph"))
1111
Description: VIMC IMPACT CALCULATION PACKAGE. This package is mainly for the VIMC Science Team to investigate vaccination impact.
@@ -34,6 +34,6 @@ Suggests:
3434
RSQLite,
3535
withr
3636
Remotes: reside-ic/fakerbase
37-
RoxygenNote: 7.3.1
37+
RoxygenNote: 7.3.2
3838
VignetteBuilder: knitr
3939
Config/testthat/edition: 3

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# vimpact 0.1.4
2+
3+
* Produce age specific calendar impact.
4+
15
# vimpact 0.1.3
26

37
* Recognise new burden outcomes.

R/impact_central.R

+26-34
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
1-
get_raw_impact_details <- function(con, meta1, burden_outcome, is_under5 = FALSE, countries_to_extract = NULL){
1+
get_raw_impact_details <- function(con, meta1, burden_outcome, is_under5 = FALSE, countries_to_extract = NULL, age_specific = FALSE){
22
#verify parameters
33
stopifnot(nrow(meta1) == 2L)
44
stopifnot(burden_outcome %in% c("deaths", "cases", "dalys", "yll",
55
"deaths_cwyx", "cases_cwyx", "dalys_cwyx", "yll_cwyx")) # _cwyx outcomes are MenA specific.
66
stopifnot(is_under5 %in% c(TRUE, FALSE))
77

8-
#preparation
9-
# determine burden outcome, k will be used to determine burden outcome ids
10-
if(burden_outcome == "deaths"){
11-
k <- 1
12-
} else if(burden_outcome == "cases"){
13-
k <- 2
14-
} else if(burden_outcome == "dalys"){
15-
k <- 3
16-
} else if(burden_outcome == "yll"){
17-
k <- 4
18-
} else if(burden_outcome == "deaths_cwyx"){
19-
k <- 5
20-
} else if(burden_outcome == "cases_cwyx"){
21-
k <- 6
22-
} else if(burden_outcome == "dalys_cwyx"){
23-
k <- 7
24-
} else if(burden_outcome == "yll_cwyx"){
25-
k <- 8
26-
} else {
27-
stop("Can only take burden outcome as one of deaths, cases, dalys, yll, deaths_cwyx, cases_cwyx, dalys_cwyx, yll_cwyx")
28-
}
29-
308
# determine whether a recipe is for routine or campaign vaccine delivery
319
# routine or campaign matters for method2a in terms of the shape of burden estimates to extract
3210
# if routine, by year of birth
@@ -56,13 +34,22 @@ get_raw_impact_details <- function(con, meta1, burden_outcome, is_under5 = FALSE
5634

5735
# set up db extraction sql queries
5836
if((meta1$method[1] == "method0") || (meta1$method[1] == "method2a" && any(j))){
59-
sql <- paste("SELECT country, year AS time, sum(value) AS value",
60-
"FROM burden_estimate",
61-
"WHERE burden_estimate_set = %s",
62-
"AND burden_outcome IN %s",
63-
age_constrain,
64-
country_constrain,
65-
"GROUP BY country, year")
37+
if(meta1$method[1] == "method0" & age_specific){
38+
sql <- paste("SELECT country, year AS time, age, value",
39+
"FROM burden_estimate",
40+
"WHERE burden_estimate_set = %s",
41+
"AND burden_outcome IN %s",
42+
age_constrain,
43+
country_constrain)
44+
} else {
45+
sql <- paste("SELECT country, year AS time, sum(value) AS value",
46+
"FROM burden_estimate",
47+
"WHERE burden_estimate_set = %s",
48+
"AND burden_outcome IN %s",
49+
age_constrain,
50+
country_constrain,
51+
"GROUP BY country, year")
52+
}
6653
} else if((meta1$method[1] == "method1") || (meta1$method[1] == "method2a" && any(i)) || (meta1$method[1] == "method2b")){
6754
sql <- paste("SELECT country, (year-age) AS time, sum(value)AS value",
6855
"FROM burden_estimate",
@@ -75,18 +62,23 @@ get_raw_impact_details <- function(con, meta1, burden_outcome, is_under5 = FALSE
7562

7663
# get burden outcome ids
7764
i <- meta1$meta_type == "focal"
78-
ii <- unlist(strsplit(meta1$burden_outcome_id[i], ";"))
65+
ss_id <- unlist(strsplit(meta1$burden_outcome_id[i], ";"))
66+
ss_code <- unlist(strsplit(meta1$burden_outcome[i], ";"))
67+
ii <- ss_id[ss_code == burden_outcome]
68+
7969
j <- meta1$meta_type == "baseline"
80-
jj <- unlist(strsplit(meta1$burden_outcome_id[j], ";"))
70+
ss_id <- unlist(strsplit(meta1$burden_outcome_id[j], ";"))
71+
ss_code <- unlist(strsplit(meta1$burden_outcome[j], ";"))
72+
jj <- ss_id[ss_code == burden_outcome]
8173

8274
# extract burden estimates
8375
d_baseline <- DBI::dbGetQuery(con, sprintf(sql,
8476
sql_in(meta1$burden_estimate_set[j], text_item = FALSE),
85-
sql_in(jj[k], text_item = FALSE)))
77+
sql_in(jj, text_item = FALSE)))
8678

8779
d_focal <- DBI::dbGetQuery(con, sprintf(sql,
8880
sql_in(meta1$burden_estimate_set[i], text_item = FALSE),
89-
sql_in(ii[k], text_item = FALSE)))
81+
sql_in(ii, text_item = FALSE)))
9082
if(meta1$disease[1] == "HepB" && (nrow(d_focal) == 0L || nrow(d_baseline) == 0L)) {
9183
# when you are extracting data for HepB - IC and CDA models - for specific countries
9284
# you may end out with 0 rows for d_baseline or d_focal

0 commit comments

Comments
 (0)