-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSEI.R
87 lines (68 loc) · 1.45 KB
/
SEI.R
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
#' Susceptible-Exposed-Infected Model
#'
#' @inherit SI_ode
#' @export
#'
#' @examples
#' ##Model Input
#' S_0 <- 989
#' E_0 <- 10
#' I_0 <- 1
#' beta <- 3
#' gamma = 1/2
#' dt <- 1
#' parameters <- c(beta = beta, gamma = gamma)
#' inits <- c(S = S_0, E = E_0, I = I_0)
#'
#' SEI_ode(1, inits, parameters)
SEI_ode <- function(t, x, params) {
## Specify model compartments
S <- x[1]
E <- x[2]
I <- x[3]
with(as.list(params),{
## Specify total population
N = S + E + I
## Derivative Expressions
dS = -beta * S * I / N
dE = +beta * S * I / N - gamma * E
dI = +gamma * E
## output
derivatives <- c(dS, dE, dI)
list(derivatives)
})
}
#' Susceptible-Exposed-Infected Model with Simple Demographics
#' @inherit SI_ode
#' @export
#'
#' @examples
#' ##Model Input
#' S_0 <- 989
#' E_0 <- 10
#' I_0 <- 1
#' beta <- 3
#' gamma <- 1/2
#' mu <- 1/81
#' dt <- 1
#' parameters <- c(beta = beta, gamma = gamma, mu = mu)
#' inits <- c(S = S_0, E = E_0, I = I_0)
#'
#' SEI_demographics_ode(1, inits, parameters)
SEI_demographics_ode <- function(t, x, params) {
## Specify model compartments
S <- x[1]
E <- x[2]
I <- x[3]
with(as.list(params),{
## Specify total population
N = S + E + I
## Derivative Expressions
dS = -beta * S * I / N - mu * S + mu * N
dE = +beta * S * I / N - gamma * E - mu * E
dI = +gamma * E - mu *I
## output
derivatives <- c(dS, dE, dI)
list(derivatives)
})
}