-
Notifications
You must be signed in to change notification settings - Fork 10
Agent Multigroup
Junling Ma edited this page Nov 8, 2023
·
4 revisions
# the transmission rate matrix
beta = matrix(c(0.4, 0.2, 0.2, 0.3), nrow=2)
# the recovery rate
gamma = newExpWaitingTime(0.2)
# the rate leaving the latent stage and becoming infectious
sigma=0.5
# the population size
N = 10000
The state of an agent is an R list. At most one of the value can be unnamed, others must be named. The names are called domains, and their values can be any R value.
In this example, there are two domains, an unnamed one denoting the infections status, and a named one specifying the group it is in.
# initialize a simulation with N agents
sim = Simulation$new(N)
for (i in 1:n) {
sim$setState(i, list(if (i <= 20) "I" else "S", group=i %% 2))
}
See the details of Counter objects and the Logger class in the SEIR model page.
The following counts the number of agents in the states specified by "from".
sim$addLogger(newCounter("S1", from=list("S", group=0)))
sim$addLogger(newCounter("S2", list("S", group=1)))
sim$addLogger(newCounter("E1", list("E", group=0)))
sim$addLogger(newCounter("E2", list("E", group=1)))
sim$addLogger(newCounter("I1", list("I", group=0)))
sim$addLogger(newCounter("I2", list("I", group=1)))
sim$addLogger(newCounter("R1", list("R", group=0)))
sim$addLogger(newCounter("R2", list("R", group=1)))
We create a random mixing object and add it to the simulation
m = newRandomMixing()
sim$addContact(m)
See details of transitions int he SEIR model.
sim$addTransition("E"->"I", sigma)
sim$addTransition("I"->"R", gamma)
sim$addTransition(list("I", group=0) + list("S", group=0) ->
list("I", group=0) + list("E", group=0) ~ m, beta[1, 1])
sim$addTransition(list("I", group=0) + list("S", group=1) ->
list("I", group=0) + list("E", group=1) ~ m, beta[1, 2])
sim$addTransition(list("I", group=1) + list("S", group=0) ->
list("I", group=1) + list("E", group=0) ~ m, beta[2, 1])
sim$addTransition(list("I", group=1) + list("S", group=1) ->
list("I", group=1) + list("E", group=1) ~ m, beta[2, 2])
result = sim$run(0:250)
print(result)