## For reproducibility, specify the number of threads.
set_num_threads(1)
## Create an 'SIR' model with 6 nodes.
u0 <- data.frame(
S = 100:105,
I = c(0, 1, 0, 2, 0, 3),
R = rep(0, 6)
)
model <- SIR(
u0 = u0,
tspan = 1:10,
beta = 0.16,
gamma = 0.077
)
## Run the model with a fixed seed for reproducibility.
result <- run(model, seed = 12)
## 1. Population Prevalence (level = 1, default)
## Proportion of infected individuals in the total population.
prevalence(result, I ~ S + I + R)
## Shorthand: '.' represents all compartments in the model (S + I + R).
prevalence(result, I ~ .)
## 2. Node Prevalence (level = 2)
## Proportion of nodes with at least one infected individual.
prevalence(result, I ~ S + I + R, level = 2)
## 3. Within-Node Prevalence (level = 3)
## Prevalence calculated separately for each node.
prevalence(result, I ~ S + I + R, level = 3)
## 4. Conditional Prevalence
## Calculate prevalence only in nodes where the number of
## recovered is zero.
prevalence(result, I ~ S + I + R | R == 0, level = 3)
Run the code above in your browser using DataLab