agents_smallworld {epiworldR}R Documentation

Load agents to a model

Description

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.

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.

Value

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)
sir

# We can also retrieve the network
net <- get_network(sir)
head(net)

# 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)

plot(sir)

[Package epiworldR version 0.1-0 Index]