forked from cmmid/ringbp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path-C02R10QDGG7N-2.Rhistory
executable file
·512 lines (512 loc) · 15.5 KB
/
-C02R10QDGG7N-2.Rhistory
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
net_fig
net_fig <- plot_grid(net_figa,
plot_grid(NULL,net_exa,net_exb,net_exc,net_exd,nrow = 1,
rel_widths = c(0.25,1,1,1,1)),
nrow = 2,
rel_heights = c(1,0.3),
labels = "AUTO")
net_fig
?map
devtools::load_all(".")
sce_figa <- sce %>%
mutate(intervention = recode(intervention,
nothing = "No control",
isolation = "Case isolation",
primary_quarantine = "Primary tracing",
secondary_quarantine = "Secondary tracing")) %>%
mutate(intervention = factor(intervention,
levels = c("No control",
"Case isolation",
"Primary tracing",
"Secondary tracing"))) %>%
unnest(cols = "results") %>%
case_plot(nrow = 1)+
theme(legend.position = "top")
sce_figa
?replicate
sce <- read_rds("data-raw/scenarios.rds")
sce_figa <- sce %>%
mutate(intervention = recode(intervention,
nothing = "No control",
isolation = "Case isolation",
primary_quarantine = "Primary tracing",
secondary_quarantine = "Secondary tracing")) %>%
mutate(intervention = factor(intervention,
levels = c("No control",
"Case isolation",
"Primary tracing",
"Secondary tracing"))) %>%
unnest(cols = "results") %>%
case_plot(nrow = 1)+
theme(legend.position = "top")
plot_network2 <- purrr::partial(plot_network,
am = am_list[[1]],
day = 20,
num.initial.cases = 1,
prop.asym = 0.4,
delay_shape = 1,
delay_scale = 1.4,
prop.ascertain = 0.9,
presymrate = 0.2,
R = 0.8,
outside = 0.001,
testing = FALSE,
s = 333)
sce_figb <- function(){
par(mar = c(1,0,0,0))
plot_network2(isolation = FALSE,
quarantine = FALSE,
tracing = FALSE,
secondary = FALSE)
}
sce_figc <- function(){
par(mar = c(1,0,0,0))
plot_network2(isolation = TRUE,
quarantine = FALSE,
tracing = FALSE,
secondary = FALSE)
}
sce_figd <- function(){
par(mar = c(1,0,0,0))
plot_network2(isolation = TRUE,
quarantine = TRUE,
tracing = TRUE,
secondary = FALSE)
}
sce_fige <- function(){
par(mar = c(1,0,0,0))
plot_network2(isolation = TRUE,
quarantine = TRUE,
tracing = TRUE,
secondary = TRUE)
}
sce_fig <- plot_grid(sce_figa,
plot_grid(NULL,sce_figb,sce_figc,sce_figd,sce_fige,nrow = 1,
rel_widths = c(0.25,1,1,1,1)),
nrow = 2,
rel_heights = c(1,0.7),
labels = "AUTO")
pdf("inst/plots/Figure_2.pdf",
width = 12,
height = 8)
sce_fig
dev.off()
nrow(sce$results[[1]])
```r
library(covidhm)
#Load association matrices
load("data-raw/am_list.RData")
#First item in the list is data across all days
m <- am_list[[1]]
#Plot network
plot_network(
am = m,
day = 20,
num.initial.cases = 1,
prop.asym = 0.4,
delay_shape = 1,
delay_scale = 1.4,
prop.ascertain = 0.9,
presymrate = 0.2,
R = 0.8,
outside = 0.001,
sensitivity = "high",
testing = "none",
s = 333,
isolation = FALSE,
secondary = FALSE,
tracing = FALSE,
quarantine = FALSE)
#Plot network
plot_network(
am = m,
day = 20,
num.initial.cases = 1,
prop.asym = 0.4,
delay_shape = 1,
delay_scale = 1.4,
prop.ascertain = 0.9,
presymrate = 0.2,
R = 0.8,
outside = 0.001,
testing = FALSE,
s = 333,
isolation = FALSE,
secondary = FALSE,
tracing = FALSE,
quarantine = FALSE)
res <- scenario_sim(net = haslemere, n.sim = 10, num.initial.cases = 1,prop.asym=0.4,
prop.ascertain = 0.9, cap_max_days = 70,
delay_shape = 1, delay_scale = 1.4, R = 0.8, presymrate = 0.2, scenario = "nothing",
sensitivity = "high", testing = FALSE, outside = 0.001, distancing = 0)
res <- scenario_sim(net = haslemere, n.sim = 10, num.initial.cases = 1,prop.asym=0.4,
prop.ascertain = 0.9, cap_max_days = 70,
delay_shape = 1, delay_scale = 1.4, R = 0.8, presymrate = 0.2, scenario = "nothing",
testing = FALSE, outside = 0.001, distancing = 0)
res <- scenario_sim(net = am_list[[1]], n.sim = 10, num.initial.cases = 1,prop.asym=0.4,
prop.ascertain = 0.9, cap_max_days = 70,
delay_shape = 1, delay_scale = 1.4, R = 0.8, presymrate = 0.2, scenario = "nothing",
testing = FALSE, outside = 0.001, distancing = 0)
# Plot of raw cumulative cases
ggplot(data=res, aes(x=week, y=cumcases,col = sim)) +
geom_line(show.legend = FALSE, alpha=0.6, aes(group = sim)) +
scale_y_continuous(name="Weekly number of cases") +
theme_bw()
dis %>% filter(week == 3) %>%
group_by(intervention,distancing) %>%
summarise(medcases = median(weekly_quarantine)/468,
Ucases = quantile(weekly_quarantine,0.75)/468,
Lcases = quantile(weekly_quarantine, 0.25)/468)
dis
dis %>% filter(week == 3) %>%
unnest(cols = "results") %>%
group_by(intervention,distancing) %>%
summarise(medcases = median(weekly_quarantine)/468,
Ucases = quantile(weekly_quarantine,0.75)/468,
Lcases = quantile(weekly_quarantine, 0.25)/468)
dis %>% filter(week == 3) %>%
unnest(cols = "results")
dis %>%
unnest(cols = "results") %>%
filter(week == 3)
dis %>%
unnest(cols = "results") %>%
filter(week == 3) %>%
group_by(intervention,dist) %>%
summarise(medcases = median(weekly_quarantine)/468,
Ucases = quantile(weekly_quarantine,0.75)/468,
Lcases = quantile(weekly_quarantine, 0.25)/468)
dis %>%
unnest(cols = "results") %>%
filter(week == 3) %>%
group_by(intervention,dist) %>%
summarise(medcases = median(weekly_quarantine))
dis %>%
unnest(cols = "results") %>%
filter(week == 3) %>%
group_by(intervention,dist) %>%
summarise(medcases = median(weekly_quarantine)/468,
Ucases = quantile(weekly_quarantine,0.75)/468,
Lcases = quantile(weekly_quarantine, 0.25)/468)
dis_fig <- dis %>%
mutate(dist = paste0(dist*100,"% reduction"),
intervention = recode(intervention,
nothing = "No control",
isolation = "Case isolation",
primary_quarantine = "Primary tracing",
secondary_quarantine = "Secondary tracing")) %>%
unnest(cols = "results") %>%
case_plot(facet = "grid", gridvar = "dist")+
theme(legend.position = "none")
dis_fig
#distancing
dis %>%
unnest(cols = "results") %>%
filter(week == 3) %>%
group_by(intervention,dist) %>%
summarise(medcases = median(cumcases)/468,
Ucases = quantile(cumcases,0.75)/468,
Lcases = quantile(cumcases, 0.25)/468)
#distancing
dis %>%
unnest(cols = "results") %>%
filter(week == 9) %>%
group_by(intervention,dist) %>%
summarise(medcases = median(cumcases)/468,
Ucases = quantile(cumcases,0.75)/468,
Lcases = quantile(cumcases, 0.25)/468)
-.68-0.31
0.68-0.31
0.37/0.68
tes %>% filter(week == 3) %>%
group_by(intervention,testing) %>%
summarise(medcases = median(weekly_tests)/468,
Ucases = quantile(weekly_tests,0.75)/468,
Lcases = quantile(weekly_tests, 0.25)/468)
tes %>%
unnest(cols = "results") %>%
filter(week == 9)
#testing
tes %>%
unnest(cols = "results") %>%
filter(week == 9) %>%
group_by(intervention,tests) %>%
summarise(medcases = median(cumcases)/468,
Ucases = quantile(cumcases,0.75)/468,
Lcases = quantile(cumcases, 0.25)/468)
468/20
tes %>% unnest(cols = "results") %>%
filter(week == 3) %>%
group_by(intervention,testing) %>%
summarise(medcases = median(weekly_tests)/468,
Ucases = quantile(weekly_tests,0.75)/468,
Lcases = quantile(weekly_tests, 0.25)/468)
tes %>% unnest(cols = "results") %>%
filter(week == 3) %>%
group_by(intervention,tests) %>%
summarise(medcases = median(weekly_tests)/468,
Ucases = quantile(weekly_tests,0.75)/468,
Lcases = quantile(weekly_tests, 0.25)/468)
468*0.07
devtools::load_all(".")
###########################################
#SIMULATE CONTACT TRACING SCENARIOS
###########################################
rm(list=ls())
library(covidhm)
library(dplyr)
library(purrr)
source("inst/scripts/default_params.R")
future::plan("multiprocess")
# Simulate scenarios ------------------------------------------------------
scenarios <- tibble(intervention = c("nothing","isolation", "primary_quarantine","secondary_quarantine"))
res <- scenarios %>%
mutate(results = map(intervention, ~ scenario_sim2(scenario = .,
outside = 0.001,
distancing = 0,
testing = FALSE)))
saveRDS(res, file = "data-raw/scenarios.rds")
res <- scenarios %>%
mutate(results = map(intervention, ~ scenario_sim2(scenario = .,
outside = 0.001,
distancing = 0,
testing = FALSE)))
res <- scenarios %>%
mutate(results = map(intervention, ~ scenario_sim2(scenario = .,
outside = 0.001,
distancing = 0,
testing = FALSE,
test_neg = 0)))
tes <- read_rds("data-raw/testing.rds")
tes_fig <- tes %>%
mutate(tests = paste(tests,"tests per day")) %>%
bind_rows(sce %>%
filter(intervention %in% c("primary_quarantine",
"secondary_quarantine")) %>%
mutate(tests = "No testing")) %>%
mutate(tests = factor(tests, levels = c("No testing",
"5 tests per day",
"25 tests per day",
"50 tests per day")),
intervention = recode(intervention,
primary_quarantine = "Primary tracing",
secondary_quarantine = "Secondary tracing")) %>%
unnest(cols = "results") %>%
case_plot(facet = "grid",gridvar = "tests",testing = TRUE)+
theme(legend.position = "top")
tes_fig
sce <- read_rds("data-raw/scenarios.rds")
tes <- read_rds("data-raw/testing.rds")
tes_fig <- tes %>%
mutate(tests = paste(tests,"tests per day")) %>%
bind_rows(sce %>%
filter(intervention %in% c("primary_quarantine",
"secondary_quarantine")) %>%
mutate(tests = "No testing")) %>%
mutate(tests = factor(tests, levels = c("No testing",
"5 tests per day",
"25 tests per day",
"50 tests per day")),
intervention = recode(intervention,
primary_quarantine = "Primary tracing",
secondary_quarantine = "Secondary tracing")) %>%
unnest(cols = "results") %>%
case_plot(facet = "grid",gridvar = "tests",testing = TRUE)+
theme(legend.position = "top")
tes_fig
sce <- read_rds("data-raw/scenarios.rds")
tes <- read_rds("data-raw/testing.rds")
#Scenarios
sce %>% filter(week == 9) %>%
group_by(intervention) %>%
summarise(medcases = median(cumcases)/468,
Ucases = quantile(cumcases,0.95)/468,
Lcases = quantile(cumcases, 0.05)/468)
#Scenarios
sce %>%
unnest(cols = "results") %>%
filter(week == 9) %>%
group_by(intervention) %>%
summarise(medcases = median(cumcases)/468,
Ucases = quantile(cumcases,0.95)/468,
Lcases = quantile(cumcases, 0.05)/468)
sce %>%
unnest(cols = "results") %>%
filter(week == 3) %>%
group_by(intervention) %>%
summarise(medcases = median(weekly_quarantine)/468,
Ucases = quantile(weekly_quarantine, 0.95)/468,
Lcases = quantile(weekly_quarantine, 0.05)/468)
sce %>%
unnest(cols = "results") %>%
filter(week == 9) %>%
group_by(intervention) %>%
summarise(medcases = median(weekly_quarantine)/468,
Ucases = quantile(weekly_quarantine, 0.95)/468,
Lcases = quantile(weekly_quarantine, 0.05)/468)
#testing
tes %>%
unnest(cols = "results") %>%
filter(week == 9) %>%
group_by(intervention,tests) %>%
summarise(medcases = median(cumcases)/468,
Ucases = quantile(cumcases,0.95)/468,
Lcases = quantile(cumcases, 0.05)/468)
tes %>% unnest(cols = "results") %>%
filter(week == 3) %>%
group_by(intervention,tests) %>%
summarise(medcases = median(weekly_tests)/468,
Ucases = quantile(weekly_tests,0.95)/468,
Lcases = quantile(weekly_tests, 0.05)/468)
scenarios
scenarios <- tidyr::expand_grid(
## Put parameters that are grouped by disease into this data.frame
delay_group = list(tibble::tibble(
delay = c("Medium", "Short"),
delay_shape = c(1.651524, 1),
delay_scale = c(4.287786, 1.4)
)),
presymrate = c(0.2,0.4),
prop.asym = c(0.2, 0.4),
control_effectiveness = c(0.3, 0.6, 0.9),
num.initial.cases = c(1, 5),
scenario = c("primary_quarantine", "secondary_quarantine"),
R = c(0.5,0.8,2)) %>%
tidyr::unnest("delay_group") %>%
dplyr::mutate(scenarioID = 1:dplyr::n())
scenarios
1.5/5
0.3*288
sce <- read_rds("data-raw/scenarios.rds")
net <- read_rds("data-raw/network.rds")
sen <- read_rds("data-raw/sensitivity.rds")
dis <- read_rds("data-raw/distancing.rds")
dis2 <- read_rds("data-raw/distancing2.rds")
out <- read_rds("data-raw/outside.rds")
tes <- read_rds("data-raw/testing.rds")
sce7 <- read_rds("data-raw/scenarios7.rds")
sce16 <- read_rds("data-raw/scenarios16.rds")
load("data-raw/am_list.RData")
tes_fig <- tes %>%
mutate(tests = paste(tests,"tests per day")) %>%
bind_rows(sce %>%
filter(intervention %in% c("primary_quarantine",
"secondary_quarantine")) %>%
mutate(tests = "No testing")) %>%
mutate(tests = factor(tests, levels = c("No testing",
"5 tests per day",
"25 tests per day",
"50 tests per day")),
intervention = recode(intervention,
primary_quarantine = "Primary tracing",
secondary_quarantine = "Secondary tracing")) %>%
unnest(cols = "results") %>%
case_plot(facet = "grid",gridvar = "tests",testing = TRUE)+
theme(legend.position = "top")
dis_fig <- dis %>%
mutate(dist = paste0(dist*100,"% reduction"),
intervention = recode(intervention,
nothing = "No control",
isolation = "Case isolation",
primary_quarantine = "Primary tracing",
secondary_quarantine = "Secondary tracing")) %>%
unnest(cols = "results") %>%
case_plot(facet = "grid", gridvar = "dist")+
theme(legend.position = "none")
fig3 <- plot_grid(tes_fig,dis_fig,nrow = 2,labels = "AUTO",rel_heights = c(0.45,0.55))
pdf("inst/plots/Figure_3.pdf",
width = 12,
height = 16)
fig3
dev.off()
#distancing
dis %>%
unnest(cols = "results") %>%
filter(week == 9) %>%
group_by(intervention,dist) %>%
summarise(medcases = median(cumcases)/468,
Ucases = quantile(cumcases,0.95)/468,
Lcases = quantile(cumcases, 0.05)/468)
0.746-0.293
0.453/0.746
0.162-0.113
0.046/0.162
dis %>%
unnest(cols = "results") %>%
filter(week == 3) %>%
group_by(intervention,dist) %>%
summarise(medcases = median(weekly_quarantine)/468,
Ucases = quantile(weekly_quarantine,0.95)/468,
Lcases = quantile(weekly_quarantine, 0.05)/468)
dis2 <- read_rds("data-raw/distancing2.rds")
dis2_fig <- dis2 %>%
case_plot(facet = "grid", gridvar = "distancing")
dis2
dis2_fig <- dis2 %>%
mutate(dist = paste0(dist*100,"% reduction"),
intervention = recode(intervention,
nothing = "No control",
isolation = "Case isolation",
primary_quarantine = "Primary tracing",
secondary_quarantine = "Secondary tracing")) %>%
unnest(cols = "results") %>%
case_plot(facet = "grid", gridvar = "dist")+
theme(legend.position = "none")
pdf("inst/plots/EDF_8.pdf",
width =12,
height = 8)
dis2_fig
dev.off()
devtools::document()
roxygen2::roxygenise()
?format_network
?scenario_sim
devtools::document()
roxygen2::roxygenise()
?scenario_sim
## Not run:
#Load association matrices
load("data-raw/am_list.RData")
#First item in the list is data across all days
m <- am_list[[1]]
res <- scenario_sim(net = m, n.sim = 10, num.initial.cases = 1,prop.asym=0.4,
prop.ascertain = 0.9, cap_max_days = 70,
delay_shape = 1, delay_scale = 1.4, R = 0.8, presymrate = 0.2, scenario = "nothing",
testing = FALSE, outside = 0.001, distancing = 0)
res
>outbreak_model
?outbreak_model
devtools::document()
roxygen2::roxygenise()
?outbreak_model
load("data-raw/am_list.RData")
haslemere <- format_network(am_list[[1]])
outbreak_model(net = haslemere, num.initial.cases = 1, prop.ascertain = 0.9, cap_max_days = 69, R = 0.8, presymrate = 0.2,
delay_shape = 1,delay_scale = 1.4,prop.asym = 0.4, quarantine = TRUE, isolation = TRUE, tracing = TRUE, secondary = TRUE,
outside = 0.001, testing = FALSE, test_neg = 0.1)
?outbreak_step
load("data-raw/am_list.RData")
haslemere <- format_network(am_list[[1]])
# incubation period sampling function
incfn <- dist_setup(dist_shape = 2.322737,dist_scale = 6.492272)
# delay distribution sampling function
delayfn <- dist_setup(1, 1.4)
# generate initial cases
case_data <- outbreak_setup(net = haslemere, num.initial.cases = 1,incfn,delayfn,prop.asym=0.4, isolation = TRUE)
# generate next generation of cases
outbreak_step(day = 1, case_data = case_data,net = haslemere, prop.asym = 0.4, incfn = incfn, delayfn = delayfn, prop.ascertain = 1,
presymrate = 0.2, R = 0.8, quarantine = TRUE, isolation = TRUE, tracing = TRUE, secondary = TRUE, outside = 0.001, testing = FALSE,test_neg = 0.1)
?outbreak_setup
devtools::document()
roxygen2::roxygenise()
?outbreak_setup
load("data-raw/am_list.RData")
haslemere <- format_network(am_list[[1]])
# incubation period sampling function
incfn <- dist_setup(dist_shape = 2.322737,dist_scale = 6.492272)
# delay distribution sampling function
delayfn <- dist_setup(dist_shape = 1,dist_scale = 1.4)
outbreak_setup(net, num.initial.cases = 1,incfn,delayfn,prop.asym=0, isolation = TRUE)
outbreak_setup(haslemere, num.initial.cases = 1,incfn,delayfn,prop.asym=0, isolation = TRUE)
devtools::document()
roxygen2::roxygenise()