-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathS1_Text.Rmd
1315 lines (918 loc) · 32.1 KB
/
S1_Text.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: "S1 Appendix"
output:
pdf_document:
number_sections: true
header-includes:
- \usepackage{booktabs}
---
A critical requirement for parameter inference on State-Space Models is the
robustness of likelihood estimates. Namely, different runs ought to yield
similar log-likelihood values from a single set of parameters (model
configuration). Consequently, in this appendix, we formulate and assess the
convergence of six measurement model candidates that account for the observed
incidence. Some models account for the relative contact rate, assuming mobility
data as a proxy observation. We couple those candidate measurements models with
two process models. The first process model (PM1) describes the relative contact
rate of the SEI3R within-host profile in terms of Geometric Brownian Motion. The
other process model (PM2) employs the Cox-Ingersoll-Ross formulation to describe
the relative contact rate. Specifically, we perform a sensitivity analysis on
the accuracy of the likelihood estimates under various particle and integration
step sizes for each chosen model configuration. Overall, the results allow us to
identify possible model misspecifications and to select an appropriate
integration step and sample size in a context of finite computational resources.
\tableofcontents
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(doParallel)
library(doRNG)
library(dplyr)
library(extraDistr)
library(kableExtra)
library(imputeTS)
library(lubridate)
library(pomp)
library(purrr)
library(readr)
library(readxl)
library(tidyr)
library(stringr)
library(tictoc)
source("./R_scripts/data.R")
source("./R_scripts/helpers.R")
source("./R_scripts/likelihood_funs.R")
source("./R_scripts/POMP_models.R")
source("./R_scripts/plots.R")
denoms <- 2 ** (2:7)
dts <- 1 / denoms
```
\newpage
# Data
In this work, we base the inference process on two datasets. The first dataset
corresponds to the number of COVID-19 cases detected during Ireland's first
wave, from 29 February 2020 to 17 May 2020. We refer to this dataset as $y^1$
and distinguish between two aggregation levels: daily ($y^1_d$) and weekly
($y^1_w$). The second dataset ($y^2$) is Apple's driving mobility index which
quantifies the number of requests made to Apple Maps for directions. These
indexes are normalised to the value on 28 February 2020. Furthermore, given that
data for May 11-12 is missing, we approximate such values using linear
interpolation. In a similar manner to incidence data, we employ two subsets of
datasets. Accordingly, $y^2_d$ denotes daily measurements, and $y^2_w$ denotes
the measurement of the end of the week.
\hfill
```{r}
data_list <- get_data()
```
```{r}
daily_incidence <- get_irish_data() |> slice(1:79)
wkl_incidence <- get_wkl_incidence(daily_incidence)
g1 <- daily_epi_trend(daily_incidence, "A) Daily detected cases")
g2 <- weekly_epicurve(wkl_incidence, "B) Weekly detected cases")
dates <- seq(ymd('2020-02-29'), ymd("2020-05-17"), by = '1 day')
drv_data_obj <- get_driving_data()
imp <- drv_data_obj$imputed_data
daily_mob_df <- data.frame(date = dates, y = imp)
g3 <- plot_daily_mobility(daily_mob_df)
g4 <- plot_wkl_mobility(daily_mob_df)
save_plot <- (g1 | g2) / (g3 | g4)
dvc <- "pdf"
fig_path <- str_glue("./paper_plots/Fig_02_Data.{dvc}")
ggsave(fig_path, plot = save_plot, height = 5, width = 5)
dvc <- "eps"
fig_path <- str_glue("./paper_plots/Fig_02_Data.{dvc}")
ggsave(filename = fig_path, plot = save_plot, device = cairo_ps, height = 5,
width = 5)
save_plot
```
\newpage
# Geometric Brownian Motion (DGP1)
## Process model (PM1)
\hfill
\begin{equation}
\frac{dS}{dt} = - S_t \lambda_t
\end{equation}
\begin{equation}
\frac{dE}{dt} = S_t \lambda_t - \sigma E_t
\end{equation}
\begin{equation}
\frac{dP}{dt} = \omega \sigma E_t - \eta P_t
\end{equation}
\begin{equation}
\frac{dI}{dt} = \eta P_t - \gamma I_t
\end{equation}
\begin{equation}
\frac{dA}{dt} = (1-\omega) \sigma E_t - \kappa A_t
\end{equation}
\begin{equation}
\frac{dR}{dt} = \kappa A_t + \gamma I_t
\end{equation}
\begin{equation}
\lambda_t = \frac{ \beta_t(I_t + P_t + \mu A_t)}{N_t}
\end{equation}
\begin{equation}
\beta_t = \zeta Z_t
\end{equation}
\begin{equation}
\color{red}
\frac{dZ}{dt} = \alpha Z_t dW
\end{equation}
\begin{equation}
dW \sim Normal(0, \sqrt{dt})
\end{equation}
## Testing measurement model candidates
### Testing points
We use five point estimates (table below) as probes to assess the reliability of
likelihood estimates. These point estimates correspond to _plausible_ values
obtained in a earlier version of this inference analysis. For the final version,
we assume such values as **given**, and conduct the analysis from the start.
Considering that these tests are not intended to be exhaustive but rather of
exploratory nature, any arbitrary point is valid as a probe.
\hfill
```{r}
path <- "./Saved_objects/SEI3R_GBM/top_10.csv"
test_pars <- read_csv(path)
set.seed(123)
phi_guesses <- round(rhnorm(10, 0.3), 3)
test_pars$phi <- phi_guesses
pars_list <- transpose(test_pars)
kable_df <- test_pars
old_names <- colnames(kable_df)
new_names <- ifelse(old_names == "P_0",
paste0("$",old_names , "$"),
paste0("$\\",old_names , "$"))
colnames(kable_df) <- new_names
kable_df <- kable_df |> mutate(id = row_number(), .before = everything()) |>
slice(1:5)
knitr::kable(kable_df, "latex", booktabs = TRUE,
escape = FALSE, digits = 3)
```
### Summary
Specifically, we formulate six measurement model candidates. We describe
these models using three features:
\hfill
* Whether we fit the model to **daily** or **weekly** data.
* Whether we model incidence measurements using the **Poisson** or the
**Negative binomial** distribution.
* Whether the model incorporates the mobility data as a proxy measurement for
the relative effective contact rate. We assume these measurements are normally
distributed.
\hfill
For each probe (point estimate) and model candidate, we run the particle filter
16 times. We repeat the process for various particle and integration step sizes.
For each batch of 16 runs, we estimate the log-likelihood mean, the
log-likelihood standard error, and the computational time.
In a nutshell, the results indicate that when one models daily incidence
measurements with the Poisson distribution, the particle filter does not
converge as the number of particles increases. This finding suggests model
misspecification under such an assumption.
Furthermore, the accuracy of log-likelihood estimates is not compromised by
relative large integration steps (e.g., $\frac{1}{8}$), which diminishes the
burden on computational resources. On the contrary, and as expected in Monte
Carlo simulation, the accuracy relies on the number of samples (particles).
\hfill
```{r}
models_df <- data.frame(
model_id = 1:6,
Frequency = c("Daily", "Daily", "Daily", "Daily", "Weekly", "Weekly"),
Incidence_model = c("Pois", "Nbin", "Pois", "Nbin", "Pois", "Pois"),
Mobility_model = c(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE),
Converges = c("No", "Yes", "No", "Yes", "Yes", "Yes"))
kable_df <- models_df
colnames(kable_df) <- c("Id", "Frequency", "Incidence", "Mobility", "Converges")
knitr::kable(kable_df, "latex", booktabs = TRUE,
escape = FALSE, digits = 3)
```
### Candidate 1
This formulation assumes that daily incidence measurements are distributed
according to the Poisson distribution. Also, this structure does not
incorporate mobility data.
#### Equations
\hfill
\begin{equation}
\frac{dC}{dt} = \eta P_t - C_t \delta(t \, mod \, 1)
\end{equation}
\begin{equation}
y^1_d \sim Pois(C_t)
\end{equation}
\newpage
#### Convergence test
\hfill
\hfill
This test shows that the likelihood standard error **does NOT** tend to zero as
the number of particles increases. As a consequence, we cannot proceed with the
next step in the inference process. That is, using the Iterated Filtering
algorithm for parameter inference inasmuch as this plug-and-play method relies
on robust likelihood estimates. Moreover, this result is also a signal of model misspecification.
\hfill
```{r GBM_1}
model_id <- 1
folder <- str_glue("./Saved_objects/SEI3R_GBM/mdl_{model_id}")
tested_model <- models_df[model_id, ]
freq <- tested_model |> pull(Frequency)
inc_mdl <- tested_model |> pull(Incidence_model)
mob_mdl <- tested_model |> pull(Mobility_model)
obs_df <- data_list[[freq]]
mdl_filename <- str_glue("GBM_{model_id}")
seeds <- c(157050396, 429423692, 339568946, 311085801, 553095796)
map_df(1:5, function(i) {
pars_set <- pars_list[[i]]
map_dfr(dts, function(dt) {
pomp_obj <- pomp_GBM(inc_mdl, mob_mdl, obs_df, mdl_filename, dt)
par_obj <- pomp_obj$pars
pomp_mdl <- pomp_obj$mdl
n_particles <- c(5e3, 1e4, 2e4, 5e4, 1e5)
fn <- file.path(folder, str_glue("pf_sensitivity_{i}_dt_{dt}.rds"))
pars <- c(unlist(pars_set), par_obj$fixed)
pomp_mdl <- pomp_mdl |> pomp(params = pars)
pf_sensitivity(n_particles = n_particles, n_cores = detectCores(),
seed = seeds[[i]], pomp_mdl = pomp_mdl, fn = fn,
n_iter = detectCores() * 2) |>
mutate(inv_dt = 1/dt)
}) |> mutate(id = i)
}) -> sens_df
```
```{r, fig.height = 7}
plot_ll_se(sens_df, GBM_colour)
```
\newpage
### Candidate 2
This formulation assumes that daily incidence measurements are distributed
according to the Negative binomial distribution. Also, this structure does not
incorporate mobility data.
#### Equations
\hfill
\hfill
\begin{equation}
\frac{dC}{dt} = \eta P_t - C_t \delta(t \, mod \, 1)
\end{equation}
\begin{equation}
y^1_d \sim Nbin(C_t, \phi^{-1})
\end{equation}
#### Time comparison
\hfill
As we will see below, these likelihood estimates converge. For this and other
models that exhibit convergence, we present a plot comparing computational time
elapsed in order to obtain likelihood estimates for testing point # 1. We do so
for several scenarios. Here, scenarios refer to the number of particles and the
integration step size.
\hfill
```{r}
plot_ll_time(sens_df |> filter(id == 1), GBM_colour)
```
\newpage
#### Convergence test
\hfill
In this plot, we observe that the likelihood standard error approximates zero as
the number of particles increases.
\hfill
```{r GBM_2}
model_id <- 2
folder <- str_glue("./Saved_objects/SEI3R_GBM/mdl_{model_id}")
tested_model <- models_df[model_id, ]
freq <- tested_model |> pull(Frequency)
inc_mdl <- tested_model |> pull(Incidence_model)
mob_mdl <- tested_model |> pull(Mobility_model)
obs_df <- data_list[[freq]]
mdl_filename <- str_glue("GBM_{model_id}")
seeds <- c(406058540, 384577220, 450611898, 158637695, 445355553)
map_df(1:5, function(i) {
pars_set <- pars_list[[i]]
map_dfr(dts, function(dt) {
pomp_obj <- pomp_GBM(inc_mdl, mob_mdl, obs_df, mdl_filename, dt)
par_obj <- pomp_obj$pars
pomp_mdl <- pomp_obj$mdl
n_particles <- c(5e3, 1e4, 2e4, 5e4, 1e5)
fn <- file.path(folder, str_glue("pf_sensitivity_{i}_dt_{dt}.rds"))
pars <- c(unlist(pars_set), par_obj$fixed)
pomp_mdl <- pomp_mdl |> pomp(params = pars)
pf_sensitivity(n_particles = n_particles, n_cores = detectCores(),
seed = seeds[[i]], pomp_mdl = pomp_mdl, fn = fn,
n_iter = detectCores() * 2) |>
mutate(inv_dt = 1/dt)
}) |> mutate(id = i)
}) -> sens_df
```
```{r, fig.height = 7}
plot_ll_se(sens_df, GBM_colour)
```
\newpage
### Candidate 3
This formulation assumes that daily incidence measurements are distributed
according to the Poisson distribution. Also, this structure **incorporates**
mobility data.
#### Equations
\hfill
\hfill
\begin{equation}
\frac{dC}{dt} = \eta P_t - C_t \delta(t \, mod \, 1)
\end{equation}
\begin{equation}
y^1_d \sim Pois(C_t)
\end{equation}
\begin{equation}
y^2_d \sim Normal(Z_t, \tau)
\end{equation}
\newpage
#### Convergence test
\hfill
Mobility data does not redress convergence issues in the assumption that daily
incidence measurements are distributed according to the Poisson distribution.
\hfill
```{r GBM_3}
model_id <- 3
folder <- str_glue("./Saved_objects/SEI3R_GBM/mdl_{model_id}")
tested_model <- models_df[model_id, ]
freq <- tested_model |> pull(Frequency)
inc_mdl <- tested_model |> pull(Incidence_model)
mob_mdl <- tested_model |> pull(Mobility_model)
obs_df <- data_list[[freq]]
mdl_filename <- str_glue("GBM_{model_id}")
seeds <- c(749210329, 633239544, 506479957, 675552576, 33000524)
map_df(1:5, function(i) {
pars_set <- pars_list[[i]]
map_dfr(dts, function(dt) {
pomp_obj <- pomp_GBM(inc_mdl, mob_mdl, obs_df, mdl_filename, dt)
par_obj <- pomp_obj$pars
pomp_mdl <- pomp_obj$mdl
n_particles <- c(5e3, 1e4, 2e4, 5e4, 1e5)
fn <- file.path(folder, str_glue("pf_sensitivity_{i}_dt_{dt}.rds"))
pars <- c(unlist(pars_set), par_obj$fixed)
pomp_mdl <- pomp_mdl |> pomp(params = pars)
pf_sensitivity(n_particles = n_particles, n_cores = detectCores(),
seed = seeds[[i]], pomp_mdl = pomp_mdl, fn = fn,
n_iter = detectCores() * 2) |>
mutate(inv_dt = 1/dt)
}) |> mutate(id = i)
}) -> sens_df
```
```{r, fig.height = 7}
plot_ll_se(sens_df, GBM_colour)
```
\newpage
### Candidate 4
This formulation assumes that daily incidence measurements are distributed
according to the Negative Binomial distribution. Also, this structure
**incorporates** mobility data.
#### Equations
\hfill
\hfill
\begin{equation}
\frac{dC}{dt} = \eta P_t - C_t \delta(t \, mod \, 1)
\end{equation}
\begin{equation}
y^1_d \sim Nbin(C_t, \phi^{-1})
\end{equation}
\begin{equation}
y^2_d \sim Normal(Z_t, \tau)
\end{equation}
#### Time comparison
\hfill
\hfill
```{r}
plot_ll_time(sens_df |> filter(id == 1), GBM_colour)
```
\newpage
#### Convergence test
\hfill
\hfill
```{r GBM_4}
model_id <- 4
folder <- str_glue("./Saved_objects/SEI3R_GBM/mdl_{model_id}")
tested_model <- models_df[model_id, ]
freq <- tested_model |> pull(Frequency)
inc_mdl <- tested_model |> pull(Incidence_model)
mob_mdl <- tested_model |> pull(Mobility_model)
obs_df <- data_list[[freq]]
mdl_filename <- str_glue("GBM_{model_id}")
seeds <- c(844589231, 935794189, 132397586, 602352313, 252313981)
map_df(1:5, function(i) {
pars_set <- pars_list[[i]]
map_dfr(dts, function(dt) {
pomp_obj <- pomp_GBM(inc_mdl, mob_mdl, obs_df, mdl_filename, dt)
par_obj <- pomp_obj$pars
pomp_mdl <- pomp_obj$mdl
n_particles <- c(5e3, 1e4, 2e4, 5e4, 1e5)
fn <- file.path(folder, str_glue("pf_sensitivity_{i}_dt_{dt}.rds"))
pars <- c(unlist(pars_set), par_obj$fixed)
pomp_mdl <- pomp_mdl |> pomp(params = pars)
pf_sensitivity(n_particles = n_particles, n_cores = detectCores(),
seed = seeds[[i]], pomp_mdl = pomp_mdl, fn = fn,
n_iter = detectCores() * 2) |>
mutate(inv_dt = 1/dt)
}) |> mutate(id = i)
}) -> sens_df
```
```{r, fig.height = 7}
plot_ll_se(sens_df, GBM_colour)
```
\newpage
### Candidate 5
This formulation assumes that **weekly** incidence measurements are distributed
according to the Poisson distribution. Also, this structure **does not**
incorporate mobility data.
#### Equations
\hfill
\begin{equation}
\frac{dC}{dt} = \eta P_t - C_t \delta(t \, mod \, 7)
\end{equation}
\begin{equation}
y^1_w \sim Pois(C_t)
\end{equation}
#### Time comparison
\hfill
\hfill
```{r}
plot_ll_time(sens_df |> filter(id == 1), GBM_colour)
```
\newpage
#### Convergence test
\hfill
\hfill
```{r GBM_5}
model_id <- 5
folder <- str_glue("./Saved_objects/SEI3R_GBM/mdl_{model_id}")
tested_model <- models_df[model_id, ]
freq <- tested_model |> pull(Frequency)
inc_mdl <- tested_model |> pull(Incidence_model)
mob_mdl <- tested_model |> pull(Mobility_model)
obs_df <- data_list[[freq]]
mdl_filename <- str_glue("GBM_{model_id}")
seeds <- c(737178508, 153530893, 932012977, 147980594, 153746799)
map_df(1:5, function(i) {
pars_set <- pars_list[[i]]
map_dfr(dts, function(dt) {
pomp_obj <- pomp_GBM(inc_mdl, mob_mdl, obs_df, mdl_filename, dt)
par_obj <- pomp_obj$pars
pomp_mdl <- pomp_obj$mdl
n_particles <- c(5e3, 1e4, 2e4, 5e4, 1e5)
fn <- file.path(folder, str_glue("pf_sensitivity_{i}_dt_{dt}.rds"))
pars <- c(unlist(pars_set), par_obj$fixed)
pomp_mdl <- pomp_mdl |> pomp(params = pars)
pf_sensitivity(n_particles = n_particles, n_cores = detectCores(),
seed = seeds[[i]], pomp_mdl = pomp_mdl, fn = fn,
n_iter = detectCores() * 2) |>
mutate(inv_dt = 1/dt)
}) |> mutate(id = i)
}) -> sens_df
```
```{r, fig.height = 7}
plot_ll_se(sens_df, GBM_colour)
```
\newpage
### Candidate 6
This formulation assumes that **weekly** incidence measurements are distributed
according to the Poisson distribution. Also, this structure **incorporates**
mobility data.
#### Equations
\hfill
\begin{equation}
\frac{dC}{dt} = \eta P_t - C_t \delta(t \, mod \, 7)
\end{equation}
\begin{equation}
y^1_w \sim Pois(C_t)
\end{equation}
\begin{equation}
y^2_w \sim Normal(Z_t, \tau)
\end{equation}
#### Time comparison
\hfill
\hfill
```{r}
plot_ll_time(sens_df |> filter(id == 1), GBM_colour)
```
\newpage
#### Convergence test
\hfill
\hfill
```{r GBM_6}
model_id <- 6
folder <- str_glue("./Saved_objects/SEI3R_GBM/mdl_{model_id}")
tested_model <- models_df[model_id, ]
freq <- tested_model |> pull(Frequency)
inc_mdl <- tested_model |> pull(Incidence_model)
mob_mdl <- tested_model |> pull(Mobility_model)
obs_df <- data_list[[freq]]
mdl_filename <- str_glue("GBM_{model_id}")
seeds <- c(155346244,717579098, 627611221, 714870127, 576080780)
map_df(1:5, function(i) {
pars_set <- pars_list[[i]]
map_dfr(dts, function(dt) {
pomp_obj <- pomp_GBM(inc_mdl, mob_mdl, obs_df, mdl_filename, dt)
par_obj <- pomp_obj$pars
pomp_mdl <- pomp_obj$mdl
n_particles <- c(5e3, 1e4, 2e4, 5e4, 1e5)
fn <- file.path(folder, str_glue("pf_sensitivity_{i}_dt_{dt}.rds"))
pars <- c(unlist(pars_set), par_obj$fixed)
pomp_mdl <- pomp_mdl |> pomp(params = pars)
pf_sensitivity(n_particles = n_particles, n_cores = detectCores(),
seed = seeds[[i]], pomp_mdl = pomp_mdl, fn = fn,
n_iter = detectCores() * 2) |>
mutate(inv_dt = 1/dt)
}) |> mutate(id = i)
}) -> sens_df
```
```{r, fig.height = 7}
plot_ll_se(sens_df, GBM_colour)
```
\newpage
# Cox-Ingersoll-Ross (DGP2)
## Process model (PM2)
\hfill
\begin{equation}
\frac{dS}{dt} = - S_t \lambda_t
\end{equation}
\begin{equation}
\frac{dE}{dt} = S_t \lambda_t - \sigma E_t
\end{equation}
\begin{equation}
\frac{dP}{dt} = \omega \sigma E_t - \eta P_t
\end{equation}
\begin{equation}
\frac{dI}{dt} = \eta P_t - \gamma I_t
\end{equation}
\begin{equation}
\frac{dA}{dt} = (1-\omega) \sigma E_t - \kappa A_t
\end{equation}
\begin{equation}
\frac{dR}{dt} = \kappa A_t + \gamma I_t
\end{equation}
\begin{equation}
\lambda_t = \frac{ \beta_t(I_t + P_t + \mu A_t)}{N_t}
\end{equation}
\begin{equation}
\beta_t = \zeta Z_t
\end{equation}
\begin{equation}
\color{red}
\frac{dZ}{dt} = \nu(\upsilon - Z_t) + \sqrt{\alpha}Z_tdW
\end{equation}
\begin{equation}
dW \sim Normal(0, \sqrt{dt})
\end{equation}
## Testing measurement model candidates
### Testing points
We use five point estimates (table below) as probes to assess the reliability of
likelihood estimates. These point estimates correspond to _plausible_ values
obtained in a earlier version of this inference analysis. For the final version,
we assume such values as **given**, and conduct the analysis from the start.
Considering that these tests are not intended to be exhaustive but rather of
exploratory nature, any arbitrary point is valid as a probe.
\hfill
```{r}
path <- "./Saved_objects/SEI3R_CIR/top_10.csv"
test_pars <- read_csv(path)
set.seed(321)
phi_guesses <- round(rhnorm(10, 0.3), 3)
test_pars$phi <- phi_guesses
pars_list <- transpose(test_pars)
kable_df <- test_pars
old_names <- colnames(kable_df)
new_names <- ifelse(old_names == "P_0",
paste0("$",old_names , "$"),
paste0("$\\",old_names , "$"))
colnames(kable_df) <- new_names
kable_df <- kable_df |> mutate(id = row_number(), .before = everything()) |>
slice(1:5)
knitr::kable(kable_df, "latex", booktabs = TRUE,
escape = FALSE, digits = 3)
```
### Summary
Similarly to the procedure followed in the previous section, we couple the CIR
process model (PM2) with those six measurement model candidates formulated for
the GBM process model (PM1) and repeat the analysis. In doing so, we obtain
identical insights.
\hfill
```{r CIR_summary}
models_df <- data.frame(
model_id = 7:12,
Frequency = c("Daily", "Daily", "Daily", "Daily", "Weekly", "Weekly"),
Incidence_model = c("Pois", "Nbin", "Pois", "Nbin", "Pois", "Pois"),
Mobility_model = c(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE),
Convergence = c("No", "Yes", "No", "Yes", "Yes", "Yes"))
kable_df <- models_df
colnames(kable_df) <- c("Id", "Frequency", "Incidence", "Mobility", "Converges")
knitr::kable(kable_df, "latex", booktabs = TRUE,
escape = FALSE, digits = 3)
```
### Candidate 7
This formulation assumes that daily incidence measurements are distributed
according to the Poisson distribution. Also, this structure does not
incorporate mobility data.
#### Equations
\hfill
\begin{equation}
\frac{dC}{dt} = \eta P_t - C_t \delta(t \, mod \, 1)
\end{equation}
\begin{equation}
y^1_d \sim Pois(C_t)
\end{equation}
\newpage
#### Convergence test
\hfill
\hfill
```{r CIR_7}
model_id <- 7
folder <- str_glue("./Saved_objects/SEI3R_CIR/mdl_{model_id}")
tested_model <- models_df[model_id - 6, ]
freq <- tested_model |> pull(Frequency)
inc_mdl <- tested_model |> pull(Incidence_model)
mob_mdl <- tested_model |> pull(Mobility_model)
obs_df <- data_list[[freq]]
mdl_filename <- str_glue("CIR_{model_id}")
seeds <- c(583990633, 778140747, 320782418, 534157346, 904115668)
map_df(1:5, function(i) {
pars_set <- pars_list[[i]]
map_dfr(dts, function(dt) {
pomp_obj <- pomp_CIR(inc_mdl, mob_mdl, obs_df, mdl_filename, dt)
par_obj <- pomp_obj$pars
pomp_mdl <- pomp_obj$mdl
n_particles <- c(5e3, 1e4, 2e4, 5e4, 1e5)
fn <- file.path(folder, str_glue("pf_sensitivity_{i}_dt_{dt}.rds"))
pars <- c(unlist(pars_set), par_obj$fixed)
pomp_mdl <- pomp_mdl |> pomp(params = pars)
pf_sensitivity(n_particles = n_particles, n_cores = detectCores(),
seed = seeds[[i]], pomp_mdl = pomp_mdl, fn = fn,
n_iter = detectCores() * 2) |>
mutate(inv_dt = 1/dt)
}) |> mutate(id = i)
}) -> sens_df
```
```{r, fig.height = 7}
plot_ll_se(sens_df, CIR_colour)
```
\newpage
### Candidate 8
This formulation assumes that daily incidence measurements are distributed
according to the Negative binomial distribution. Also, this structure does not
incorporate mobility data.
#### Equations
\hfill
\hfill
\begin{equation}
\frac{dC}{dt} = \eta P_t - C_t \delta(t \, mod \, 1)
\end{equation}
\begin{equation}
y^1_d \sim Nbin(C_t, \phi^{-1})
\end{equation}
#### Time comparison
\hfill
\hfill
```{r}
plot_ll_time(sens_df |> filter(id == 1), CIR_colour)
```
\newpage
#### Convergence test
\hfill
\hfill
```{r CIR_8}
model_id <- 8
folder <- str_glue("./Saved_objects/SEI3R_CIR/mdl_{model_id}")
tested_model <- models_df[model_id - 6, ]
freq <- tested_model |> pull(Frequency)
inc_mdl <- tested_model |> pull(Incidence_model)
mob_mdl <- tested_model |> pull(Mobility_model)
obs_df <- data_list[[freq]]
mdl_filename <- str_glue("CIR_{model_id}")
seeds <- c(60473346, 454175526, 714473089, 710821362, 72567013)
map_df(1:5, function(i) {
pars_set <- pars_list[[i]]
map_dfr(dts, function(dt) {
pomp_obj <- pomp_CIR(inc_mdl, mob_mdl, obs_df, mdl_filename, dt)
par_obj <- pomp_obj$pars
pomp_mdl <- pomp_obj$mdl
n_particles <- c(5e3, 1e4, 2e4, 5e4, 1e5)
fn <- file.path(folder, str_glue("pf_sensitivity_{i}_dt_{dt}.rds"))
pars <- c(unlist(pars_set), par_obj$fixed)
pomp_mdl <- pomp_mdl |> pomp(params = pars)
pf_sensitivity(n_particles = n_particles, n_cores = detectCores(),
seed = seeds[[i]], pomp_mdl = pomp_mdl, fn = fn,
n_iter = detectCores() * 2) |>
mutate(inv_dt = 1/dt)
}) |> mutate(id = i)
}) -> sens_df
```
```{r, fig.height = 7}
plot_ll_se(sens_df, CIR_colour)
```
\newpage
### Candidate 9
This formulation assumes that daily incidence measurements are distributed
according to the Poisson distribution. Also, this structure **incorporates**
mobility data.