The functions described in this section are methods for objects of class
epiworld_model
. Besides of printing and plotting, other methods provide
access to manipulate model parameters, getting information about the model
and running the simulation.
Usage
queuing_on(x)
queuing_off(x)
verbose_off(x)
verbose_on(x)
run(model, ndays, seed = NULL)
# S3 method for class 'epiworld_model'
summary(object, ...)
get_states(x)
get_param(x, pname)
add_param(x, pname, pval)
# S3 method for class 'epiworld_model'
add_param(x, pname, pval)
set_param(x, pname, pval)
set_name(x, mname)
get_name(x)
get_n_viruses(x)
get_n_tools(x)
get_ndays(x)
today(x)
get_n_replicates(x)
size(x)
set_agents_data(model, data)
get_agents_data_ncols(model)
get_virus(model, virus_pos)
get_tool(model, tool_pos)
initial_states(model, proportions)
clone_model(model)
Arguments
- x
An object of class
epiworld_model
.- model
Model object.
- ndays
Number of days (steps) of the simulation.
- seed
Seed to set for initializing random number generator (passed to
set.seed()
).- object
Object of class
epiworld_model
.- ...
Additional arguments.
- pname
String. Name of the parameter.
- pval
Numeric. Value of the parameter.
- mname
String. Name of the model.
- data
A numeric matrix.
- virus_pos
Integer. Relative location (starting from 0) of the virus in the model
- tool_pos
Integer. Relative location (starting from 0) of the tool in the model
- proportions
Numeric vector. Proportions in which agents will be distributed (see details).
Value
The
verbose_on
andverbose_off
functions return the same model, howeververbose_off
returns the model with no progress bar.
The
run
function returns the simulated model of classepiworld_model
.
The
summary
function prints a more detailed view of the model, and returns the same model invisibly.
The
get_states
function returns the unique states found in a model.
The
get_param
function returns a selected parameter from the model object of classepiworld_model
.
add_param
returns the model with the added parameter invisibly.
The
set_param
function does not return a value but instead alters a parameter value.
The
set_name
function does not return a value but instead alters an object ofepiworld_model
.
get_name
returns the name of the model.
get_n_viruses
returns the number of viruses of the model.
get_n_tools
returns the number of tools of the model.
get_ndays
returns the number of days of the model.
today
returns the current model day
get_n_replicates
returns the number of replicates of the model.
size.epiworld_model
returns the number of agents in the model.
The 'set_agents_data' function returns an object of class DataFrame.
'get_agents_data_ncols' returns the number of columns in the model dataframe.
'get_virus' returns a virus.
get_tool
returns a tool.
inital_states
returns the model with an updated initial state.
clone_model
returns a copy of the model.
Details
The verbose_on
and verbose_off
functions activate and deactivate printing
progress on screen, respectively. Both functions return the model (x
) invisibly.
epiworld_model
objects are pointers to an underlying C++ class
in epiworld
. To generate a copy of a model, use clone_model
, otherwise,
the assignment operator will only copy the pointer.
Examples
model_sirconn <- ModelSIRCONN(
name = "COVID-19",
n = 10000,
prevalence = 0.01,
contact_rate = 5,
transmission_rate = 0.4,
recovery_rate = 0.95
)
# Queuing - If you wish to implement the queuing function, declare whether
# you would like it "on" or "off", if any.
queuing_on(model_sirconn)
#> Warning: SIR Connected models do not have queue.
queuing_off(model_sirconn)
run(model_sirconn, ndays = 100, seed = 1912)
#> _________________________________________________________________________
#> Running the model...
#> ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> done.
# Verbose - "on" prints the progress bar on the screen while "off"
# deactivates the progress bar. Declare which function you want to implement,
# if any.
verbose_on(model_sirconn)
verbose_off(model_sirconn)
run(model_sirconn, ndays = 100, seed = 1912)
get_states(model_sirconn) # Returns all unique states found within the model.
#> [1] "Susceptible" "Infected" "Recovered"
get_param(model_sirconn, "Contact rate") # Returns the value of the selected
#> [1] 5
# parameter within the model object.
# In order to view the parameters,
# run the model object and find the
# "Model parameters" section.
set_param(model_sirconn, "Contact rate", 2) # Allows for adjustment of model
# parameters within the model
# object. In this example, the
# Contact rate parameter is
# changed to 2. You can now rerun
# the model to observe any
# differences.
set_name(model_sirconn, "My Epi-Model") # This function allows for setting
# a name for the model. Running the
# model object, the name of the model
# is now reflected next to "Name of
# the model".
get_name(model_sirconn) # Returns the set name of the model.
#> [1] "My Epi-Model"
get_n_viruses(model_sirconn) # Returns the number of viruses in the model.
#> [1] 1
# In this case, there is only one virus:
# "COVID-19".
get_n_tools(model_sirconn) # Returns the number of tools in the model. In
#> [1] 0
# this case, there are zero tools.
get_ndays(model_sirconn) # Returns the length of the simulation in days. This
#> [1] 100
# will match "ndays" within the "run" function.
today(model_sirconn) # Returns the current day of the simulation. This will
#> [1] 100
# match "get_ndays()" if run at the end of a simulation, but will differ if run
# during a simulation
get_n_replicates(model_sirconn) # Returns the number of replicates of the
#> [1] 2
# model.
size(model_sirconn) # Returns the population size in the model. In this case,
#> [1] 10000
# there are 10,000 agents in the model.
# Set Agents Data
# First, your data matrix must have the same number of rows as agents in the
# model. Below is a generated matrix which will be passed into the
# "set_agents_data" function.
data <- matrix(data = runif(20000, min = 0, max = 100), nrow = 10000, ncol = 2)
set_agents_data(model_sirconn, data)
get_agents_data_ncols(model_sirconn) # Returns number of columns
#> [1] 2
get_virus(model_sirconn, 0) # Returns information about the first virus in
#> Virus : COVID-19
#> Id : 0
#> state_init : 1
#> state_post : 2
#> state_removed : 2
#> queue_init : 2
#> queue_post : -2
#> queue_removed : -99
# the model (index begins at 0).
add_tool(model_sirconn, tool("Vaccine", .9, .9, .5, 1, prevalence = 0.5, as_prop = TRUE))
get_tool(model_sirconn, 0) # Returns information about the first tool in the
#> Tool : Vaccine
#> Id : 0
#> state_init : -99
#> state_post : -99
#> queue_init : 0
#> queue_post : 0
# model. In this case, there are no tools so an
# error message will occur.