Skip to contents

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.






run(model, ndays, seed =, 1))

# S3 method for epiworld_model
summary(object, ...)


get_param(x, pname)

set_param(x, pname, pval)

set_name(x, mname)







set_agents_data(model, data)


get_virus(model, virus_pos)

get_tool(model, tool_pos)

initial_states(model, proportions)




An object of class epiworld_model.


Model object.


Number of days (steps) of the simulation.


Seed to set for initializing random number generator.


Object of class epiworld_model.


Additional arguments.


String. Name of the parameter.


Numeric. Value of the parameter.


String. Name of the model.


A numeric matrix.


Integer. Relative location (starting from 0) of the virus in the model


Integer. Relative location (starting from 0) of the tool in the model


Numeric vector. Proportions in which agents will be distributed (see details).


  • The verbose_on and verbose_off functions return the same model, however verbose_off returns the model with no progress bar.

  • The run function returns the simulated model of class epiworld_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 class epiworld_model.

  • 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 of epiworld_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.

  • 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.


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.


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. 
#> Warning: SIR Connected models do not have queue.
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. 
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. 
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), proportion = .5)                            
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.