/
103_Country_Half_Year_Reccs.Rmd
394 lines (321 loc) · 11.4 KB
/
103_Country_Half_Year_Reccs.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
---
title: "Quantifiers for Continuous Distribution by country for indicative ITN retention times"
author: "Hannah Koenker"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
pdf_document:
# html_document:
toc: yes
toc_depth: 2
# toc_float: yes
fig_width: 7
fig_height: 6
fig_caption: yes
df_print: kable
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE)
library(haven)
library(tidyverse)
library(broom)
library(readxl)
library(janitor)
library(flextable)
library(officer) # for setting color of vlines in flextable
library(readxl)
library(writexl)
# ![](images/TH_logo.jpg){width=1.0"}
######################
# Set figure theme and colors
######################
theme_set(theme_classic())
```
```{r readmins}
## Read in the full output appended dataset for checking things
# all <- read_dta("data/gruns_all.dta") %>%
# clean_names()
## Read in the recommended quantifiers
s2ming <- read_dta("data/s2_min_npp_gruns_all.dta") %>%
clean_names()
s3ming <- read_dta("data/s3_min_npp_gruns_all.dta") %>%
clean_names()
t80s2 <- s2ming %>%
filter(target==80)
t80s3 <- s3ming %>%
filter(target==80)
t90s2 <- s2ming %>%
filter(target==90)
t90s3 <- s3ming %>%
filter(target==90)
```
```{r graph-check, include=FALSE}
t80s2 %>%
mutate(retention=as.factor(retention)) %>%
ggplot() +
geom_jitter(aes(x=retention, y=q, color=retention), alpha=.5, height=0)
t80s3 %>%
mutate(retention=as.factor(retention)) %>%
ggplot() +
geom_jitter(aes(x=retention, y=q, color=retention), alpha=.5, height=0)
t90s2 %>%
mutate(retention=as.factor(retention)) %>%
ggplot() +
geom_jitter(aes(x=retention, y=q, color=retention), alpha=.5, height=0)
t90s3 %>%
mutate(retention=as.factor(retention)) %>%
ggplot() +
geom_jitter(aes(x=retention, y=q, color=retention), alpha=.5, height=0)
# Check for BF:
# all %>%
# filter(iso_a2=="BF" & retention==2.5 & group==3) %>%
# ggplot() +
# geom_line(aes(x=year, y=accrk)) +
# facet_wrap(~scenario)
```
```{r medians}
## Medians
t80s2med <- t80s2 %>%
group_by(retention) %>%
summarize(median=median(q)) %>%
mutate(retention=as.factor(retention))
t90s2med <- t90s2 %>%
group_by(retention) %>%
summarize(median=median(q)) %>%
mutate(retention=as.factor(retention))
t80s3med <- t80s3 %>%
group_by(retention) %>%
summarize(median=median(q)) %>%
mutate(retention=as.factor(retention))
t90s3med <- t90s3 %>%
group_by(retention) %>%
summarize(median=median(q)) %>%
mutate(retention=as.factor(retention))
```
```{r table-prep}
s280wide <- t80s2 %>%
select(-target) %>%
pivot_wider(id_cols=iso_a2, names_from=retention, values_from=q)
s380wide <- t80s3 %>%
select(-target) %>%
pivot_wider(id_cols=iso_a2, names_from=retention, values_from=q) %>%
mutate(`3.5`=case_when(`3`==0 & `3.5`==1 ~ 0,
TRUE ~ as.numeric(`3.5`))) # replace odd 1%s at 3.5y with zero, when 3y is zero.
s290wide <- t90s2 %>%
select(-target) %>%
pivot_wider(id_cols=iso_a2, names_from=retention, values_from=q)
s390wide <- t90s3 %>%
select(-target) %>%
pivot_wider(id_cols=iso_a2, names_from=retention, values_from=q)
## Export all Tables for use in other projects
# Ghana
gh <- bind_rows(s280wide, s290wide, s380wide, s390wide,.id = "id") %>%
filter(iso_a2=="GH") %>%
mutate(id=case_when(id==1 ~ "Full CD: 80% target",
id==2 ~ "Full CD: 90% target",
id==3 ~ "CD between campaigns: 80% target",
id==4 ~ "CD between campaigns: 90% target"))
write_xlsx (gh, path = "../Ghana_SBD/data/ghana_halfyear_quants.xlsx")
# DRC
drc <- bind_rows(s280wide, s290wide, s380wide, s390wide,.id = "id") %>%
filter(iso_a2=="CD") %>%
mutate(id=case_when(id==1 ~ "Full CD: 80% target",
id==2 ~ "Full CD: 90% target",
id==3 ~ "CD between campaigns: 80% target",
id==4 ~ "CD between campaigns: 90% target"))
write_xlsx (drc, path = "output/drc_halfyear_quants.xlsx")
```
\newpage
# Indicative quantifiers for CD as a replacement for mass campaigns
## 80% ITN access target
```{r betweenCD80-violin, fig.cap="Median recommended quantifer for continuous distribution between ITN campaigns, by ITN retention time (80% target for ITN access)", height=4, width=5}
t80s2 %>%
mutate(retention=as.factor(retention)) %>%
ggplot() +
geom_violin(aes(x=retention, y=q, color=retention), alpha=.5, width=1) + # , draw_quantiles = c(0.5)
geom_jitter(aes(x=retention, y=q, color=retention), alpha=.10, width=.15) +
geom_text(data=t80s2med, aes(x=retention, y=median, color=retention, label=median), fontface="bold") +
labs(x="ITN retention time in years",
y="Recommended quantifier (% of population)",
color="",
title="Median recommended quantifier for annual large-scale CD, by ITN retention time") +
theme(legend.position="none")
```
\newpage
```{r table-s280}
set_flextable_defaults(
border.color = "#AAAAAA", font.family = "Arial", fonts_ignore=TRUE,
font.size = 10, padding = 2, line_spacing = 1.5)
# std_border = fp_border(color="white") ## set the color of the border needed later down
tables280 <- s280wide %>%
flextable() %>%
set_header_labels(
iso_a2 = "Country (ISO2 code)"
) %>%
add_header_row(colwidths = c(1,6),
values = c("Country (ISO2 code)", "ITN retention time (years)")) %>%
add_header_row(
colwidths = c(7),
values=c("Minimum quantifier (population x quantifier, annually) to sustain ITN access at or above 80%")
) %>%
fontsize(size = 9, part = "body") %>%
fontsize(size=10, part="header") %>%
colformat_double(
j=2:7,
big.mark = ",",
digits = 0,
na_str = "",
suffix="%"
) %>%
theme_vanilla %>%
align(align = "center", part = "all") %>%
# vline(j=5, border=std_border, part="all") %>%
# vline(j=1, border=std_border, part="all") %>%
set_table_properties(width=.5) %>%
# autofit(part = "all") %>%
align(align = "center", part = "all")%>%
merge_h(part = "header") %>%
merge_v(part = "header")
invisible(save_as_image(tables280, path="figs/Table_S280_halfyears_long.png"))
```
\newpage
## 90% ITN access target
```{r betweenCD90-violin, fig.cap="Median recommended quantifer for annual large-scale continuous distribution, by ITN retention time (90% target for ITN access)", height=4, width=5}
t90s2 %>%
mutate(retention=as.factor(retention)) %>%
ggplot() +
geom_violin(aes(x=retention, y=q, color=retention), alpha=.5, width=1) + # , draw_quantiles = c(0.5)
geom_text(data=t90s2med, aes(x=retention, y=median, color=retention, label=median)) +
labs(x="ITN retention time in years",
y="Recommended quantifier (% of population)",
color="",
title="Median recommended quantifier for annual large-scale CD, by ITN retention time") +
theme(legend.position="none")
```
\newpage
```{r table-s290}
s290wide %>%
flextable() %>%
set_header_labels(
iso_a2 = "Country (ISO2 code)"
) %>%
add_header_row(colwidths = c(1,6),
values = c("Country (ISO2 code)", "ITN retention time (years)")) %>%
add_header_row(
colwidths = c(7),
values=c("Minimum quantifier (population x quantifier, annually) to sustain ITN access at or above 90%")
) %>%
fontsize(size = 9, part = "body") %>%
fontsize(size=10, part="header") %>%
colformat_double(
j=2:7,
big.mark = ",",
digits = 0,
na_str = "",
suffix="%"
) %>%
theme_vanilla %>%
align(align = "center", part = "all") %>%
# vline(j=5, border=std_border, part="all") %>%
# vline(j=1, border=std_border, part="all") %>%
set_table_properties(width=.5) %>%
# autofit(part = "all") %>%
align(align = "center", part = "all")%>%
merge_h(part = "header") %>%
merge_v(part = "header")
```
\newpage
# Indicative quantifiers for CD between mass campaigns
## 80% ITN access target
```{r betweencampaign-violin, fig.cap="Median recommended quantifer for continuous distribution between ITN campaigns, by ITN retention time (80% target for ITN access)", height=4, width=5}
t80s3 %>%
mutate(retention=as.factor(retention)) %>%
ggplot() +
geom_violin(aes(x=retention, y=q, color=retention), alpha=.5, width=1) + # , draw_quantiles = c(0.5)
geom_jitter(aes(x=retention, y=q, color=retention), alpha=.10, width=.15) +
geom_text(data=t80s3med, aes(x=retention, y=median, color=retention, label=median), fontface="bold") +
labs(x="ITN retention time in years",
y="Recommended quantifier (% of population)",
color="",
title="Median recommended quantifier for between-campaign CD, by ITN retention time") +
theme(legend.position="none")
```
\newpage
```{r table-s380}
tables380 <- s380wide %>%
flextable() %>%
set_header_labels(
iso_a2 = "Country (ISO2 code)"
) %>%
add_header_row(colwidths = c(1,6),
values = c("Country (ISO2 code)", "ITN retention time (years)")) %>%
add_header_row(
colwidths = c(7),
values=c("Minimum quantifier (population x quantifier, each year between campaigns) to sustain ITN access at or above 80%")
) %>%
fontsize(size = 9, part = "body") %>%
fontsize(size=10, part="header") %>%
colformat_double(
j=2:7,
big.mark = ",",
digits = 0,
na_str = "",
suffix="%"
) %>%
theme_vanilla %>%
align(align = "center", part = "all") %>%
# vline(j=5, border=std_border, part="all") %>%
# vline(j=1, border=std_border, part="all") %>%
set_table_properties(width=.5) %>%
# autofit(part = "all") %>%
align(align = "center", part = "all")%>%
merge_h(part = "header") %>%
merge_v(part = "header")
invisible(save_as_image(tables380, path="figs/Table_S380_halfyears_long.png"))
```
## 90% ITN access target
```{r betweencampaign90-violin, warning=FALSE, fig.cap="Median recommended quantifer for continuous distribution between ITN campaigns, by ITN retention time (90% target for ITN access)", height=4, width=5}
t90s3 %>%
mutate(retention=as.factor(retention)) %>%
ggplot() +
geom_violin(aes(x=retention, y=q, color=retention), alpha=.5, width=1) + # , draw_quantiles = c(0.5)
geom_text(data=t90s3med, aes(x=retention, y=median, color=retention, label=median)) +
labs(x="ITN retention time in years",
y="Recommended quantifier (% of population)",
color="",
title="Median recommended quantifier for annual large-scale CD, by ITN retention time") +
theme(legend.position="none")
```
\newpage
```{r table-s390}
s390wide %>%
flextable() %>%
set_header_labels(
iso_a2 = "Country (ISO2 code)"
) %>%
add_header_row(colwidths = c(1,6),
values = c("Country (ISO2 code)", "ITN retention time (years)")) %>%
add_header_row(
colwidths = c(7),
values=c("Minimum quantifier (population x quantifier, each year between campaigns) to sustain ITN access at or above 90%")
) %>%
fontsize(size = 9, part = "body") %>%
fontsize(size=10, part="header") %>%
colformat_double(
j=2:7,
big.mark = ",",
digits = 0,
na_str = "",
suffix="%"
) %>%
theme_vanilla %>%
align(align = "center", part = "all") %>%
# vline(j=5, border=std_border, part="all") %>%
# vline(j=1, border=std_border, part="all") %>%
set_table_properties(width=.5) %>%
# autofit(part = "all") %>%
align(align = "center", part = "all")%>%
merge_h(part = "header") %>%
merge_v(part = "header")
```