/
Weekly-Model-Evaluation_v9.Rmd
3740 lines (2924 loc) · 186 KB
/
Weekly-Model-Evaluation_v9.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
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "COVID-19 US Forecast Evaluation Report"
author: "This report was developed by the [Reich Lab](https://reichlab.io/) and the US [COVID-19 Forecast Hub](https://covid19forecasthub.org/) from UMass-Amherst in collaboration with [CMU Delphi](https://delphi.cmu.edu/), as part of the Forecast Evaluation Research Collaborative."
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
toc: true
toc_float:
collapsed: false
smooth_scroll: false
---
<!-- code to run rmarkdown::render(input="./vignettes/covidHubUtils-overview.Rmd") -->
<!-- Code for adding logo at the top -->
<!-- <script> -->
<!-- $(document).ready(function() { -->
<!-- $('#TOC').parent().prepend('<div id=\"nav_logo\"><a href=\"https://covid19forecasthub.org/\" target=\"_blank\"><img src=\"https://github.com/reichlab/covid19-forecast-hub-web/raw/master/images/forecast-hub-logo_DARKBLUE.png\"></a></div>'); -->
<!-- }); -->
<!-- </script> -->
<style>
#nav_logo {
width: 100%;
margin-top: 20px;
}
#TOC {
background: url("https://github.com/reichlab/covid19-forecast-hub-web/raw/master/images/forecast-hub-logo_DARKBLUE-20px-padding.png");
background-size: contain;
padding-top: 80px !important;
background-repeat: no-repeat;
}
</style>
<!-- </style> -->
```{r setup, include=FALSE}
#load libraries
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(lubridate)
library(scoringutils)
library(RColorBrewer)
library(DT)
library(surveillance)
library(htmltools)
library(kableExtra)
library(covidHubUtils)
library(plotly)
library(tidyverse)
library(zoltr)
library(dplyr)
library(desc)
theme_set(theme_bw())
source("functions_weekly_evaluation.R")
data("hub_locations")
```
```{r prelim set values}
# the_locations <- hub_locations %>% filter(geo_type == "state") %>%
# filter(abbreviation %in% datasets::state.abb) %>% pull(fips) #states, us and territories
county_fips <- hub_locations %>% #counties: 500 most populous
filter(geo_type == "county") %>%
filter(abbreviation %in% datasets::state.abb) %>%
arrange(-population) %>%
filter(row_number()<=500) %>% pull(fips)
US_fips <- hub_locations %>% filter(geo_type == "state") %>% filter(abbreviation %in% datasets::state.abb) %>% pull(fips) #only 50 states
the_locations <- hub_locations %>% filter(geo_type == "state") %>% pull(fips) #states, us and territories
n_weeks_ohio <- 4 #weeks to exclude truth data for ohio
n_weeks_eval <- 10 #weeks included in evaluation
n_weeks_history <-52 # number of weeks for historical data
```
```{r get-date-boundaries}
#Important dates used
# fixed date
# forecast_mon <- as.Date ("2022-07-04")
forecast_mon <- lubridate::floor_date(Sys.Date(), unit = "week") + 1 #Even when running on Tuesday, will be Monday date
last_eval_sat <- as.Date(calc_target_week_end_date(forecast_mon, horizon = 0))
first_eval_sat <- last_eval_sat - 7*(n_weeks_eval - 1) #First Evaluated Date
first_eval_sat_ohio <- last_eval_sat - 7*(n_weeks_ohio - 1) #First week to exclude truth data for Ohio
first_eval_sat_hist <- last_eval_sat - 7*(n_weeks_history - 1) #First Evaluated Date (historical)
last_submission_date <- last_eval_sat - 5 #Last submission date
first_submission_date <- first_eval_sat - 11 #First submission date
first_mon_cutoff <- first_eval_sat - 5
last_1wk_target_end_date <- as.Date(calc_target_week_end_date(last_submission_date, horizon = 1)) #last 1 week ahead horizon
first_1wk_target_end_date <- as.Date(calc_target_week_end_date(first_submission_date, horizon = 0)) #first 1 week ahead horizon
first_4wk_target_end_date <- as.Date(calc_target_week_end_date(first_submission_date, horizon = 4)) #first horizon with all 4 target weeks evaluated
last_4wk_target_end_date <- as.Date(calc_target_week_end_date(last_submission_date, horizon = 4))
eval_sat <- c(first_eval_sat, last_eval_sat) #range of dates evaluated
```
```{r load data}
#load files generated in query-scores-weekly-report.R
load(file = "truth_dat_case.rda")
load(file = "truth_dat_inc.rda")
load(file = "truth_dat_hosp.rda")
load(file = "truth_dat_hosp_all.rda")
load(file = "truth_dat_inc_all.rda")
load(file = "truth_dat_case_all.rda")
load(file = "score_hosp_all.rda")
load(file = "score_inc_all.rda")
load(file = "score_case_all.rda")
# remove COVIDhub-ensemble and COVID_CDC-ensemble models
score_inc_all <- score_inc_all %>% filter(model != "COVIDhub-ensemble" & model != "COVIDhub_CDC-ensemble")
score_case_all <- score_case_all %>% filter(model != "COVIDhub-ensemble" & model != "COVIDhub_CDC-ensemble")
score_hosp_all <- score_hosp_all %>% filter(model != "COVIDhub-ensemble" & model != "COVIDhub_CDC-ensemble")
# score_case_all <- score_case_all %>% filter(model != "COVIDhub-4_week_ensemble")
# score_hosp_all <- score_hosp_all %>% filter(model != "COVIDhub-4_week_ensemble")
# remove most recent 4 weeks of truth/score for ohio
truth_dat_inc_all_ohio <- truth_dat_inc_all %>%
subset((location != "39") | (location == "39" & target_end_date < first_eval_sat_ohio))
truth_dat_inc_ohio <- truth_dat_inc %>%
subset((location != "39") | (location == "39" & target_end_date < first_eval_sat_ohio))
score_inc_all_ohio <- score_inc_all %>%
subset((location != "39") | (location == "39" & target_end_date < first_eval_sat_ohio))
# split state and county case data
score_case_all_s <- score_case_all %>% #states, us and territories
filter(location %in% the_locations)
score_case_all_c <- score_case_all %>% #500 most popoulus counties
filter(location %in% county_fips)
# split state and county truth data
truth_dat_case_s <- truth_dat_case %>% #states, us and territories
filter(location %in% the_locations)
truth_dat_case_c <- truth_dat_case %>% #500 most popoulus counties
filter(location %in% county_fips)
truth_dat_case_all_s <- truth_dat_case_all %>% #states, us and territories
filter(location %in% the_locations)
truth_dat_case_all_c <- truth_dat_case_all %>% #500 most popoulus counties
filter(location %in% county_fips)
```
```{r}
location_order_case_s <- truth_dat_case_s %>%
filter(target_end_date == max(target_end_date)) %>%
arrange(value) %>%
pull(location_name)
location_order_case_c <- truth_dat_case_c %>%
filter(target_end_date == max(target_end_date)) %>%
arrange(value) %>%
pull(location_name)
location_order_death <- truth_dat_inc %>%
filter(target_end_date == max(target_end_date)) %>%
arrange(value) %>%
pull(location_name)
location_order_hosp <- truth_dat_hosp %>%
filter(target_end_date == max(target_end_date)) %>%
arrange(value) %>%
pull(location_name)
```
```{r inclusion in accuracy table historical}
#at least 50% of historical WIS or historical MAE
case_accuracy_historical_s <- historical_accuracy_filter(score_case_all_s)
case_accuracy_historical_c <- historical_accuracy_filter(score_case_all_c)
inc_accuracy_historical <- historical_accuracy_filter(score_inc_all_ohio)
hosp_accuracy_historical <- historical_accuracy_filter(score_hosp_all)
```
# Overview
This report provides an evaluation of the accuracy and precision of probabilistic forecasts of COVID-19 cases and deaths submitted to the [US COVID-19 Forecast Hub](https://covid19forecasthub.org/){target="_blank"}. Some analyses include forecasts submitted in the past twelve months, starting in `r format(first_eval_sat_hist, "%B %d, %Y")`. Others focus on evaluating "recent" forecasts, submitted only in the last `r n_weeks_eval` weeks.
<!-- The forecasts evaluated were submitted during the time period from `r format(first_submission_date, "%B %d, %Y")` through `r format(last_submission_date, "%B %d, %Y")`. The revision dates of this data was calculated as of `r today()`.
In this weekly report we are evaluating forecasts made in 57 different locations (US on a national level, 50 states, and 6 territories), for 4 horizons over `r n_weeks_eval` submission weeks. We are evaluating incident cases, and incident deaths.
Additionally, we have included a historical score report to aggregate scores from forecasts that have been submitted to the forecast hub since the first week in April.
-->
In collaboration with the US Centers for Disease Control and Prevention (CDC), the COVID-19 Forecast hub collects short-term COVID-19 forecasts from dozens of research groups around the globe. Every week we combine the most recent forecasts from each team into a single "ensemble" forecast for each of the targets. This forecast is used as the official ensemble forecast of the CDC, typically appearing on their [forecasting website](https://www.cdc.gov/coronavirus/2019-ncov/covid-data/mathematical-modeling.html){target="_blank"} on Wednesday. You can explore the full set of models, including their forecasts for past weeks online at the [Forecast Hub interactive visualization](https://viz.covid19forecasthub.org/){target="_blank"}. Other related resources include CMU Delphi's [forecast evaluation dashboard](https://delphi.cmu.edu/forecast-eval/){target="_blank"}, a separate product of the Forecast Evaluation Research Collaborative, as well as the preprint [Evaluation of individual and ensemble probabilistic forecasts of COVID-19 mortality in the US.](https://www.medrxiv.org/content/10.1101/2021.02.03.21250974v3){target="_blank"}
This report evaluates forecasts at the state and national level for newly reported weekly cases, deaths and hospitalizations due to COVID-19. Data from the [JHU CSSE dashboard](https://coronavirus.jhu.edu/){target="_blank"} is used as ground truth data for evaluating the forecasts.
Starting on September 6, 2021, COVIDhub-ensemble only reported two-week ahead forecasts for cases, due to persistent large inaccuracies observed when forecasting beyond that. As of September 28, 2021, COVIDhub-ensemble only reports one-week ahead forecasts for cases and 14 day ahead forecasts for hospitalizations. For a more complete explanation see our blog post [here](https://forecasters.org/blog/2021/09/28/on-the-predictability-of-covid-19/){target="_blank"}.
To reduce duplication of results, the COVIDhub_CDC-ensemble and COVIDhub-ensemble are omitted from this evaluation. The COVIDhub_CDC-ensemble pulls a subset of forecasts of cases and hospitalizations from the COVIDhub-4_week_ensemble and forecasts of deaths from the COVIDhub-trained_ensemble, and the COVIDhub-ensemble nearly matches the COVIDhub-4_week_ensemble and COVIDhub-trained_ensemble predictions for those targets up to occasional small differences in the included models. As a result, the performance of the COVIDhub_CDC-ensemble and COVIDhub-ensemble models matches or nearly matches the performance of the COVIDhub-4_week_ensemble and COVIDhub-trained_ensemble on those targets. For more information about COVID19 forecast hub ensemble methods see [this page](https://covid19forecasthub.org/doc/ensemble/){target="_blank"}.
We evaluate models based on their [adjusted relative weighted interval scores (WIS, a measure of distributional accuracy)](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1008618){target="_blank"}, and adjusted relative mean absolute error (MAE). Scores are aggregated separately for the most recent 10 weeks and for 52 historical weeks. To account for the variation in difficult of forecasting different weeks and locations, a [pairwise approach](https://www.medrxiv.org/content/10.1101/2021.02.03.21250974v2){target="_blank"} was used to calculated the relative adjusted WIS and MAE. Models with relative scores lower than 1 have been more accurate than the baseline on average, whereas relative scores greater than 1 indicate less accuracy than baseline on average.
# Incident Death Forecasts {.tabset .tabset-fade}
## Summary Tables {.tabset .tabset-fade}
Due to technical issues Ohio has with reporting deaths, the most recent 4 weeks of death data for Ohio will not be included in this evaluation.
The first and second tables evaluate recent/historical forecast models based on their WIS and MAE by horizon.
The third and fourth tables evaluate recent/historical forecast models based on their prediction interval coverage at the 50% and 95% levels by horizon.
Scores are aggregated separately for the most recent 10 weeks and for 52 historical weeks.
<!--The table included below evaluated models based on their prediction interval coverage (50% and 95% coverage), and their adjusted relative weighted interval scores (WIS) and adjusted relative mean absolute error (MAE) for a recent and historical number of weeks.
* The **prediction interval coverage** measures the proportion of times a prediction interval of a certain level covered the true value, to assess the degree to which forecasts accurately characterized uncertainty about future observations. Well calibrated models should have a 50% coverage level of 0.5 and a 95% coverage level of 0.95.
* The **weighted interval score (WIS)** is a proper score that combines a set of interval scores for probabilistic forecasts that provide quantiles of the predictive forecast distribution. To account for the variation in difficult of forecasting different weeks and locations, a pairwis approach was used to calculated the relative adjusted WIS. The code for this comparison can be found [here](https://github.com/jbracher/pairwise_comparisons). A preprint on this method for calculating the WIS can be found [here](https://arxiv.org/pdf/2005.12881.pdf). Models with an adjusted relative WIS lower than 1 are more accurate than the baseline, and models with an adjusted relative WIS greater than 1 are less accurate than the baseline is predicting the number of incident cases.
* The **mean absolute error (MAE)** is defined as the the difference between the forecasted value and the actual value. For this calculation, point forecasts submitted by teams were used. When point forecasts were not available, the 0.50 quantile was used. Similar to calculating the WIS, a pairwise approach was used to account for variation across locations and weeks. Models with an adjusted relative MAE lower than 1 are more accurate than the baseline, and models with an adjusted relative MAE greater than 1 are less accurate than the baseline is predicting the number of incident cases.
-->
Inclusion criteria for each column are detailed below the table.
```{r recent relative wis DEATHs}
#at least 50% of recent WIS or 50% of recent MAE
inc_accuracy_recent <- recent_accuracy_filter(score_inc_all_ohio,first_eval_sat)
inc_scores <- inc_accuracy_recent %>%
filter(!is.na(score_value)) %>%
filter(n_locations >= 25) %>%
filter(n_weeks >= 4) %>%
droplevels()
# bring all timezeros to Saturday:
inc_scores$timezero <- inc_scores$submission_sat
# restrict to 1-4 wk ahead state-level
scores <- inc_scores %>% filter(horizon %in% paste(1:4), location %in% US_fips) %>%
filter(score_name %in% c("abs_error", "wis")) %>%
select("model", "timezero", "location", "horizon", "score_name", "score_value") %>%
pivot_wider(names_from = score_name, values_from = score_value) %>%
filter(!is.na(wis)) %>%
droplevels()
# the included models:
models <- unique(scores$model)
# matrices to store:
results_ratio_hzn1 <- matrix(ncol = length(models),
nrow = length(models),
dimnames = list(models, models))
results_ratio_list <- list(results_ratio_hzn1, results_ratio_hzn1,
results_ratio_hzn1, results_ratio_hzn1)
set.seed(123) # set seed for permutation tests
for(mx in seq_along(models)){
for(my in 1:mx){
for(hzn in 1:4){
pwc <- pairwise_comparison(scores = filter(scores, horizon==hzn),
mx = models[mx],
my = models[my],
permutation_test = FALSE)
results_ratio_list[[hzn]][mx, my] <- pwc$ratio
results_ratio_list[[hzn]][my, mx] <- 1/pwc$ratio
}
}
}
ind_baseline <- which(rownames(results_ratio_list[[1]]) == "COVIDhub-baseline")
geom_mean_ratios_hzn1 <- exp(rowMeans(log(results_ratio_list[[1]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn2 <- exp(rowMeans(log(results_ratio_list[[2]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn3 <- exp(rowMeans(log(results_ratio_list[[3]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn4 <- exp(rowMeans(log(results_ratio_list[[4]][, -ind_baseline]), na.rm = TRUE))
ratios_baseline_raw_hzn1 <- results_ratio_list[[1]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn2 <- results_ratio_list[[2]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn3 <- results_ratio_list[[3]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn4 <- results_ratio_list[[4]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_adj_hzn1 <- geom_mean_ratios_hzn1/geom_mean_ratios_hzn1["COVIDhub-baseline"]
ratios_baseline_adj_hzn2 <- geom_mean_ratios_hzn2/geom_mean_ratios_hzn2["COVIDhub-baseline"]
ratios_baseline_adj_hzn3 <- geom_mean_ratios_hzn3/geom_mean_ratios_hzn3["COVIDhub-baseline"]
ratios_baseline_adj_hzn4 <- geom_mean_ratios_hzn4/geom_mean_ratios_hzn4["COVIDhub-baseline"]
tab <- data.frame(model = c(names(geom_mean_ratios_hzn1),
names(geom_mean_ratios_hzn2),
names(geom_mean_ratios_hzn3),
names(geom_mean_ratios_hzn4)),
horizon = rep(1:4, each=length(geom_mean_ratios_hzn1)),
geom_mean_ratios = c(geom_mean_ratios_hzn1,
geom_mean_ratios_hzn2,
geom_mean_ratios_hzn3,
geom_mean_ratios_hzn4),
ratios_baseline_raw = c(ratios_baseline_raw_hzn1,
ratios_baseline_raw_hzn2,
ratios_baseline_raw_hzn3,
ratios_baseline_raw_hzn4),
ratios_baseline_adj = c(ratios_baseline_adj_hzn1,
ratios_baseline_adj_hzn2,
ratios_baseline_adj_hzn3,
ratios_baseline_adj_hzn4)
)
tab <- tab[order(tab$horizon,tab$ratios_baseline_adj), ]
pairwise_scores <- tab %>%
mutate(relative_wis = round(ratios_baseline_adj, 2)) %>%
select(model, horizon, relative_wis) %>%
pivot_wider(names_from = "horizon",values_from = "relative_wis") %>%
rename("1 wk relWIS" = "1", "2 wk relWIS" = "2", "3 wk relWIS" = "3", "4 wk relWIS" = "4" ) %>%
dplyr::rowwise() %>%
dplyr::mutate(relative_wis = mean(c_across(where(is.numeric)), na.rm = T)) %>%
dplyr::ungroup() %>%
arrange(relative_wis)
```
```{r recent relative mae DEATHs}
# matrices to store:
results_ratio_hzn1 <- matrix(ncol = length(models),
nrow = length(models),
dimnames = list(models, models))
results_ratio_list <- list(results_ratio_hzn1, results_ratio_hzn1,
results_ratio_hzn1, results_ratio_hzn1)
set.seed(123) # set seed for permutation tests
for(mx in seq_along(models)){
for(my in 1:mx){
for(hzn in 1:4){
pwc <- pairabs_comparison(scores = filter(scores, horizon==hzn),
mx = models[mx],
my = models[my],
permutation_test = FALSE)
results_ratio_list[[hzn]][mx, my] <- pwc$ratio
results_ratio_list[[hzn]][my, mx] <- 1/pwc$ratio
}
}
}
ind_baseline <- which(rownames(results_ratio_list[[1]]) == "COVIDhub-baseline")
geom_mean_ratios_hzn1 <- exp(rowMeans(log(results_ratio_list[[1]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn2 <- exp(rowMeans(log(results_ratio_list[[2]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn3 <- exp(rowMeans(log(results_ratio_list[[3]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn4 <- exp(rowMeans(log(results_ratio_list[[4]][, -ind_baseline]), na.rm = TRUE))
ratios_baseline_raw_hzn1 <- results_ratio_list[[1]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn2 <- results_ratio_list[[2]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn3 <- results_ratio_list[[3]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn4 <- results_ratio_list[[4]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_adj_hzn1 <- geom_mean_ratios_hzn1/geom_mean_ratios_hzn1["COVIDhub-baseline"]
ratios_baseline_adj_hzn2 <- geom_mean_ratios_hzn2/geom_mean_ratios_hzn2["COVIDhub-baseline"]
ratios_baseline_adj_hzn3 <- geom_mean_ratios_hzn3/geom_mean_ratios_hzn3["COVIDhub-baseline"]
ratios_baseline_adj_hzn4 <- geom_mean_ratios_hzn4/geom_mean_ratios_hzn4["COVIDhub-baseline"]
tab <- data.frame(model = c(names(geom_mean_ratios_hzn1),
names(geom_mean_ratios_hzn2),
names(geom_mean_ratios_hzn3),
names(geom_mean_ratios_hzn4)),
horizon = rep(1:4, each=length(geom_mean_ratios_hzn1)),
geom_mean_ratios = c(geom_mean_ratios_hzn1,
geom_mean_ratios_hzn2,
geom_mean_ratios_hzn3,
geom_mean_ratios_hzn4),
ratios_baseline_raw = c(ratios_baseline_raw_hzn1,
ratios_baseline_raw_hzn2,
ratios_baseline_raw_hzn3,
ratios_baseline_raw_hzn4),
ratios_baseline_adj = c(ratios_baseline_adj_hzn1,
ratios_baseline_adj_hzn2,
ratios_baseline_adj_hzn3,
ratios_baseline_adj_hzn4)
)
tab <- tab[order(tab$horizon,tab$ratios_baseline_adj), ]
pairwise_scores_mae <- tab %>%
mutate(relative_mae = round(ratios_baseline_adj, 2)) %>%
select(model, horizon, relative_mae) %>%
pivot_wider(names_from = "horizon",values_from = "relative_mae") %>%
rename("1 wk relMAE" = "1", "2 wk relMAE" = "2", "3 wk relMAE" = "3", "4 wk relMAE" = "4" ) %>%
dplyr::rowwise() %>%
dplyr::mutate(relative_mae = mean(c_across(where(is.numeric)), na.rm = T)) %>%
dplyr::ungroup() %>%
arrange(relative_mae)
```
```{r historical relative WIS DEATH}
inc_scores <- inc_accuracy_historical %>%
filter(n_locations >= 25) %>%
filter(n_weeks >= 4) %>%
droplevels()
# bring all timezeros to Saturday:
inc_scores$timezero <- inc_scores$submission_sat
# restrict to 1-4 wk ahead state-level
scores <- inc_scores %>% filter(horizon %in% paste(1:4), location %in% US_fips) %>%
filter(!is.na(score_value)) %>%
select("model", "timezero", "location", "horizon", "score_name", "score_value") %>%
filter(score_name %in% c("abs_error", "wis")) %>%
pivot_wider(names_from = score_name, values_from = score_value) %>% filter(!is.na(wis))
# the included models:
models <- unique(scores$model)
# matrices to store:
results_ratio_hzn1 <- matrix(ncol = length(models),
nrow = length(models),
dimnames = list(models, models))
results_ratio_list <- list(results_ratio_hzn1, results_ratio_hzn1,
results_ratio_hzn1, results_ratio_hzn1)
set.seed(123) # set seed for permutation tests
for(mx in seq_along(models)){
for(my in 1:mx){
for(hzn in 1:4){
pwc <- pairwise_comparison(scores = filter(scores, horizon==hzn),
mx = models[mx],
my = models[my],
permutation_test = FALSE)
results_ratio_list[[hzn]][mx, my] <- pwc$ratio
results_ratio_list[[hzn]][my, mx] <- 1/pwc$ratio
}
}
}
ind_baseline <- which(rownames(results_ratio_list[[1]]) == "COVIDhub-baseline")
geom_mean_ratios_hzn1 <- exp(rowMeans(log(results_ratio_list[[1]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn2 <- exp(rowMeans(log(results_ratio_list[[2]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn3 <- exp(rowMeans(log(results_ratio_list[[3]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn4 <- exp(rowMeans(log(results_ratio_list[[4]][, -ind_baseline]), na.rm = TRUE))
ratios_baseline_raw_hzn1 <- results_ratio_list[[1]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn2 <- results_ratio_list[[2]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn3 <- results_ratio_list[[3]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn4 <- results_ratio_list[[4]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_adj_hzn1 <- geom_mean_ratios_hzn1/geom_mean_ratios_hzn1["COVIDhub-baseline"]
ratios_baseline_adj_hzn2 <- geom_mean_ratios_hzn2/geom_mean_ratios_hzn2["COVIDhub-baseline"]
ratios_baseline_adj_hzn3 <- geom_mean_ratios_hzn3/geom_mean_ratios_hzn3["COVIDhub-baseline"]
ratios_baseline_adj_hzn4 <- geom_mean_ratios_hzn4/geom_mean_ratios_hzn4["COVIDhub-baseline"]
tab <- data.frame(model = c(names(geom_mean_ratios_hzn1),
names(geom_mean_ratios_hzn2),
names(geom_mean_ratios_hzn3),
names(geom_mean_ratios_hzn4)),
horizon = rep(1:4, each=length(geom_mean_ratios_hzn1)),
geom_mean_ratios = c(geom_mean_ratios_hzn1,
geom_mean_ratios_hzn2,
geom_mean_ratios_hzn3,
geom_mean_ratios_hzn4),
ratios_baseline_raw = c(ratios_baseline_raw_hzn1,
ratios_baseline_raw_hzn2,
ratios_baseline_raw_hzn3,
ratios_baseline_raw_hzn4),
ratios_baseline_adj = c(ratios_baseline_adj_hzn1,
ratios_baseline_adj_hzn2,
ratios_baseline_adj_hzn3,
ratios_baseline_adj_hzn4)
)
tab <- tab[order(tab$horizon,tab$ratios_baseline_adj), ]
historical_wis <- tab %>%
mutate(relative_wis_historical = round(ratios_baseline_adj, 2)) %>%
select(model, horizon, relative_wis_historical) %>%
pivot_wider(names_from = "horizon",values_from = "relative_wis_historical") %>%
rename("1 wk relWIS" = "1", "2 wk relWIS" = "2", "3 wk relWIS" = "3", "4 wk relWIS" = "4" ) %>%
dplyr::rowwise() %>%
dplyr::mutate(relative_wis = mean(c_across(where(is.numeric)), na.rm = T)) %>%
dplyr::ungroup() %>%
arrange(relative_wis)
```
```{r historical relative MAE DEATHS}
# matrices to store:
results_ratio_hzn1 <- matrix(ncol = length(models),
nrow = length(models),
dimnames = list(models, models))
results_ratio_list <- list(results_ratio_hzn1, results_ratio_hzn1,
results_ratio_hzn1, results_ratio_hzn1)
set.seed(123) # set seed for permutation tests
for(mx in seq_along(models)){
for(my in 1:mx){
for(hzn in 1:4){
pwc <- pairabs_comparison(scores = filter(scores, horizon==hzn),
mx = models[mx],
my = models[my],
permutation_test = FALSE)
results_ratio_list[[hzn]][mx, my] <- pwc$ratio
results_ratio_list[[hzn]][my, mx] <- 1/pwc$ratio
}
}
}
ind_baseline <- which(rownames(results_ratio_list[[1]]) == "COVIDhub-baseline")
geom_mean_ratios_hzn1 <- exp(rowMeans(log(results_ratio_list[[1]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn2 <- exp(rowMeans(log(results_ratio_list[[2]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn3 <- exp(rowMeans(log(results_ratio_list[[3]][, -ind_baseline]), na.rm = TRUE))
geom_mean_ratios_hzn4 <- exp(rowMeans(log(results_ratio_list[[4]][, -ind_baseline]), na.rm = TRUE))
ratios_baseline_raw_hzn1 <- results_ratio_list[[1]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn2 <- results_ratio_list[[2]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn3 <- results_ratio_list[[3]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_raw_hzn4 <- results_ratio_list[[4]][, "COVIDhub-baseline"] ## avgWIS_model / avgWIS_baseline
ratios_baseline_adj_hzn1 <- geom_mean_ratios_hzn1/geom_mean_ratios_hzn1["COVIDhub-baseline"]
ratios_baseline_adj_hzn2 <- geom_mean_ratios_hzn2/geom_mean_ratios_hzn2["COVIDhub-baseline"]
ratios_baseline_adj_hzn3 <- geom_mean_ratios_hzn3/geom_mean_ratios_hzn3["COVIDhub-baseline"]
ratios_baseline_adj_hzn4 <- geom_mean_ratios_hzn4/geom_mean_ratios_hzn4["COVIDhub-baseline"]
tab <- data.frame(model = c(names(geom_mean_ratios_hzn1),
names(geom_mean_ratios_hzn2),
names(geom_mean_ratios_hzn3),
names(geom_mean_ratios_hzn4)),
horizon = rep(1:4, each=length(geom_mean_ratios_hzn1)),
geom_mean_ratios = c(geom_mean_ratios_hzn1,
geom_mean_ratios_hzn2,
geom_mean_ratios_hzn3,
geom_mean_ratios_hzn4),
ratios_baseline_raw = c(ratios_baseline_raw_hzn1,
ratios_baseline_raw_hzn2,
ratios_baseline_raw_hzn3,
ratios_baseline_raw_hzn4),
ratios_baseline_adj = c(ratios_baseline_adj_hzn1,
ratios_baseline_adj_hzn2,
ratios_baseline_adj_hzn3,
ratios_baseline_adj_hzn4)
)
tab <- tab[order(tab$horizon,tab$ratios_baseline_adj), ]
historical_mae <- tab %>%
mutate(relative_mae = round(ratios_baseline_adj, 2)) %>%
select(model, horizon, relative_mae) %>%
pivot_wider(names_from = "horizon",values_from = "relative_mae") %>%
rename("1 wk relMAE" = "1", "2 wk relMAE" = "2", "3 wk relMAE" = "3", "4 wk relMAE" = "4" ) %>%
dplyr::rowwise() %>%
dplyr::mutate(relative_mae = mean(c_across(where(is.numeric)), na.rm = T)) %>%
dplyr::ungroup() %>%
arrange(relative_mae)
```
```{r counts of forecasts by model and create leaderboards for DEATHS accuracy}
inc_count_fcasts_recent <- inc_accuracy_recent %>% group_by(model,score_name) %>%
summarise(n_forecasts_wis = sum(score_name == "wis" & !is.na(score_value)),
n_forecasts_mae = sum(score_name == "abs_error" & !is.na(score_value))) %>% ungroup() %>%
mutate(n_fcast = ifelse(n_forecasts_wis > 0, n_forecasts_wis, n_forecasts_mae)) %>%
group_by(model) %>%
summarise("# recent forecasts" = max(n_fcast))
inc_count_fcasts_historical <- inc_accuracy_historical %>% group_by(model,score_name) %>%
summarise(n_forecasts_wis = sum(score_name == "wis" & !is.na(score_value)),
n_forecasts_mae = sum(score_name == "abs_error" & !is.na(score_value))) %>% ungroup() %>%
mutate(n_fcast = ifelse(n_forecasts_wis > 0, n_forecasts_wis, n_forecasts_mae)) %>%
group_by(model) %>%
summarise("# historical forecasts" = max(n_fcast)) %>%
ungroup()
leaderboard_table <- inc_count_fcasts_recent %>%
full_join(pairwise_scores) %>%
full_join(pairwise_scores_mae) %>%
filter(!is.na(relative_mae) | !is.na(relative_wis)) %>%
arrange(relative_wis)
leaderboard_table_historical <- inc_count_fcasts_historical %>%
full_join(historical_wis, by = c("model")) %>%
full_join(historical_mae, by = c("model")) %>%
filter(!is.na(relative_mae) | !is.na(relative_wis)) %>%
arrange(relative_wis)
render <- JS(
"function(data, type, row) {",
" if(type === 'sort' && data === null) {",
" return 999999;",
" }",
" return data;",
"}"
)
```
```{r}
inc_model_order <- leaderboard_table %>% arrange(relative_wis) %>% pull(model)
inc_model_order_historical <- leaderboard_table_historical %>% arrange(relative_wis) %>% pull(model)
```
### Recent accuracy
```{r recent Leaderboard DEATHS accuracy}
# a custom table container
sketch_recent_accuracy = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, "Model"),
th(rowspan = 2, "# recent forecasts"),
th(colspan = 4, "Relative WIS"),
th(colspan = 4, "Relative MAE")
),
tr(
lapply((c("1 wk","2 wk","3 wk","4 wk","1 wk","2 wk","3 wk","4 wk")), th)))))
leaderboard_table1<- leaderboard_table %>%
arrange(relative_wis) %>%
select (model, "# recent forecasts", "1 wk relWIS", "2 wk relWIS","3 wk relWIS","4 wk relWIS","1 wk relMAE","2 wk relMAE","3 wk relMAE","4 wk relMAE")
datatable(leaderboard_table1,
rownames= FALSE,
options = list(pageLength = 5,
# order = case_model_order,
autoWidth = TRUE,
columnDefs = list(list(width = '100px', targets = "_all", render = render)),
ordering = TRUE),
# filter = c("top")
colnames = c("Model", "# recent forecasts", "1 wk relWIS", "2 wk relWIS","3 wk relWIS","4 wk relWIS","1 wk relMAE","2 wk relMAE","3 wk relMAE","4 wk relMAE"), container=sketch_recent_accuracy)
filter = c("top")
```
To calculate each column in our table, different inclusion criteria were applied. This table only includes forecasts for the last `r n_weeks_eval` weeks, since `r format(first_eval_sat, "%B %d, %Y")`.The models included have submitted at least 50% of forecasts during this time, where one forecast is a location, target, forecast date combination. The data are initially ordered by model based on their relative WIS score aggregated across horizons, with the most accurate models at the top.
* The column titled, "# recent forecasts" lists the number of forecasts a team has submitted with a target end date over the most recent `r n_weeks_eval` week period.
* Columns 3 through 6 calculate the adjusted relative WIS over the most recent `r n_weeks_eval` week period by horizon.
* Columns 7 through 10 calculate the adjusted relative MAE over the most recent `r n_weeks_eval` week period by horizon.
### Historical accuracy
```{r historical Leaderboard DEATHS accuracy}
# a custom table container
sketch_historical_accuracy = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, "Model"),
th(rowspan = 2, "# historical forecasts"),
th(colspan = 4, "Relative WIS"),
th(colspan = 4, "Relative MAE")
),
tr(
lapply((c("1 wk","2 wk","3 wk","4 wk","1 wk","2 wk","3 wk","4 wk")), th)))))
leaderboard_table_historical1<- leaderboard_table_historical %>%
arrange(relative_wis) %>%
select (model, "# historical forecasts", "1 wk relWIS", "2 wk relWIS","3 wk relWIS","4 wk relWIS","1 wk relMAE","2 wk relMAE","3 wk relMAE","4 wk relMAE")
datatable(leaderboard_table_historical1,
rownames= FALSE,
options = list(pageLength = 5,
# order = case_model_order_historical,
autoWidth = TRUE,
columnDefs = list(list(width = '100px', targets = "_all", render = render)),
ordering = TRUE),
# filter = c("top")
colnames = c("Model", "# historical forecasts", "1 wk relWIS", "2 wk relWIS","3 wk relWIS","4 wk relWIS","1 wk relMAE","2 wk relMAE","3 wk relMAE","4 wk relMAE"), container=sketch_historical_accuracy)
filter = c("top")
```
To calculate each column in our table, different inclusion criteria were applied. This table only includes forecasts for the last `r n_weeks_history` weeks, since `r format(first_eval_sat_hist, "%B %d, %Y")`. The models included have submitted at least 50% of forecasts during this time, where one forecast is a location, target, forecast date combination. The data are initially ordered based on their relative WIS score aggregated across horizons.
* The column titled, "# historical forecasts" lists the number of forecasts a team has submitted with a target end date over the most recent `r n_weeks_history` week period.
* Columns 3 through 6 calculate the adjusted relative WIS over the most recent `r n_weeks_history` week period by horizon.
* Columns 7 through 10 calculate the adjusted relative MAE over the most recent `r n_weeks_history` week period by horizon.
```{r increase mempry limit to 30000, results='hide'}
memory.limit(30000)
```
```{r inclusion in coverage table recent: DEATHS}
# RECENT
# at least 50% of recent coverage
inc_coverage_recent <- recent_coverage_filter(score_inc_all_ohio,first_eval_sat)
inc_scores <- inc_coverage_recent %>%
filter(!is.na(score_value)) %>%
filter(n_locations >= 25) %>%
filter(n_weeks >= 4) %>%
droplevels()
# bring all timezeros to Saturday:
inc_scores$timezero <- inc_scores$submission_sat
# restrict to 1-4 wk ahead state-level
scores <- inc_scores %>% filter(horizon %in% paste(1:4), location %in% US_fips) %>%
filter(score_name %in% c("coverage_50", "coverage_95")) %>%
select("model", "timezero", "location", "horizon", "score_name", "score_value") %>%
pivot_wider(names_from = score_name, values_from = score_value) %>%
droplevels()
# the included models:
models <- unique(scores$model)
#number of forecasts by model
inc_countc_fcasts_recent <- inc_coverage_recent %>% group_by(model,score_name) %>%
summarise(n_forecasts_50 = sum(score_name == "coverage_50" & !is.na(score_value)),
n_forecasts_95 = sum(score_name == "coverage_95" & !is.na(score_value))) %>% ungroup() %>%
mutate(n_fcast = ifelse(n_forecasts_50 > 0, n_forecasts_50, n_forecasts_95)) %>%
group_by(model) %>%
summarise("# recent forecasts" = max(n_fcast))
recent_calib_50 <- score_inc_all_ohio %>%
filter(model %in% models) %>%
filter(!is.na(score_value)) %>%
filter(score_name %in% c("coverage_50")) %>%
filter(target_end_date >= first_eval_sat) %>% droplevels() %>%
select(model,horizon,score_value) %>%
group_by(model,horizon) %>%
summarise(mean_PI50 = round(sum(score_value, na.rm = TRUE) / n(),2)) %>%
ungroup() %>%
pivot_wider(names_from = "horizon",values_from = "mean_PI50") %>%
rename("1 wk 50% coverage" = "1", "2 wk 50% coverage" = "2", "3 wk 50% coverage" = "3", "4 wk 50% coverage" = "4" ) %>%
dplyr::rowwise() %>%
dplyr::mutate(coverage_50 = mean(c_across(where(is.numeric)), na.rm = T)) %>%
dplyr::ungroup()
recent_calib_95 <- score_inc_all_ohio %>%
filter(model %in% models) %>%
filter(!is.na(score_value)) %>%
filter(score_name %in% c("coverage_95")) %>%
filter(target_end_date >= first_eval_sat) %>% droplevels() %>%
select(model,horizon,score_value) %>%
group_by(model,horizon) %>%
summarise(mean_PI95 = round(sum(score_value, na.rm = TRUE) / n(),2)) %>%
ungroup() %>%
pivot_wider(names_from = "horizon",values_from = "mean_PI95") %>%
rename("1 wk 95% coverage" = "1", "2 wk 95% coverage" = "2", "3 wk 95% coverage" = "3", "4 wk 95% coverage" = "4" ) %>%
dplyr::rowwise() %>%
dplyr::mutate(coverage_95 = mean(c_across(where(is.numeric)), na.rm = T)) %>%
dplyr::mutate(diff_95 = abs(0.95-coverage_95)) %>%
dplyr::ungroup()
# HISTORICAL
# at least 50% of historical coverage
inc_coverage_historical <- historical_coverage_filter(score_inc_all_ohio)
inc_scores_historical <- inc_coverage_historical %>%
filter(!is.na(score_value)) %>%
filter(n_locations >= 25) %>%
filter(n_weeks >= 4) %>%
droplevels()
# bring all timezeros to Saturday:
inc_scores_historical$timezero <- inc_scores_historical$submission_sat
# restrict to 1-4 wk ahead state-level
scores_historical <- inc_scores_historical %>% filter(horizon %in% paste(1:4), location %in% US_fips) %>%
filter(score_name %in% c("coverage_50", "coverage_95")) %>%
select("model", "timezero", "location", "horizon", "score_name", "score_value") %>%
pivot_wider(names_from = score_name, values_from = score_value) %>%
droplevels()
# the included models:
models_historical <- unique(scores_historical$model)
#number of forecasts by model
inc_countc_fcasts_historical <- inc_coverage_historical %>% group_by(model,score_name) %>%
summarise(n_forecasts_50 = sum(score_name == "coverage_50" & !is.na(score_value)),
n_forecasts_95 = sum(score_name == "coverage_95" & !is.na(score_value))) %>% ungroup() %>%
mutate(n_fcast = ifelse(n_forecasts_50 > 0, n_forecasts_50, n_forecasts_95)) %>%
group_by(model) %>%
summarise("# historical forecasts" = max(n_fcast))
historical_calib_50 <- score_inc_all_ohio %>%
filter(model %in% models_historical) %>%
filter(!is.na(score_value)) %>%
filter(score_name %in% c("coverage_50")) %>%
select(model,horizon,score_value,n_weeks) %>%
group_by(model,horizon) %>%
summarise(mean_PI50 = round(sum(score_value, na.rm = TRUE) / n(),2)) %>%
ungroup() %>%
pivot_wider(names_from = "horizon",values_from = "mean_PI50") %>%
rename("1 wk 50% coverage" = "1", "2 wk 50% coverage" = "2", "3 wk 50% coverage" = "3", "4 wk 50% coverage" = "4" ) %>%
dplyr::rowwise() %>%
dplyr::mutate(coverage_50 = mean(c_across(where(is.numeric)), na.rm = T)) %>%
dplyr::ungroup()
historical_calib_95 <- score_inc_all_ohio %>%
filter(model %in% models_historical) %>%
filter(!is.na(score_value)) %>%
filter(score_name %in% c("coverage_95")) %>%
select(model,horizon,score_value) %>%
group_by(model,horizon) %>%
summarise(mean_PI95 = round(sum(score_value, na.rm = TRUE) / n(),2)) %>%
ungroup() %>%
pivot_wider(names_from = "horizon",values_from = "mean_PI95") %>%
rename("1 wk 95% coverage" = "1", "2 wk 95% coverage" = "2", "3 wk 95% coverage" = "3", "4 wk 95% coverage" = "4" ) %>%
dplyr::rowwise() %>%
dplyr::mutate(coverage_95 = mean(c_across(where(is.numeric)), na.rm = T)) %>%
dplyr::mutate(diff_95 = abs(0.95-coverage_95)) %>%
dplyr::ungroup()
calibration_table <- inc_countc_fcasts_recent %>%
full_join(recent_calib_50) %>%
full_join(recent_calib_95) %>%
filter(!is.na(coverage_95) | !is.na(coverage_50)) %>%
arrange(diff_95)
calibration_table_hist <- inc_countc_fcasts_historical %>%
full_join(historical_calib_50) %>%
full_join(historical_calib_95) %>%
filter(!is.na("# historical forecasts")) %>%
filter(!is.na("1 wk 50% coverage") | !is.na("1 wk 95% coverage")) %>%
filter(!is.na(coverage_95) | !is.na(coverage_50)) %>%
arrange(diff_95)
render <- JS(
"function(data, type, row) {",
" if(type === 'sort' && data === null) {",
" return 999999;",
" }",
" return data;",
"}"
)
```
```{r}
calib_model_order <- calibration_table %>% arrange(diff_95) %>% pull(model)
calib_model_order_historical <- calibration_table_hist %>% arrange(diff_95) %>% pull(model)
```
### Recent coverage
This table only includes forecasts for the last `r n_weeks_eval` weeks, since `r format(first_eval_sat, "%B %d, %Y")`. For inclusion in this table, the models must have submitted at least 50% of forecasts during this time, where one forecast is a location, target, forecast date combination. The data are initially ordered by model based on their 95% PI coverage, with the most accurate models aggregated across horizons at the top.
```{r recent Leaderboard DEATHS coverage}
# a custom table container
sketch_recent_coverage = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, "Model"),
th(rowspan = 2, "# recent forecasts"),
th(colspan = 4, "50% PI coverage"),
th(colspan = 4, "95% PI coverage")
),
tr(
lapply((c("1 wk","2 wk","3 wk","4 wk","1 wk","2 wk","3 wk","4 wk")), th)))))
calibration_table1<- calibration_table %>%
arrange(diff_95)%>%
select (model, "# recent forecasts", "1 wk 50% coverage", "2 wk 50% coverage", "3 wk 50% coverage", "4 wk 50% coverage","1 wk 95% coverage", "2 wk 95% coverage", "3 wk 95% coverage", "4 wk 95% coverage")
datatable(calibration_table1,
rownames= FALSE,
options = list(pageLength = 5,
# order = list(list(2, 'asc')),
autoWidth = TRUE,
columnDefs = list(list(width = '100px', targets = "_all", render = render)),
ordering = TRUE),
# filter = c("top")
colnames = c("Model", "# recent forecasts", "1 wk 50% coverage", "2 wk 50% coverage", "3 wk 50% coverage", "4 wk 50% coverage","1 wk 95% coverage", "2 wk 95% coverage", "3 wk 95% coverage", "4 wk 95% coverage"), container=sketch_recent_coverage)
```
### Historical coverage
This table only includes forecasts for the last `r n_weeks_history` weeks, since `r format(first_eval_sat_hist, "%B %d, %Y")`. For inclusion in this table, the models must have submitted at least 50% of forecasts during this time, where one forecast is a location, target, forecast date combination. The data are initially ordered by model based on their 95% PI coverage, with the most accurate models aggregated across horizons at the top.
```{r historical Leaderboard DEATHS coverage}
# a custom table container
sketch_historical_coverage = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, "Model"),
th(rowspan = 2, "# historical forecasts"),
th(colspan = 4, "50% PI coverage"),
th(colspan = 4, "95% PI coverage")
),
tr(
lapply((c("1 wk","2 wk","3 wk","4 wk","1 wk","2 wk","3 wk","4 wk")), th)))))
calibration_table_hist1<- calibration_table_hist %>%
arrange(diff_95) %>%
select (model, "# historical forecasts", "1 wk 50% coverage", "2 wk 50% coverage", "3 wk 50% coverage", "4 wk 50% coverage","1 wk 95% coverage", "2 wk 95% coverage", "3 wk 95% coverage", "4 wk 95% coverage")
datatable(calibration_table_hist1,
rownames= FALSE,
options = list(pageLength = 5,
# order = list(list(2, 'asc')),
autoWidth = TRUE,
columnDefs = list(list(width = '100px', targets = "_all", render = render)),
ordering = TRUE),
# filter = c("top")
colnames = c("Model", "# historical forecasts", "1 wk 50% coverage", "2 wk 50% coverage", "3 wk 50% coverage", "4 wk 50% coverage","1 wk 95% coverage", "2 wk 95% coverage", "3 wk 95% coverage", "4 wk 95% coverage"), container=sketch_historical_coverage)
```
## WIS components
The data in this graph has been aggregated over all locations and submission weeks. We only included forecasts for the last 10 weeks. The models included have submitted at least 50% of forecasts during this time, where one forecast is a location, target, forecast date combination. This is the same exclusion criteria applied for WIS scores in the recent evaluation period.
The sum of the bars adds up to the WIS score. Of note, these values may not be exactly the same as the relative WIS scores shown in the leaderboard table because these are not adjusted for weeks or locations missing. The data are ordered on the x axis based on their relative WIS score shown in the accuracy table, aggregated across horizons. The y axis is truncated at 95th percentile of the sum of the bars across models, rounded up to the nearest 10.
```{r wis bar function DEATHS, fig.height=8, fig.width=13}
wis_barplot_function(score_inc_all_ohio, y = pairwise_scores, order = inc_model_order)
```
## Evaluation by Week {.tabset .tabset-fade}
In the following figures, we have evaluated models across multiple forecasting weeks. Points included in this comparison are for models that have submitted probabilistic forecasts for all 50 states. The models in the legend with a dot and line have scores for every week. The models with just a line are missing scores for at least one week.
For the first 2 figures, WIS is used as a metric, WIS is used as a metric, with the y axis truncated at the 97.5 percentile of the average WIS, with the y axis truncated at the 97.5 percentile of the average WIS. The first figure shows the mean WIS across all 50 states for submission weeks beginning `r format(first_eval_sat_hist, "%B %d, %Y")` at a 1 week horizon. The second figure shows the mean WIS aggregated across locations, however it is for a 4 week horizon.
### 1 Week Horizon WIS
```{r,fig.width=10, fig.height=6}
byweek_inc <- by_week_function(score_inc_all_ohio, var = "wis",loc=US_fips, nloc=50)
#expand all points
all_dates <- byweek_inc %>%
ungroup %>%
expand(model, horizon, target_end_date)
miss_dates <- all_dates %>%
dplyr::anti_join(byweek_inc)
byweek_inc1<- byweek_inc %>%
dplyr::full_join(miss_dates)
# find 97.5 percentile
b_inc<-byweek_inc1 %>%
filter(horizon == "4")
p975_inc<-quantile(b_inc$mean_score,probs=.975, na.rm = TRUE)
by_week_wis_1wk <- plot_byweek_function(byweek_inc1, var = "WIS", horizon_num = "1") +
geom_hline(yintercept = .95)+ coord_cartesian(ylim=c(0, p975_inc))
ggplotly(by_week_wis_1wk, tooltip = c("label", "labelx", "labely"))
```
### 4 Week Horizon WIS
In this figure, the dotted black line represents the average 1 week ahead error across all models. There is often larger error for the 4 week horizon compared to the 1 week horizon.
```{r,fig.width=10, fig.height=6}
#calc 1 week error
meanwis_1wk <- byweek_inc1 %>%
filter(horizon == "1") %>%
group_by(target_end_date) %>%
summarise(mean_score = mean(mean_score, na.rm = TRUE)) %>%
mutate(model = "`average wis or 1 week horizon`",
horizon = "4") %>%
select(model, horizon, target_end_date, mean_score)
by_week_wis_4wk <- plot_byweek_function(byweek_inc1, var = "wis", horizon_num = "4") +
geom_line(data = meanwis_1wk, aes(x = target_end_date, y = mean_score), alpha=.5, color = "black", linetype = 2) +
geom_point(data = meanwis_1wk, aes(x = target_end_date, y = mean_score), alpha=.5, size = 2, color = "black") + coord_cartesian(ylim=c(0, p975_inc))
ggplotly(by_week_wis_4wk,tooltip = c("label", "labelx", "labely"))
```