-
Notifications
You must be signed in to change notification settings - Fork 0
/
TablesPlots.Rmd
300 lines (241 loc) · 13 KB
/
TablesPlots.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
---
title: "Tables and plots"
output: html_document
---
Code to generate tables and figures.
Code accompanies:
Mercaldo, RA, Bellan, SE. Evaluation of Alternative Endpoints for Zika Virus Vaccine Efficacy Trials. 2019.
Rachel Mercaldo, 2019
License at bottom.
```{r}
rm(list = ls())
library(Gmisc)
library(grid)
library(tidyverse)
library(data.table)
library(ggpubr)
library(kableExtra)
library(scales)
```
```{r}
temp = list.files(pattern = "*.csv") #any/all result .csv files in current directory
tbl = lapply(temp, read_csv) %>% bind_rows() #make them a tbl
```
### Data processing:
```{r}
tbl$N <- tbl$regSize*4 #4 regions at each regSize, total population 4*regsize
tbl$startDate <- NA
tbl$startDate[tbl$run == 'runMax'] <- '2016-08-03'
tbl$startDate[tbl$run == 'run00025'] <- '2016-05-05'
tbl$startDate[tbl$run == 'run0005'] <- '2016-08-21'
tbl$meanDuration <- as.numeric(as.Date(tbl$meanDate,"%m/%d/%Y") - as.Date(tbl$startDate, "%Y-%m-%d"))
names(tbl)[names(tbl) == 'vaccEff'] <- 'Assumed Vaccine Efficacy'
tbl$`Mean Trial Duration` <- as.numeric(tbl$meanDuration)
```
```{r}
#turn trialType into categories for easier ggplotting:
tbl$cat<-NA
tbl$cat[tbl$trialType == 'infTrial' & tbl$testInterval == 7 & tbl$run == 'runMax'] <- 1
tbl$cat[tbl$trialType == 'infTrial' & tbl$testInterval == 14 & tbl$run == 'runMax'] <- 2
tbl$cat[tbl$trialType == 'infTrial' & tbl$testInterval == 28 & tbl$run == 'runMax'] <- 3
tbl$cat[tbl$trialType == 'symptomTrial'& tbl$run == 'runMax' ] <- 4
tbl$cat[tbl$trialType=='CZStrial' & tbl$run == 'run00025'] <- 5
tbl$cat[tbl$trialType=='CZStrial' & tbl$run == 'run0005'] <- 6
tbl$cat[tbl$trialType=='CZStrial' & tbl$run == 'runMax']<-7
tbl<-tbl[!is.na(tbl$cat),]
tbl$cat <- factor(tbl$cat, levels = c(1:7), labels = c('Infection, Weekly Testing',
'Infection, Biweekly Testing',
'Infection, Monthly Testing',
'Symptomatic ZVD',
'CZS, Start at 0.00025 Hazard',
'CZS, Start at 0.0005 Hazard',
'CZS, Start after Peak'))
tbl$`Assumed Vaccine Efficacy` <- factor(tbl$`Assumed Vaccine Efficacy`,
levels = c(0.5,0.7,0.9),
labels = c('50%','70%','90%'))
czs<-tbl[tbl$cat %in% c("CZS, Start at 0.00025 Hazard", "CZS, Start at 0.0005 Hazard", "CZS, Start after Peak"),]
tbl80<-tbl[tbl$power >= 0.8,]
```
## Plots
### Rates
```{r, echo = FALSE, warning = FALSE}
load('paho.Rdata')
colnames(paho)[2]<- "Costa Rica" #get rid of unsightly "."
paho<-cbind(paho[,8],paho[,1:6])
pahoPlot<-melt.data.table(paho,id.vars = 1, measure.vars = 2:7,variable.name = "Country")
fig1<-ggplot(pahoPlot, aes(x=week, y=value, group = Country, color = Country)) + geom_line(size = 4)+
theme_classic() + theme(legend.key.size = unit(1.65, 'lines'))+
scale_x_continuous(breaks = c(1,seq(5,80,by=5)))
fig1<-ggpar(fig1,
palette = "lancet",
xlab ="Week", ylab = "Hazard of Infection",
font.x = c(22), font.y = c(22),
xtickslab.rt = 45,
font.tickslab = c(20)) +
font("legend.title", color = "black", face = "bold", size = 22) +
font("legend.text", color = "black", size = 20) +
annotate("text", x = 2, y = -0.00005, label = "1/3/2016", size = 7)+
annotate("text", x = 81, y = -0.00005, label = "7/23/2017", size = 7)
fig1
ggsave('rates.png', device = 'png', width = 16, height = 12)
```
### Power:
```{r, echo = FALSE, warning = FALSE}
fig2<-ggplot(tbl, aes(x=N, y=power, fill = cat, color = cat)) +
facet_wrap(~`Assumed Vaccine Efficacy`, ncol = 1, strip.position = "top", labeller = label_both)+
geom_smooth(method='loess',span = 0.1, size = 4) + geom_point()+
scale_y_continuous(limits = c(0,1.1), breaks = seq(0 , 1, .2)) +
scale_x_continuous(breaks = seq(0, 110000, 10000), labels = comma) +
theme_classic() + theme(axis.text.x = element_text(vjust = .95, hjust = 1),strip.text = element_text(size = 22)) +
geom_hline(yintercept = .80,linetype = 'dashed') +
theme(legend.key.size = unit(1.65, 'lines'))
fig2<-ggpar(fig2,
palette = "lancet",
xlab ="Number of Participants", ylab = "Statistical Power",
font.x = c(22), font.y = c(22),
xtickslab.rt = 45,
font.tickslab = c(20),
legend.title = 'Trial Scenario',
font.legend = c(20, 'plain'))+
font("legend.title", color = "black", face = "bold", size = 22) +
font("legend.text", color = "black", face = 'plain', size = 20)
fig2
ggsave('powerByN.png', device = 'png', width = 16, height = 12)
```
### Pre-immunity and First trimester infections:
```{r, echo = FALSE, warning = FALSE}
czs<-czs[!is.na(czs$ColFirst),]
czs<-czs[czs$`Assumed Vaccine Efficacy` == "70%",] #focus on intermediate efficacy for simpler plot
dat<-gather(czs, 'FirstCountry', 'FirstValue', c(30,37,44,51,58,65))
dat<-gather(dat, 'PreImmune', 'PreValue', c(33, 39, 45, 51, 57, 63))
dat$FirstCountry <- factor(dat$FirstCountry, levels = c('ColFirst',
'CosFirst',
'EcuFirst',
'MexFirst',
'PanFirst',
'PerFirst'),
labels = c('Colombia',
'Costa Rica',
'Ecuador',
'Mexico',
'Panama',
'Peru'))
dat$PreImmune <- factor(dat$PreImmune, levels = c('ColPreI',
'CosPreI',
'EcuPreI',
'MexPreI',
'PanPreI',
'PerPreI'),
labels = c('Colombia',
'Costa Rica',
'Ecuador',
'Mexico',
'Panama',
'Peru'))
fig3a<-ggplot(dat, aes(x=N, y=PreValue, group = PreImmune, color = PreImmune)) +
geom_line(size = 4) + facet_grid(.~cat) +
scale_y_continuous(limits = c(0,150), breaks = seq(0,150, 25)) +
scale_x_continuous(breaks = seq(0, 110000, 20000), labels = comma)+
labs(y='Infections before Vaccine Protective Date', color = 'Country') +
theme_classic() + theme(strip.text = element_text(size = 22)) +
theme(legend.key.size = unit(1.65, 'lines'))
fig3a<-ggpar(fig3a,
palette = "lancet",
font.y = c(22),
font.tickslab = c(20),
legend.title = "Country") +
rremove('x.axis') + rremove('x.text') +
rremove('x.ticks') +
rremove('xlab') +
font("legend.title", color = 'black', face = 'bold', size = 22) +
font("legend.text", color = 'black', size = 20)
fig3b<-ggplot(dat, aes(x=N, y=FirstValue, group = FirstCountry, color = FirstCountry)) +
geom_line(size = 4) + facet_grid(.~cat) +
scale_y_continuous(limits = c(0,52), breaks = seq(0,52, 5)) +
scale_x_continuous(breaks = seq(0, 110000, 20000), labels = comma)+
labs(x = 'Number of Participants', y='Infections in First Trimester', color = 'Country') +
theme_classic() + theme(axis.text.x = element_text(vjust = .95, hjust = 1), strip.text = element_text(size = 22)) + theme(legend.key.size = unit(1.65, 'lines'))
fig3b<-ggpar(fig3b,
palette = "lancet",
font.x = c(22), font.y = c(22),
font.tickslab = c(20),
xtickslab.rt = 45,
legend.title = "Country") +
font("legend.title", color = 'black', face = 'bold', size = 22) +
font("legend.text", color = 'black', size = 20)
fig3<-ggarrange(fig3a, fig3b, nrow=2, align = 'v',common.legend = TRUE, legend="right")
fig3
ggsave('preImmuneEffect.png', device = 'png', width = 16, height = 12)
```
##Tables
###Table 1:
```{r, echo = FALSE, warning = FALSE}
parms<-data.table("Parameter" = c('Incubation period in days, Median (25%, 75%)',
'Viremia duration in days, Mean (25%, 75%)',
'CZS risk, 1st trimester',
'CZS risk, 2nd/3rd trimester',
'CZS risk, multiple trimesters, including 1st',
'Contraceptive use, proportion of Latin American women aged 15-49 yrs',
'Recruited population size, assumed vaccine efficacy, conception probability, start date within scaled hazard data'),
"Value" = c('5.9 (4.6, 7.6)', '9.9 (5.8, 12.7)', '0.15', '0.0227', '0.21', '73%', 'Varied'),
"Reference" = c(rep('Lessler, 2016', 2), rep('Reynolds, 2017',3), 'United Nations, 2015', ' '))
kable(parms, align = 'l', escape = F) %>%
kable_styling(full_width = F, font_size = 16) %>%
row_spec(1:7,color = 'black') %>%
column_spec(2:3,width = "12em")
```
### Table 2:
```{r, echo=FALSE, warning = FALSE}
loessData<-ggplot_build(fig2)$data
lines<-loessData[[1]] #first plot is geom_smooth ('2' is geom_point and '3' is hline)
lines$PANEL <- factor(lines$PANEL, levels = c(1:3), labels = c('50%', '70%', '90%'))
lines$group <- factor(lines$group, levels = c(1:7), labels = c('Infection, Weekly Testing',
'Infection, Biweekly Testing',
'Infection, Monthly Testing',
'Symptomatic ZVD',
'CZS, Start at 0.00025 Hazard',
'CZS, Start at 0.0005 Hazard',
'CZS, Start after Peak'))
scenarios<-unique(lines$group)
effs<-unique(lines$PANEL)
dat<-expand.grid('Assumed Efficacy' = effs, 'Trial Scenario' = scenarios)
dat$N<-'__'
dat$`Duration (days)`<-'__'
for(i in 1:nrow(dat)){
temp <- lines$x[lines$PANEL == dat$`Assumed Efficacy`[i] & lines$group == dat$`Trial Scenario`[i] & lines$y >= 0.8]
temp <- temp[!is.na(temp)]
dat$N[i] <- ifelse(length(temp) == 0, '__', round(temp[1]))
}
for(i in 1:nrow(dat)){
if(dat$N[i] != '__'){
temp<-tbl[tbl$cat == dat$`Trial Scenario`[i] & tbl$`Assumed Vaccine Efficacy` == dat$`Assumed Efficacy`[i] & tbl$power >= 0.8,]
temp<-temp[temp$N >= as.numeric(dat$N[i]),]
dat$`Duration (days)`[i] <- ifelse(nrow(temp) == 0, '__', temp$`Mean Trial Duration`[1])
}
}
scenarios <- unite(dat, combo, N, `Duration (days)`, sep = ", ") %>% spread(`Assumed Efficacy`, combo)
scenarios <- separate(scenarios, `50%`, c('N', 'Duration (days)'), sep = ", ")
s<-scenarios[,c(1:3)]
scenarios <- unite(dat, combo, N, `Duration (days)`, sep = ", ") %>% spread(`Assumed Efficacy`, combo)
scenarios <- separate(scenarios, `70%`, c('N ', 'Duration (days)'), sep = ", ")
s<-cbind(s,scenarios[,c(3,4)])
scenarios <- unite(dat, combo, N, `Duration (days)`, sep = ", ") %>% spread(`Assumed Efficacy`, combo)
scenarios <- separate(scenarios, `90%`, c('N ', 'Duration (days)'), sep = ", ")
s<-cbind(s,scenarios[,c(4,5)])
scenarios <- as.data.frame(s)
scenarios$`Trial Scenario`<-c("Weekly Testing", "Biweekly Testing", "Monthly Testing", "Symptomatic ZVD", "Start at 0.00025 Hazard", "Start at 0.0005 Hazard", "Start after Peak")
colnames(scenarios)[1]<-'Trial Scenario Endpoint'
```
```{r, echo=FALSE, warning=FALSE}
kable(scenarios, align = c('l',rep('c',6)), escape = F) %>%
kable_styling(full_width = F, font_size = 16) %>%
add_header_above(c(" " = 1, "Assumed Efficacy: 50%" = 2, "Assumed Efficacy: 70%" = 2, "Assumed Efficacy: 90%" = 2)) %>%
group_rows("Infection-based", 1,3, label_row_css = "background-color: #C0C0C0;color: #110;") %>%
group_rows("Symptom-based",4,4, label_row_css = "background-color: #C0C0C0;color: #110;") %>%
group_rows("CZS-based", 5,7, label_row_css = "background-color: #C0C0C0;color: #110;") %>%
row_spec(1:7,color = 'black') #%>%
#save_kable(file = "table2.html", self_contained = T)
```
##LICENSE
This code is made available under a Creative Commons Attribution 4.0 International License. You are free to reuse this code provided that you give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. Giving appropriate credit includes citation of the above publication *and* providing a link to this repository:
https://github.com/RachelMercaldo/ZikaTrial