if (FALSE) {
## For reproducibility, call the set.seed() function and specify
## the number of threads to use. To use all available threads,
## remove the set_num_threads() call.
set.seed(123)
set_num_threads(1)
## Create an 'SIR' model with 100 nodes and initialise
## it with 990 susceptible individuals and 10 infected
## individuals in each node. Run the model over 100 days.
model <- SIR(u0 = data.frame(S = rep(990, 100),
I = rep(10, 100),
R = rep(0, 100)),
tspan = 1:100,
beta = 0.16,
gamma = 0.077)
## Run the model and save the result.
result <- run(model)
## Plot the median and interquartile range of the number
## of susceptible, infected and recovered individuals.
plot(result)
## Plot the median and the middle 95\
## number of susceptible, infected and recovered individuals.
plot(result, range = 0.95)
## Plot the median and interquartile range of the number
## of infected individuals.
plot(result, "I")
## Use the formula notation instead to plot the median and
## interquartile range of the number of infected individuals.
plot(result, ~I)
## Plot the number of susceptible, infected
## and recovered individuals in the first
## three nodes.
plot(result, index = 1:3, range = FALSE)
## Use plot type line instead.
plot(result, index = 1:3, range = FALSE, type = "l")
## Plot the number of infected individuals in the first node.
plot(result, "I", index = 1, range = FALSE)
## Plot the proportion of infected individuals (cases)
## in the population.
plot(result, I ~ S + I + R)
## Plot the proportion of nodes with infected individuals.
plot(result, I ~ S + I + R, level = 2)
## Plot the median and interquartile range of the proportion
## of infected individuals in each node
plot(result, I ~ S + I + R, level = 3)
## Plot the proportion of infected individuals in the first
## three nodes.
plot(result, I ~ S + I + R, level = 3, index = 1:3, range = FALSE)
}
Run the code above in your browser using DataLab