-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmer_report.Rmd
457 lines (365 loc) · 14.9 KB
/
mer_report.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
---
title: "Country Targeted HIV Testing Report"
author: "Ian E. Fellows"
output: html_document
params:
country:
label: "Country"
input: select
value: "Lesotho"
choices: ["Cote d'Ivoire", "Malawi", "Nigeria","Lesotho"]
editor_options:
chunk_output_type: console
---
```{r, echo=FALSE}
library(tidyverse)
library(ggplot2)
library(knitr)
library(xgboost)
library(Ckmeans.1d.dp)
knitr::opts_chunk$set(echo = FALSE)
if(!exists("dat_analysis2")){
country <- params$country
source("R/mer_globals.R")
filename <- paste0( "results/",stringr::str_replace_all(mer_data_source,"/","_"), "_results",".RData")
if(file.exists(filename)){
load(filename)
}else{
source("R/mer_main.R")
}
}
```
## `r country`
This workbook leverages MER structured data on HIV testing patterns and disaggregated Spectrum estimates of epidemic parameters to uncover opportunities to improved the targeting of HIV tests within `r country`. Categories with high yield, but with a relatively low number of tests compared to other categories may be good candidates for increased targeting.
## Data Checks
The table below displays the consistency between the "Total Numerator" and fully dissaggregated reported testing counts
```{r, echo=FALSE}
dat$count_check %>% kable()
```
The table below shows any negative counts. Negative counts are caused by deduplication adjustments
```{r, echo=FALSE}
dat$neg_check %>% kable()
```
## Descriptives
In this section we look at the yield rates by age and sex. Yield here is defined as the percentage of (non-index) HIV tests that result in a new diagnosis.
### Yield By Age
Age groups are broken down by as entered in DATIM. In most cases this should be 5 year age bands, but older data may have differing bands. Infant (<01 years old) tests are excluded from analysis.
```{r pressure, echo=FALSE}
age_descriptives <- dat_analysis %>%
filter(time == 0) %>%
group_by(age) %>%
summarise(observed_yield = sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
age_descriptives %>% mutate(observed_yield = observed_yield*100) %>% kable(digits=1)
```
```{r, out.width="100%"}
age_year_descriptives <- dat_analysis %>%
group_by(age, quarter) %>%
summarise(observed_yield = 100*sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
(
qplot(quarter, observed_yield, color=age, data=age_year_descriptives) +
geom_line(aes(x=as.numeric(quarter))) +
theme_bw()
) %>% plotly::ggplotly()
```
### Yield By Gender
```{r}
sex_descriptives <- dat_analysis %>%
filter(time == 0) %>%
group_by(sex) %>%
summarise(observed_yield = sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
sex_descriptives %>% mutate(observed_yield = observed_yield*100) %>% kable(digits=1)
```
```{r, out.width="100%"}
sex_year_descriptives <- dat_analysis %>%
group_by(sex, quarter) %>%
summarise(observed_yield = 100*sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
(
qplot(quarter, observed_yield, color=sex, data=sex_year_descriptives) +
geom_line(aes(x=as.numeric(quarter))) + geom_point(aes(y=0,x=1),alpha=0) +
theme_bw()
) %>% plotly::ggplotly()
```
### Yield By Modality
```{r, out.width="100%"}
descriptives <- dat_analysis %>%
filter(time == 0) %>%
group_by(modality) %>%
summarise(observed_yield = sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
descriptives %>% mutate(observed_yield = observed_yield*100) %>% kable(digits=1)
by_year_descriptives <- dat_analysis %>%
group_by(modality, quarter) %>%
summarise(observed_yield = 100*sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
(
qplot(quarter, observed_yield, color=modality, data=by_year_descriptives) +
geom_line(aes(x=as.numeric(quarter))) + geom_point(aes(y=0,x=1),alpha=0) +
theme_bw()
) %>% plotly::ggplotly()
```
```{r}
by_year_descriptives <- dat_analysis %>%
mutate(index = ifelse(modality %in% c("Index","IndexMod"), "index","nonindex")) %>%
group_by(index, quarter) %>%
summarise(
positives=sum(hiv_pos * weight),
total_tests = sum(weight)) %>%
pivot_wider(names_from = index, values_from=c(positives, total_tests)) %>%
mutate(index_tests_per_non_index_positive = total_tests_index / positives_nonindex) %>%
select(quarter, positives_nonindex, total_tests_index, index_tests_per_non_index_positive)
by_year_descriptives %>% kable(digits=1)
(
qplot(quarter, index_tests_per_non_index_positive, data=by_year_descriptives) +
geom_line(aes(x=as.numeric(quarter))) +
ylim(c(0,max(2.5, max(by_year_descriptives$index_tests_per_non_index_positive)))) +
ylab("# Index Tests / # Non-Index Positives") +
theme_bw()
) %>% plotly::ggplotly()
```
### Yield By Partner
```{r, out.width="100%"}
descriptives <- dat_analysis %>%
filter(time == 0) %>%
group_by(primepartner) %>%
summarise(observed_yield = sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
descriptives %>% mutate(observed_yield = observed_yield*100) %>% kable(digits=1)
by_year_descriptives <- dat_analysis %>%
group_by(primepartner, quarter) %>%
summarise(observed_yield = 100*sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
(
qplot(quarter, observed_yield, color=primepartner, data=by_year_descriptives) +
geom_line(aes(x=as.numeric(quarter))) + geom_point(aes(y=0,x=1),alpha=0) +
theme_bw()
) #%>% plotly::ggplotly()
```
## Yield by Site Type
```{r, out.width="100%"}
descriptives <- dat_analysis %>%
filter(time == 0) %>%
group_by(sitetype) %>%
summarise(observed_yield = sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
descriptives %>% mutate(observed_yield = observed_yield*100) %>% kable(digits=1)
by_year_descriptives <- dat_analysis %>%
group_by(sitetype, quarter) %>%
summarise(observed_yield = 100*sum(hiv_pos * weight) / sum(weight),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
(
qplot(quarter, observed_yield, color=sitetype, data=by_year_descriptives) +
geom_line(aes(x=as.numeric(quarter))) + geom_point(aes(y=0,x=1),alpha=0) +
theme_bw()
) %>% plotly::ggplotly()
```
# Model-Based Output
Yield rates can be affected by many factors, including:
* Susceptible population size
* Number of people living with HIV
* Number of HIV+ individuals on treatment
* Number of tests being done at a site
* Site type (community / facility)
* Prioritization (Aggressive, Saturation, or Sustained)
* Modality
* Partner
* Age
* Gender
* Site
* Time
Looking just at the observed yield rates can be misleading for site and PSNUs because some have populations more conducive to high yield rates, whereas others do not. In order to evaluate the effectiveness of different PSNUs and sites within psnu, a machine learning model is constructed that takes into count all of the factors above.
The model generates conditional odds ratios. These are the increased odds of generating a positive case adjusting for all other factors, including PSNU covariates like POP_EST and PLHIV.
### Location Effectiveness
```{r}
if(!is.null(glmm$re$psnu_t)){
tmp <- dat_analysis2 %>%
filter(time == 0) %>%
group_by(psnu_t) %>%
summarise(observed_yield = round(100*sum(hiv_pos * weight) / sum(weight),1),
positives=sum(hiv_pos * weight),
total_tests = sum(weight))
tmp2 <- data.frame(psnu_t=rownames(glmm$re$psnu_t),
conditional_odds_ratio = round(exp(glmm$re$psnu_t[,1]),2))
merge(tmp2,tmp) %>% arrange(desc(conditional_odds_ratio)) %>% DT::datatable(rownames = FALSE)
}
#na.omit(model_marginals$psnu_marginals) %>%
# mutate(marginal_yield = round(marginal_yield * 100, 1),
# observed_yield=round(observed_yield * 100,1)) %>%
# #rename(new_postives_last_quarter=positives, total_tests_last_quarter=total_tests) %>%
# DT::datatable(rownames = FALSE)
```
### Site Effectiveness
```{r}
tmp <- dat_analysis2 %>%
filter(time == 0) %>%
group_by(psnu_t,cluster_1, cluster_2, cluster_3, modality, sitename) %>%
summarise(positives=sum(hiv_pos * weight),
total_tests = sum(weight),
weight = sum(weight))
tmp$conditional_odds_ratio_sitename <- predict(
glmm$glmm_full_fit,
newdata=tmp,
random.only=TRUE,
re.form=site_re_formula
)
tmp <- tmp %>%
group_by(psnu_t,cluster_1, cluster_2, cluster_3, sitename) %>%
summarise(conditional_odds_ratio_sitename = sum(conditional_odds_ratio_sitename*weight) / sum(weight),
observed_yield = round(100*sum(positives) / sum(weight),1),
positives=sum(positives),
total_tests = sum(weight))
tmp4 <-tmp %>%
mutate(conditional_odds_ratio_sitename = round(exp(conditional_odds_ratio_sitename),2)) %>%
arrange(desc(conditional_odds_ratio_sitename))
tmp4 <- tmp4[c("psnu_t", "sitename","conditional_odds_ratio_sitename", "observed_yield", "positives", "total_tests"
)]
tmp4 %>% DT::datatable(rownames = FALSE)
```
## Model Based Target Change Recommendations
The machine learning model gives us estimated yield rates at the site level disaggregated by partner, modality, snu priority, age and sex. It also can provide estimates of what the yield rates would have been had the sites tested a different number of people. Infant testing (<01 years old) is excluded.
These yield estimates can be used to provide guidance on the number of tests these sites should target for next quarter. A greedy algorithm is used to optimize yield rates subject to thee constraint that the total number of tests remains constant, and the increase (or decrease) in the number of non-index modality tests compared to last quarter can be at most `r (max_diff - 1) * 100`%.
```{r}
```
If these changes are adopted, yield among non Index/IndexMod modalities could increase from `r round(model_allocations$initial_yield * 100, 2)` to `r round(model_allocations$final_yield * 100, 2)`, an increase of `r round(100*model_allocations$final_yield/model_allocations$initial_yield-100, 2)`%. The algorithm proposes increasing index testing from `r as.integer(sum(model_allocations$index_allocations$current_hts_tst_index, na.rm=TRUE))` tests per quarter to `r as.integer(round(sum(model_allocations$index_allocations$proposed_hts_tst_index, na.rm=TRUE)))`, leading to an estimated `r as.integer(round(sum(model_allocations$index_allocations$expected_new_hiv_cases_at_proposed, na.rm=TRUE)) - sum(model_allocations$index_allocations$current_hts_tst_pos_index, na.rm=TRUE))` additional identified positives.
## Allocations by PSNU
```{r}
df <- model_allocations$allocations %>%
mutate(psnu_t = as.character(psnu_t)) %>%
group_by(psnu_t) %>%
summarise(current_hts_tst = sum(current_hts_tst),
proposed_hts_tst = sum(proposed_hts_tst)
)
dfi <- model_allocations$index_allocations %>%
group_by(psnu_t) %>%
summarise(current_hts_tst = sum(current_hts_tst_index, na.rm=TRUE),
proposed_hts_tst = round(sum(proposed_hts_tst_index))
)
dft <- df %>%
bind_rows(dfi) %>%
group_by(psnu_t) %>%
summarise_all(sum) %>%
mutate(
difference = proposed_hts_tst - current_hts_tst,
action = ifelse(difference < 0,
"Reduce",
ifelse(difference > 0, "Increase","No Change"))
)
dft %>% arrange(desc(difference)) %>% kable()
```
## Allocations by modality
```{r}
df <- model_allocations$allocations %>%
mutate(modality = as.character(modality)) %>%
group_by(modality) %>%
summarise(current_hts_tst = sum(current_hts_tst),
proposed_hts_tst = sum(proposed_hts_tst)
)
dfi <- model_allocations$index_allocations %>%
summarise(current_hts_tst = sum(current_hts_tst_index, na.rm=TRUE),
proposed_hts_tst = round(sum(proposed_hts_tst_index))
)
dfi$modality <- "Index/IndexMod"
dft <- df %>%
bind_rows(dfi) %>%
group_by(modality) %>%
summarise_all(sum) %>%
mutate(
difference = proposed_hts_tst - current_hts_tst,
action = ifelse(difference < 0,
"Reduce",
ifelse(difference > 0, "Increase","No Change"))
)
dft %>% arrange(desc(difference)) %>% kable()
```
## Allocations by gender (non-index modalities)
```{r}
df <- model_allocations$allocations %>%
mutate(sex = as.character(sex)) %>%
group_by(sex) %>%
summarise(current_hts_tst = sum(current_hts_tst),
proposed_hts_tst = sum(proposed_hts_tst)
)
dft <- df %>%
group_by(sex) %>%
summarise_all(sum) %>%
mutate(
difference = proposed_hts_tst - current_hts_tst,
action = ifelse(difference < 0,
"Reduce",
ifelse(difference > 0, "Increase","No Change"))
)
dft %>% arrange(desc(difference)) %>% kable()
```
## Allocations by age (non-index modalities)
```{r}
df <- model_allocations$allocations %>%
mutate(ageasentered = as.character(ageasentered)) %>%
group_by(ageasentered) %>%
summarise(current_hts_tst = sum(current_hts_tst),
proposed_hts_tst = sum(proposed_hts_tst)
)
dft <- df %>%
group_by(ageasentered) %>%
summarise_all(sum) %>%
mutate(
difference = proposed_hts_tst - current_hts_tst,
action = ifelse(difference < 0,
"Reduce",
ifelse(difference > 0, "Increase","No Change"))
)
dft %>% kable()
```
# Model Diagnostics
## Train - Test Split
```{r}
tmp <- dat_analysis2
tmp$weight_test <- split$weight_test
tmp$weight_train <- split$weight_train
tmp %>% group_by(quarter,hiv_pos) %>%summarise(training_cases=sum(weight_train), testing_cases=sum(weight_test))
```
## Boosting Round 1: GLMM
A model summary of the GLMM fit to the full dataset.
```{r}
w <- options()$width
options(width = 10000)
summary(glmm$glmm_full_fit)
options(width = w)
```
Testing and training AUC values by number of quarters (prior to current) included in training data.
```{r}
tmp <- as.data.frame(glmm[c("auc_value","auc_training_value")])
tmp$time_lag <- (nrow(tmp)-1):0
tmp %>% kable()
```
## Boosting Round 2: GBM
Bayesian optimization of hyper-parameters.
```{r}
gbm$opt_res$History %>% kable()
```
```{r}
importance_matrix <- xgb.importance(colnames(gbm$dmat), model = gbm$gbm_full_fit)
(xgb.ggplot.importance(importance_matrix, top_n=40) + theme_bw()) %>% plotly::ggplotly()
```
## Boosting Round 3: Elastic Net
```{r}
(
qplot(enet$glmnet_fit_full$df, enet$auc_trace) + scale_x_log10()
) %>% plotly::ggplotly()
```
Number of cases affected by elastic net model
```{r}
enet$tab %>% kable()
```