2
2
# UK model: plot outputs
3
3
# - - - - - - - - - - - - - - - - - - - - - - -
4
4
5
+ library(ggplot2 )
5
6
library(cowplot )
6
7
library(stringr )
7
8
library(rlang )
@@ -66,8 +67,7 @@ deaths, peak, week
66
67
beds_icu, peak, t
67
68
beds_nonicu, peak, t
68
69
cases, peak_time, week
69
- trace_lockdown, lockdown_duration, t
70
- subclinical, total, t" )
70
+ trace_lockdown, lockdown_duration, t" )
71
71
72
72
median_ci = function (x , conf = 0.95 )
73
73
{
@@ -77,7 +77,7 @@ median_ci = function(x, conf = 0.95)
77
77
return (y )
78
78
}
79
79
80
- make_table = function (d )
80
+ make_table = function (d , table_spec = table_spec )
81
81
{
82
82
d [, week : = t %/% 7 ]
83
83
results = NULL
@@ -93,6 +93,18 @@ make_table = function(d)
93
93
res = res [, median_ci(x ), by = .(scenario , region , statistic )];
94
94
stat_nice = paste(" Total" , comp );
95
95
} else if (stat == " peak" ) {
96
+ # res = d[region == "United Kingdom" & compartment == comp, .(x = sum(value)), by = c("scenario", "run", "t", "region")];
97
+ # if (time == "week") {
98
+ # res = merge(res, res[, .(peak_day = t[which.max(x)]), by = .(scenario, run, region)]);
99
+ # res[, in_peak_week := abs(t - peak_day) <= 3];
100
+ # res = res[in_peak_week == T, .(x = sum(x)), by = .(scenario, run, region)];
101
+ # } else {
102
+ # res = res[, .(x = max(x)), by = .(scenario, run, region)];
103
+ # }
104
+ # res[, statistic := paste(stat, comp)];
105
+ # res = res[, median_ci(x), by = .(scenario, region, statistic)];
106
+ # stat_nice = ifelse(time == "t", paste("Peak", comp, "required"),
107
+ # paste(comp, "in peak week"));
96
108
res = d [region == " United Kingdom" & compartment == comp , .(x = sum(value )), by = c(" scenario" , " run" , time , " region" )];
97
109
res = res [, .(x = max(x )), by = .(scenario , run , region )];
98
110
res [, statistic : = paste(stat , comp )];
@@ -241,6 +253,10 @@ plot_epi = function(d0, t, quant, ymd_start, ymd_truncate = "2050-01-01", colour
241
253
qrun = t [scenario == " Base" , sum(total ), by = run ][, which(rank(V1 ) %in% round(1 + (.N - 1 ) * quant ))];
242
254
d = d [run %in% qrun ];
243
255
256
+ if (d [, max(run ) == 5 ]) {
257
+ mrun = 5 ;
258
+ }
259
+
244
260
# Merge intervention traces
245
261
trace_school = d [compartment == " trace_school" , .(run , t , trace_school = value - 1 , scenario )]
246
262
d = merge(d , trace_school , by = c(" run" , " t" , " scenario" ), all.x = T );
@@ -297,12 +313,15 @@ plot_epi = function(d0, t, quant, ymd_start, ymd_truncate = "2050-01-01", colour
297
313
theme_set(theme_cowplot(font_size = 7 , line_size = 0.25 ))
298
314
299
315
# load data
316
+ covid_uk_path = paste0(covid_uk_path , " /output/may7" )
300
317
d1 = reflow_dynamics(qread(paste0(covid_uk_path , " /1-dynamics.qs" )));
301
318
t1 = reflow_totals(qread(paste0(covid_uk_path , " /1-totals.qs" )));
302
319
d2.1 = reflow_dynamics(qread(paste0(covid_uk_path , " /2.1-dynamics.qs" )));
303
320
t2.1 = reflow_totals(qread(paste0(covid_uk_path , " /2.1-totals.qs" )));
304
321
d2.2 = reflow_dynamics(qread(paste0(covid_uk_path , " /2.2-dynamics.qs" )));
305
322
t2.2 = reflow_totals(qread(paste0(covid_uk_path , " /2.2-totals.qs" )));
323
+ d2.2v = reflow_dynamics(qread(paste0(covid_uk_path , " /2.2V-dynamics.qs" )));
324
+ t2.2v = reflow_totals(qread(paste0(covid_uk_path , " /2.2V-totals.qs" )));
306
325
d3 = reflow_dynamics(qread(paste0(covid_uk_path , " /3-dynamics.qs" )));
307
326
t3 = reflow_totals(qread(paste0(covid_uk_path , " /3-totals.qs" )));
308
327
d4 = reflow_dynamics(qread(paste0(covid_uk_path , " /4-dynamics.qs" )));
@@ -353,6 +372,11 @@ f = plot_grid(pla1, plb, pla2, plR,
353
372
nrow = 2 , ncol = 2 , rel_widths = c(3 , 2 ), labels = c(" a" , " b" , " " , " c" ), label_size = 9 , align = " hv" , axis = " bottom" )
354
373
ggsave(paste0(covid_uk_path , " /fig-12week.pdf" ), f , width = 20 , height = 12 , units = " cm" , useDingbats = F );
355
374
375
+ ggsave(paste0(covid_uk_path , " /fig-12week-a.pdf" ), plot_grid(pla1 , pla2 , ncol = 1 , align = " hv" , axis = " bottom" ),
376
+ width = 12 , height = 12 , units = " cm" , useDingbats = F );
377
+ ggsave(paste0(covid_uk_path , " /fig-12week-b.pdf" ), plb , width = 8 , height = 6 , units = " cm" , useDingbats = F );
378
+ ggsave(paste0(covid_uk_path , " /fig-12week-c.pdf" ), plR , width = 8 , height = 6 , units = " cm" , useDingbats = F );
379
+
356
380
# ANALYSIS 2 - TRIGGERS
357
381
d2.1 [scenario != " Base" , scenario : = paste(scenario , " national" )]
358
382
d2.2 [scenario != " Base" , scenario : = paste(scenario , " local" )]
@@ -377,7 +401,7 @@ save_table(tb2, paste0(covid_uk_path, "/table-triggers.csv"));
377
401
pl2 = plot_attackrate(t2 )
378
402
pl3 = plot_epi(d2 , t2 , (0 : 10 )/ 10 , " 2020-01-29" )
379
403
f = plot_grid(pl1 , pl2 , pl3 , ncol = 1 , rel_heights = c(6 , 6 , 10 ), labels = c(" a" , " b" , " c" ), label_size = 9 );
380
- ggsave(paste0(covid_uk_path , " /COVID-UK/ full-2.pdf" ), f , width = 20 , height = 22 , units = " cm" , useDingbats = F );
404
+ ggsave(paste0(covid_uk_path , " /full-2.pdf" ), f , width = 20 , height = 22 , units = " cm" , useDingbats = F );
381
405
382
406
pla1 = plot_epi(d2 [compartment != " deaths" & compartment != " beds_nonicu" & compartment != " beds_icu" &
383
407
scenario %like % " Local" ], t2 , (0 : 10 )/ 10 , " 2020-01-29" , " 2020-8-31" , exclude = " Base" );
@@ -407,15 +431,18 @@ plc = plot_grid(plc1, plc2, plc3, nrow = 3, align = "v", axis = "bottom", rel_he
407
431
f = plot_grid(pla , plb , plc ,
408
432
ncol = 3 , labels = c(" a" , " b" , " c" ), label_size = 9 , rel_widths = c(2 , 1 , .5 ))
409
433
ggsave(paste0(covid_uk_path , " /fig-triggers.pdf" ), f , width = 20 , height = 8 , units = " cm" , useDingbats = F );
434
+ ggsave(paste0(covid_uk_path , " /fig-triggers-a.pdf" ), pla , width = 20 * 4 / 7 , height = 8 , units = " cm" , useDingbats = F );
435
+ ggsave(paste0(covid_uk_path , " /fig-triggers-b.pdf" ), plb , width = 20 * 2 / 7 , height = 8 , units = " cm" , useDingbats = F );
436
+ ggsave(paste0(covid_uk_path , " /fig-triggers-c.pdf" ), plc , width = 20 * 1 / 7 , height = 8 , units = " cm" , useDingbats = F );
410
437
411
438
# ANALYSIS 3 - LOCKDOWN
412
439
d3 [scenario == " Intensive Interventions NA lockdown" , scenario : = " Intensive Interventions" ];
413
440
d3 [scenario == " Intensive Interventions 1000 lockdown" , scenario : = " Lockdown 1000-bed trigger" ];
414
441
d3 [scenario == " Intensive Interventions 2000 lockdown" , scenario : = " Lockdown 2000-bed trigger" ];
415
442
d3 [scenario == " Intensive Interventions 5000 lockdown" , scenario : = " Lockdown 5000-bed trigger" ];
416
- # d3[compartment == "subclinical"]$value = d3[compartment == "subclinical"]$value + d3[compartment == "cases"]$value
443
+ d3 [compartment == " subclinical" ]$ value = d3 [compartment == " subclinical" ]$ value + d3 [compartment == " cases" ]$ value
417
444
418
- tb3 = make_table(d3 )
445
+ tb3 = make_table(d3 , rbind( table_spec , data.table( compartment = " subclinical " , stat = " total " , time = " t " )) )
419
446
pl1 = plot_table(tb3 )
420
447
save_table(tb3 , paste0(covid_uk_path , " /table-lockdown.csv" ));
421
448
pl2 = plot_attackrate(t3 )
@@ -461,6 +488,11 @@ plR = ggplot(r0s2) +
461
488
f = plot_grid(pla1 , plb , pla2 , plR ,
462
489
nrow = 2 , ncol = 2 , rel_widths = c(3 , 2 ), labels = c(" a" , " b" , " " , " c" ), label_size = 9 , align = " hv" , axis = " bottom" )
463
490
ggsave(paste0(covid_uk_path , " /fig-lockdown.pdf" ), f , width = 20 , height = 12 , units = " cm" , useDingbats = F );
491
+ ggsave(paste0(covid_uk_path , " /fig-lockdown-a.pdf" ), plot_grid(pla1 , pla2 , ncol = 1 , align = " hv" , axis = " bottom" ),
492
+ width = 12 , height = 12 , units = " cm" , useDingbats = F );
493
+ ggsave(paste0(covid_uk_path , " /fig-lockdown-b.pdf" ), plb , width = 8 , height = 6 , units = " cm" , useDingbats = F );
494
+ ggsave(paste0(covid_uk_path , " /fig-lockdown-c.pdf" ), plR , width = 8 , height = 6 , units = " cm" , useDingbats = F );
495
+
464
496
465
497
# ANALYSES 4,6 - GRANDPARENTS AND SPORTS/LEISURE
466
498
# Grandparents
@@ -504,8 +536,127 @@ pla = plot_table(tb6[scenario != "Base" & statistic != "Deaths in peak week"]) +
504
536
guides(colour = guide_legend(nrow = 3 , byrow = TRUE )) + labs(colour = NULL )
505
537
f = plot_grid(pla , plb , nrow = 2 , labels = c(" a" , " b" ), label_size = 9 , align = " hv" , axis = " bottom" );
506
538
ggsave(paste0(covid_uk_path , " /fig-misc.pdf" ), f , width = 9 , height = 12 , units = " cm" , useDingbats = F );
539
+ ggsave(paste0(covid_uk_path , " /fig-misc-a.pdf" ), pla , width = 9 , height = 6 , units = " cm" , useDingbats = F );
540
+ ggsave(paste0(covid_uk_path , " /fig-misc-b.pdf" ), plb , width = 9 , height = 6 , units = " cm" , useDingbats = F );
541
+
542
+
543
+ # TOTAL INFECTIONS
544
+ 1 - quantile(d1 [scenario == " Base" & compartment == " S" & t == 702 & region == " United Kingdom" ]$ value /
545
+ d1 [scenario == " Base" & compartment == " S" & t == 0 & region == " United Kingdom" ]$ value , c(0.025 , 0.5 , 0.975 ))
546
+
547
+ # CASES AMONG INFECTIONS
548
+ cases = d1 [scenario == " Base" & compartment == " cases" & region == " United Kingdom" , sum(value ), by = run ]
549
+ subclin = d1 [scenario == " Base" & compartment == " subclinical" & region == " United Kingdom" , sum(value ), by = run ]
550
+ quantile(cases $ V1 / (cases $ V1 + subclin $ V1 ), c(0.025 , 0.5 , 0.975 ))
507
551
552
+ # STOPPED EPIDEMICS FROM COMBINED INTERVENTION (DURING CONTROL PERIOD)
553
+ r0s [scenario == " Combination" , sum(R0 < 1 )]
554
+
555
+ # SPORTS/LEISURE IMPACT
556
+ quantile(1 - d6 [scenario == " Spectator sports banned" & compartment == " cases" & region == " United Kingdom" , sum(value ), by = run ]$ V1 /
557
+ d6 [scenario == " Background" & compartment == " cases" & region == " United Kingdom" , sum(value ), by = run ]$ V1 , c(0.025 , 0.5 , 0.975 ))
558
+
559
+ quantile(1 - d6 [scenario == " Leisure reduced by 75%" & compartment == " cases" & region == " United Kingdom" , sum(value ), by = run ]$ V1 /
560
+ d6 [scenario == " Background" & compartment == " cases" & region == " United Kingdom" , sum(value ), by = run ]$ V1 , c(0.025 , 0.5 , 0.975 ))
561
+
562
+ # INTENSIVE INTERVENTIONS IMPACT (DEATHS)
563
+ # SPORTS/LEISURE IMPACT
564
+ quantile(1 - d3 [scenario == " Intensive Interventions" & compartment == " deaths" & region == " United Kingdom" , sum(value ), by = run ]$ V1 /
565
+ d1 [scenario == " Base" & compartment == " deaths" & region == " United Kingdom" , sum(value ), by = run ]$ V1 , c(0.025 , 0.5 , 0.975 ))
508
566
509
567
# NINGBO EST.
510
568
x = rbeta(100000 , 6 , 140 )/ rbeta(100000 , 126 , 1875 )
511
569
cm_mean_hdi(x )
570
+
571
+ # COMPARISON WITH UK DEATHS
572
+ ukdeaths = fread(
573
+ " Area name Area code Area type Reporting date Daily hospital deaths Cumulative hospital deaths
574
+ United Kingdom K02000001 UK 2020-03-27 181 759
575
+ United Kingdom K02000001 UK 2020-03-26 115 578
576
+ United Kingdom K02000001 UK 2020-03-25 41 463
577
+ United Kingdom K02000001 UK 2020-03-24 87 422
578
+ United Kingdom K02000001 UK 2020-03-23 54 335
579
+ United Kingdom K02000001 UK 2020-03-22 48 281
580
+ United Kingdom K02000001 UK 2020-03-21 56 233
581
+ United Kingdom K02000001 UK 2020-03-20 33 177
582
+ United Kingdom K02000001 UK 2020-03-19 41 144
583
+ United Kingdom K02000001 UK 2020-03-18 32 103
584
+ United Kingdom K02000001 UK 2020-03-17 16 71
585
+ United Kingdom K02000001 UK 2020-03-16 20 55
586
+ United Kingdom K02000001 UK 2020-03-15 14 35
587
+ United Kingdom K02000001 UK 2020-03-14 21
588
+ United Kingdom K02000001 UK 2020-03-13 8
589
+ United Kingdom K02000001 UK 2020-03-12 8
590
+ United Kingdom K02000001 UK 2020-03-11 6
591
+ United Kingdom K02000001 UK 2020-03-10 6" )
592
+
593
+ deaths = d1 [scenario == " Base" & compartment == " deaths" & region == " United Kingdom" , cm_mean_hdi(value ), by = t ]
594
+ ggplot(deaths [t < 60 ]) +
595
+ geom_ribbon(aes(x = ymd(" 2020-01-29" ) + t , ymin = lower , ymax = upper ), alpha = 0.25 ) +
596
+ geom_line(aes(x = ymd(" 2020-01-29" ) + t , y = mean )) +
597
+ geom_point(data = ukdeaths , aes(x = ymd(`Reporting date` ), y = `Daily hospital deaths` ), colour = " red" ) +
598
+ labs(x = " Date" , y = " Daily hospital deaths" )
599
+
600
+ # VARIATION SENSITIVITY
601
+ # `Combination` = list(contact = c(1.0, 0.5, 0.0, 0.5, 1.0, 0.25, 0.0, 0.25, 0), fIs = rep(0.65, 16))
602
+
603
+ dists = data.table(x = (0 : 100 )/ 100 );
604
+ dists [, d50 : = dbeta(x , 10 , 10 )];
605
+ dists [, d25 : = dbeta(x , 5 , 15 )];
606
+ dists [, d65 : = dbeta(x , 13 , 7 )];
607
+
608
+ pll = ggplot(dists , aes(x = x )) +
609
+ geom_line(aes(y = d50 / max(d50 ), colour = " Work, other contacts in under-70s" ), linetype = " dashed" ) +
610
+ geom_line(aes(y = d25 / max(d25 ), colour = " Work, other contacts in over-70s" ), linetype = " dashed" ) +
611
+ geom_line(aes(y = d65 / max(d65 ), colour = " Infectiousness of symptomatic individuals" ), linetype = " dashed" ) +
612
+ geom_pointrange(aes(x = 0.50 , ymin = 0 , ymax = 1 , y = 1 , colour = " Work, other contacts in under-70s" ), size = 0.25 , fatten = 0.2 ) +
613
+ geom_pointrange(aes(x = 0.25 , ymin = 0 , ymax = 1 , y = 1 , colour = " Work, other contacts in over-70s" ), size = 0.25 , fatten = 0.2 ) +
614
+ geom_pointrange(aes(x = 0.65 , ymin = 0 , ymax = 1 , y = 1 , colour = " Infectiousness of symptomatic individuals" ), size = 0.25 , fatten = 0.2 ) +
615
+ labs(colour = NULL , x = NULL , y = " Normalised density" ) +
616
+ guides(colour = guide_legend(nrow = 3 , byrow = TRUE , reverse = TRUE )) +
617
+ theme(legend.position = " bottom" )
618
+
619
+ d7 = rbind(
620
+ d2.2 [scenario == " Base" ],
621
+ d2.2 [scenario == " Combination 28 shift local" ],
622
+ d2.2v [scenario == " Combination" ]
623
+ )
624
+ t7 = rbind(
625
+ t2.2 [scenario == " Base" ],
626
+ t2.2 [scenario == " Combination 28 shift local" ],
627
+ t2.2v [scenario == " Combination" ]
628
+ )
629
+ d7 [scenario == " Combination 28 shift local" , scenario : = " No variation" ]
630
+ d7 [scenario == " Combination" , scenario : = " Variation" ]
631
+ t7 [scenario == " Combination 28 shift local" , scenario : = " No variation" ]
632
+ t7 [scenario == " Combination" , scenario : = " Variation" ]
633
+
634
+ tb7 = make_table(d7 )
635
+ pl1 = plot_table(tb7 [scenario != " Base" ])
636
+ save_table(tb7 , paste0(covid_uk_path , " /table-variation.csv" ));
637
+ pl2 = plot_attackrate(t7 )
638
+ pl3 = plot_epi(d7 , t7 , (0 : 10 )/ 10 , " 2020-01-29" )
639
+ f = plot_grid(pl1 , pl2 , pl3 , ncol = 1 , rel_heights = c(6 , 6 , 10 ), labels = c(" a" , " b" , " c" ), label_size = 9 );
640
+ ggsave(paste0(covid_uk_path , " /full-7.pdf" ), f , width = 20 , height = 22 , units = " cm" , useDingbats = F );
641
+
642
+ pla = plot_epi(d7 [compartment != " deaths" & compartment != " beds_nonicu" ], t7 , (0 : 10 )/ 10 , " 2020-01-29" , " 2020-10-15" ,
643
+ colours = cols4 [1 : 3 ], exclude = " Base" );
644
+ tb7 [statistic == " Cases in peak week" , statistic : = " Cases in\n peak week" ];
645
+ tb7 [statistic == " Peak ICU beds required" , statistic : = " Peak ICU beds\n required" ];
646
+ tb7 [statistic == " Peak non-ICU beds required" , statistic : = " Peak non-ICU beds\n required" ];
647
+ tb7 [statistic == " Time to peak cases (weeks)" , statistic : = " Time to peak\n cases (weeks)" ];
648
+ plb = plot_table(tb7 [statistic != " Deaths in peak week" & statistic != " Total subclinical" & scenario != " Base" ]) + theme(legend.position = " bottom" ) +
649
+ guides(colour = guide_legend(nrow = 3 , byrow = TRUE )) + labs(colour = NULL )
650
+
651
+ googen = fread(paste0(covid_uk_path , " /../../data/Global_Mobility_Report.csv" )); # Google global mobility report
652
+ googen = googen [country_region_code == " GB" ];
653
+ googen = googen [date > = " 2020-04-01" & date < = " 2020-04-07" , mean(workplaces_percent_change_from_baseline ), by = sub_region_1 ]
654
+ plc = ggplot(googen ) +
655
+ geom_histogram(aes(x = 1 + V1 / 100 )) +
656
+ xlim(0 , 1 ) +
657
+ labs(x = " Relative workplace\n visits, 1-7 April 2020" , y = " Count" )
658
+
659
+ f = plot_grid(pll , pla , plb , plc ,
660
+ nrow = 1 , ncol = 4 , rel_widths = c(1.0 , 1.3 , 1.6 , 0.8 ), labels = c(" a" , " b" , " c" , " d" ), label_size = 9 , align = " hv" , axis = " bottom" )
661
+ ggsave(paste0(covid_uk_path , " /fig-variation.pdf" ), f , width = 24 , height = 6 , units = " cm" , useDingbats = F );
662
+ ggsave(paste0(covid_uk_path , " /fig-variation.png" ), f , width = 24 , height = 6 , units = " cm" );
0 commit comments