Skip to contents

These functions provide read-access to the agents of the model. The get_agents function returns an object of class epiworld_agents which contains all the information about the agents in the model. The get_agent function returns the information of a single agent. And the get_state function returns the state of a single agent.

Usage

get_agents(model)

# S3 method for epiworld_agents
[(x, i)

# S3 method for epiworld_agent
print(x, compressed = FALSE, ...)

# S3 method for epiworld_agents
print(x, compressed = TRUE, max_print = 10, ...)

get_state(x)

Arguments

model

An object of class epiworld_model.

x

An object of class epiworld_agents

i

Index (id) of the agent (from 0 to n-1)

compressed

Logical scalar. When FALSE, it prints detailed information about the agent.

...

Ignored

max_print

Integer scalar. Maximum number of agents to print.

Value

  • The get_agents function returns an object of class epiworld_agents.

  • The [ method returns an object of class epiworld_agent.

  • The print function returns information about each individual agent of class epiworld_agent.

  • The get_state function returns the state of the epiworld_agents object.

See also

agents

Examples

 
model_sirconn <- ModelSIRCONN(
name                = "COVID-19",
n                   = 10000,
prevalence          = 0.01,
contact_rate        = 5,
transmission_rate   = 0.4,
recovery_rate       = 0.95
)

run(model_sirconn, ndays = 100, seed = 1912)
#> _________________________________________________________________________
#> Running the model...
#> ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#>  done.

x <- get_agents(model_sirconn) # Storing all agent information into object of 
                               # class epiworld_agents
                             
print(x, compressed = FALSE, max_print = 5) # Displaying detailed information of 
#> Agents from the model "Susceptible-Infected-Removed (SIR) (connected)":
#> Information about agent id 0
#>   State        : Susceptible (0)
#>   Has virus    : no
#>   Tool count   : 0
#>   Neigh. count : 0
#> Information about agent id 1
#>   State        : Recovered (2)
#>   Has virus    : no
#>   Tool count   : 0
#>   Neigh. count : 0
#> Information about agent id 2
#>   State        : Recovered (2)
#>   Has virus    : no
#>   Tool count   : 0
#>   Neigh. count : 0
#> Information about agent id 3
#>   State        : Recovered (2)
#>   Has virus    : no
#>   Tool count   : 0
#>   Neigh. count : 0
#> Information about agent id 4
#>   State        : Recovered (2)
#>   Has virus    : no
#>   Tool count   : 0
#>   Neigh. count : 0
#> ... 9995 more agents ...
                                        # the first 5 agents using 
                                        # compressed=F. Using compressed=T
                                        # results in less-detailed 
                                        # information about each agent. 
                                        
x[0] # Print information about the first agent. Substitute the agent of 
#> Information about agent id 0
#>   State        : Susceptible (0)
#>   Has virus    : no
#>   Tool count   : 0
#>   Neigh. count : 0
     # interest's position where '0' is.