Skip to content

Commit 8f8326f

Browse files
more code
1 parent 0a31c11 commit 8f8326f

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

code/measles-problem-answer.R

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
## Measles problem answers
2+
3+
pop <- 10000
4+
5+
Rzero <- 12
6+
alpha <- 1/20
7+
gamma <- 1/14
8+
9+
I_init <- 1
10+
E_init <- 1
11+
12+
vaxprop <- 0.90
13+
eff <- 0.9
14+
15+
iso <- 0.2
16+
17+
params <- list(beta = Rzero*gamma
18+
, alpha = alpha
19+
, gamma = gamma
20+
, vaxprop = vaxprop
21+
, eff = eff
22+
, theta = iso
23+
, pop = pop
24+
, I_init = I_init
25+
, E_init = E_init
26+
, V_init = vaxprop*pop
27+
, R_init = 0
28+
, Iso_init = 0
29+
)
30+
31+
spec = mp_tmb_model_spec(
32+
before = list(
33+
R ~ R_init
34+
, N ~ pop
35+
, E ~ E_init
36+
, I ~ I_init
37+
, I_iso ~ Iso_init
38+
, V ~ V_init
39+
, S ~ N - I - I_iso - R - E - V
40+
)
41+
, during = list(
42+
Lambda ~ beta * I / N
43+
, mp_per_capita_flow("S", "E" , "Lambda" , "infection")
44+
, mp_per_capita_flow("E", "I" , "alpha" , "progression")
45+
, mp_per_capita_flow("I", "R" , "gamma" , "recovery")
46+
, mp_per_capita_flow("V", "E" , "(1-eff)*Lambda", "infection_v")
47+
, mp_per_capita_flow("V", "R" , "eff*Lambda" , "protection")
48+
, mp_per_capita_flow("E", "I_iso", "theta*alpha" , "isolation")
49+
, mp_per_capita_flow("I_iso", "R" , "gamma" , "recovery_iso")
50+
)
51+
, default = params
52+
)
53+
54+
sim = mp_simulator(spec, 500, mp_state_vars(spec))
55+
(sim
56+
|> mp_trajectory()
57+
|> ggplot(aes(time, value))
58+
+ geom_line()
59+
+ facet_wrap(~matrix, scales = "free")
60+
)

0 commit comments

Comments
 (0)