These functions provide access to the network of the model. The network is
represented by an edgelist. The agents_smallworld
function generates a
small world network with the Watts-Strogatz algorithm. The
agents_from_edgelist
function loads a network from an edgelist.
The get_network
function returns the edgelist of the network.
Usage
agents_smallworld(model, n, k, d, p)
agents_from_edgelist(model, source, target, size, directed)
get_network(model)
get_agents_states(model)
add_virus_agent(agent, model, virus, state_new = -99, queue = -99)
add_tool_agent(agent, model, tool, state_new = -99, queue = -99)
has_virus(agent, virus)
has_tool(agent, tool)
change_state(agent, model, state_new, queue = -99)
get_agents_tools(model)
Arguments
- model
Model object of class epiworld_model.
- n, size
Number of individuals in the population.
- k
Number of ties in the small world network.
- d, directed
Logical scalar. Whether the graph is directed or not.
- p
Probability of rewiring.
- source, target
Integer vectors describing the source and target of in the edgelist.
- agent
Agent object of class
epiworld_agent
.- virus
Virus object of class
epiworld_virus
.- state_new
Integer scalar. New state of the agent after the action is executed.
- queue
Integer scalar. Change in the queuing system after the action is executed.
- tool
Tool object of class
epiworld_tool
.
Value
The 'agents_smallworld' function returns a model with the agents loaded.
The
agents_from_edgelist
function returns an empty model of classepiworld_model
.
The
get_network
function returns a data frame with two columns (source
andtarget
) describing the edgelist of the network.
get_agents_states
returns an character vector with the states of the agents by the end of the simulation.
The function
add_virus_agent
adds a virus to an agent and returns the agent invisibly.
The function
add_tool_agent
adds a tool to an agent and returns the agent invisibly.
The functions
has_virus
andhas_tool
return a logical scalar indicating whether the agent has the virus/tool or not.
get_agents_tools
returns a list of classepiworld_agents_tools
withepiworld_tools
(list of lists).
Details
The new_state
and queue
parameters are optional. If they are not
provided, the agent will be updated with the default values of the virus/tool.
Examples
# Initializing SIR model with agents_smallworld
sir <- ModelSIR(name = "COVID-19", prevalence = 0.01, transmission_rate = 0.9,
recovery_rate = 0.1)
agents_smallworld(
sir,
n = 1000,
k = 5,
d = FALSE,
p = .01
)
run(sir, ndays = 100, seed = 1912)
#> _________________________________________________________________________
#> Running the model...
#> ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> done.
sir
#> ________________________________________________________________________________
#> Susceptible-Infected-Recovered (SIR)
#> It features 1000 agents, 1 virus(es), and 0 tool(s).
#> The model has 3 states.
#> The final distribution is: 0 Susceptible, 3 Infected, and 997 Recovered.
# We can also retrieve the network
net <- get_network(sir)
head(net)
#> from to
#> 1 0 1
#> 2 0 2
#> 3 0 998
#> 4 0 999
#> 5 1 2
#> 6 1 3
# Simulating a bernoulli graph
set.seed(333)
n <- 1000
g <- matrix(runif(n^2) < .01, nrow = n)
diag(g) <- FALSE
el <- which(g, arr.ind = TRUE) - 1L
# Generating an empty model
sir <- ModelSIR("COVID-19", .01, .8, .3)
agents_from_edgelist(
sir,
source = el[, 1],
target = el[, 2],
size = n,
directed = TRUE
)
# Running the simulation
run(sir, 50)
#> _________________________________________________________________________
#> |Running the model...
#> |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| done.
#> | done.
plot(sir)