Skip to content

Commit 6fdb29e

Browse files
committed
Add confidence interval as parameter. Produce cause specific burden output with confidence interval. Ref #94
1 parent 3908822 commit 6fdb29e

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

R/health_burden.R

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#' Compute health burden for populations in scenarios given relative risks
44
#'
55
#' @param ind_ap_pa data.frame of all individuals' relative risks for diseases
6+
#' @param conf_int logic: whether to include confidence interval from dose response relationships or not
67
#' @param combined_AP_PA=T logic: whether to combine the two exposure pathways (AP and PA) or to compute independently
78
#'
89
#' @return list of data.frames: one for deaths per disease per demographic group, and likewise for YLLs
910
#'
1011
#' @export
11-
health_burden <- function(ind_ap_pa,combined_AP_PA=T){
12+
health_burden <- function(ind_ap_pa, conf_int = F, combined_AP_PA = T){
1213

1314
demographic <- DEMOGRAPHIC
1415
demographic$dem_index <- 1:nrow(demographic)
@@ -31,6 +32,7 @@ health_burden <- function(ind_ap_pa,combined_AP_PA=T){
3132
# set up reference (scen1)
3233
reference_scenario <- SCEN_SHORT_NAME[which(SCEN==REFERENCE_SCENARIO)]
3334
scen_names <- SCEN_SHORT_NAME[SCEN_SHORT_NAME!=reference_scenario]
35+
3436
### iterating over all all disease outcomes
3537
for ( j in 1:nrow(DISEASE_INVENTORY)){
3638
# Disease acronym and full name
@@ -81,6 +83,59 @@ health_burden <- function(ind_ap_pa,combined_AP_PA=T){
8183
death_dfs <- combine_health_and_pif(pif_values=pif_scen,hc=gbd_deaths_disease)
8284
deaths[[deaths_name]] <- death_dfs[,V1]
8385
}
86+
87+
88+
if (conf_int){
89+
90+
for (conf_cols in c('lb', 'ub')){
91+
92+
base_var <- paste0('RR_', middle_bit, reference_scenario, '_', ac, '_', conf_cols)
93+
scen_vars <- paste0('RR_', middle_bit, scen_names, '_', ac, '_', conf_cols)
94+
# subset gbd data
95+
gbd_deaths_disease <- subset(gbd_deaths,cause==gbd_dn)
96+
gbd_ylls_disease <- subset(gbd_ylls,cause==gbd_dn)
97+
98+
if (!base_var %in% colnames(ind_ap_pa)){
99+
100+
ind_ap_pa[[base_var]] <- ind_ap_pa[[paste0('RR_', middle_bit, reference_scenario, '_', ac)]]
101+
102+
for (index in 1:length(scen_vars)){
103+
ind_ap_pa[[scen_vars[[index]]]] <-
104+
ind_ap_pa[[paste0('RR_', middle_bit, scen_names[index], '_', ac)]]
105+
}
106+
}
107+
108+
# set up pif tables
109+
pif_table <- setDT(ind_ap_pa[,colnames(ind_ap_pa)%in%c(base_var,'dem_index')])
110+
setnames(pif_table,base_var,'outcome')
111+
pif_ref <- pif_table[,.(sum(outcome)),by='dem_index']
112+
## sort pif_ref
113+
setorder(pif_ref,dem_index)
114+
for (index in 1:length(scen_vars)){
115+
# set up naming conventions
116+
scen <- scen_names[index]
117+
scen_var <- scen_vars[index]
118+
yll_name <- paste0(scen, '_ylls_',middle_bit,ac, '_', conf_cols)
119+
deaths_name <- paste0(scen, '_deaths_',middle_bit,ac, '_', conf_cols)
120+
# Calculate PIFs for selected scenario
121+
pif_table <- setDT(ind_ap_pa[,colnames(ind_ap_pa)%in%c(scen_var,'dem_index')])
122+
setnames(pif_table,scen_var,'outcome')
123+
pif_temp <- pif_table[,.(sum(outcome)),by='dem_index']
124+
## sort pif_temp
125+
setorder(pif_temp,dem_index)
126+
pif_scen <- (pif_ref[,2] - pif_temp[,2]) / pif_ref[,2]
127+
# Calculate ylls
128+
yll_dfs <- combine_health_and_pif(pif_values=pif_scen, hc = gbd_ylls_disease)
129+
ylls[[yll_name]] <- yll_dfs[,V1]
130+
# Calculate deaths
131+
death_dfs <- combine_health_and_pif(pif_values=pif_scen,hc=gbd_deaths_disease)
132+
deaths[[deaths_name]] <- death_dfs[,V1]
133+
}
134+
135+
}
136+
}
137+
138+
84139
}
85140
}
86141
deaths <- deaths[,-which(colnames(deaths)=='dem_index')]

0 commit comments

Comments
 (0)