# Simple model
model_sirconn <- ModelSIRCONN(
name = "COVID-19",
n = 10000,
prevalence = 0.01,
contact_rate = 5,
transmission_rate = 0.4,
recovery_rate = 0.95
)
# Creating a tool
epitool <- tool(
name = "Vaccine",
prevalence = 0,
as_proportion = FALSE,
susceptibility_reduction = .9,
transmission_reduction = .5,
recovery_enhancer = .5,
death_reduction = .9
)
# Adding a global event
vaccine_day_20 <- globalevent_tool(epitool, .2, day = 20)
add_globalevent(model_sirconn, vaccine_day_20)
# Running and printing
run(model_sirconn, ndays = 40, seed = 1912)
model_sirconn
plot_incidence(model_sirconn)
# Example 2: Changing the contact rate -------------------------------------
model_sirconn2 <- ModelSIRCONN(
name = "COVID-19",
n = 10000,
prevalence = 0.01,
contact_rate = 5,
transmission_rate = 0.4,
recovery_rate = 0.95
)
closure_day_10 <- globalevent_set_params("Contact rate", 0, day = 10)
add_globalevent(model_sirconn2, closure_day_10)
# Running and printing
run(model_sirconn2, ndays = 40, seed = 1912)
model_sirconn2
plot_incidence(model_sirconn2)
# Example using `globalevent_fun` to record the state of the
# agents at each time step.
# We start by creating an SIR connected model
model <- ModelSIRCONN(
name = "SIR with Global Saver",
n = 1000,
prevalence = 0.01,
contact_rate = 5,
transmission_rate = 0.4,
recovery_rate = 0.3
)
# We create the object where the history of the agents will be stored
agents_history <- NULL
# This function prints the total number of agents in each state
# and stores the history of the agents in the object `agents_history`
hist_saver <- function(m) {
message("Today's totals are: ", paste(get_today_total(m), collapse = ", "))
# We use the `<<-` operator to assign the value to the global variable
# `agents_history` (see ?"<<-")
agents_history <<- cbind(
agents_history,
get_agents_states(m)
)
}
Run the code above in your browser using DataLab