These functions simulate diffusion or compartment models upon a network.
play_diffusion()
runs a single simulation of a compartment model,
allowing the results to be visualised and examined.
These functions allow both a full range of compartment models, as well as simplex and complex diffusion to be simulated upon a network.
play_diffusion(
.data,
seeds = 1,
contact = NULL,
prevalence = 0,
thresholds = 1,
transmissibility = 1,
latency = 0,
recovery = 0,
waning = 0,
immune = NULL,
steps,
old_version = FALSE
)
An object of a manynet-consistent class:
matrix (adjacency or incidence) from {base}
R
edgelist, a data frame from {base}
R or tibble from {tibble}
igraph, from the {igraph}
package
network, from the {network}
package
tbl_graph, from the {tidygraph}
package
A valid mark vector the length of the number of nodes in the network.
A matrix or network that replaces ".data" with some
other explicit contact network, e.g.
create_components(.data, membership = node_in_structural(.data))
.
Can be of arbitrary complexity, but must of the same dimensions
as .data.
The proportion that global prevalence contributes to diffusion. That is, if prevalence is 0.5, then the current number of infections is multiplied by 0.5 and added "prevalence" is 0 by default, i.e. there is no global mechanism. Note that this is endogenously defined and is updated at the outset of each step.
A numeric vector indicating the thresholds each node has. By default 1. A single number means a generic threshold; for thresholds that vary among the population please use a vector the length of the number of nodes in the network. If 1 or larger, the threshold is interpreted as a simple count of the number of contacts/exposures sufficient for infection. If less than 1, the threshold is interpreted as complex, where the threshold concerns the proportion of contacts.
The transmission rate probability, \(\beta\). By default 1, which means any node for which the threshold is met or exceeded will become infected. Anything lower means a correspondingly lower probability of adoption, even when the threshold is met or exceeded.
The inverse probability those who have been exposed become infectious (infected), \(\sigma\) or \(\kappa\). For example, if exposed individuals take, on average, four days to become infectious, then \(\sigma = 0.75\) (1/1-0.75 = 1/0.25 = 4). By default 0, which means those exposed become immediately infectious (i.e. an SI model). Anything higher results in e.g. a SEI model.
The probability those who are infected recover, \(\gamma\). For example, if infected individuals take, on average, four days to recover, then \(\gamma = 0.25\). By default 0, which means there is no recovery (i.e. an SI model). Anything higher results in an SIR model.
The probability those who are recovered become susceptible again, \(\xi\). For example, if recovered individuals take, on average, four days to lose their immunity, then \(\xi = 0.25\). By default 0, which means any recovered individuals retain lifelong immunity (i.e. an SIR model). Anything higher results in e.g. a SIRS model. \(\xi = 1\) would mean there is no period of immunity, e.g. an SIS model.
A logical or numeric vector identifying nodes that begin the diffusion process as already recovered. This could be interpreted as those who are vaccinated or equivalent. Note however that a waning parameter will affect these nodes too. By default NULL, indicating that no nodes begin immune.
The number of steps forward in the diffusion to play.
By default the number of nodes in the network.
If steps = Inf
then the diffusion process will continue until
there are no new infections or all nodes are infected.
This is included to maintain backward compatibility with the old version of this function, that would return a special object. The new version adds the diffusion event record as changes to the original network.
By default, the function will simulate a simple diffusion process in
which some infectious disease or idea diffuses from seeds through
contacts at some constant rate (transmissibility
).
These seeds
can be specified by a vector index
(the number of the position of each node in the network that should serve as a seed)
or as a logical vector where TRUE is interpreted as already infected.
thresholds
can be set such that adoption/infection requires more than one
(the default) contact already being infected.
This parameter also accepts a vector so that thresholds can vary.
Complex diffusion is where the thresholds
are defined less than one.
In this case, the thresholds are interpreted as proportional.
That is, the threshold to adoption/infection is defined by the
proportion of the node's contacts infected.
Nodes that cannot be infected can be indicated as immune
with a logical vector or index, similar to how seeds
are identified.
Note that immune
nodes are interpreted internally as Recovered (R)
and are thus subject to waning
(see below).
Compartment models are flexible models of diffusion or contagion, where nodes are compartmentalised into one of two or more categories.
The most basic model is the SI model.
The SI model is the default in play_diffusion()
/play_diffusions()
,
where nodes can only move from the Susceptible (S) category to the
Infected (I) category.
Whether nodes move from S to I depends on whether they are exposed
to the infection, for instance through a contact,
the transmissibility
of the disease,
and their thresholds
to the disease.
Another common model is the SIR model.
Here nodes move from S to I, as above, but additionally they can
move from I to a Recovered (R) status.
The probability that an infected node recovers at a timepoint
is controlled by the recovery
parameter.
The next most common models are the SIS and SIRS models.
Here nodes move from S to I or additionally to R, as above,
but additionally they can move from I or R back to a Susceptible (S) state.
This probability is governed by the waning
parameter.
Where recover > 0
and waning = 1
, the Recovery (R) state will be skipped
and the node will return immediately to the Susceptible (S) compartment.
Lastly, these functions also offer the possibility of specifying
a latency period in which nodes have been infected but are not yet infectious.
Where latency > 0
, an additional Exposed (E) compartment is introduced
that governs the probability that a node moves from this E compartment
to infectiousness (I).
This can be used in in SEI, SEIS, SEIR, and SEIRS models.
Other makes:
make_cran
,
make_create
,
make_ego
,
make_explicit
,
make_learning
,
make_motifs
,
make_random
,
make_read
,
make_stochastic
,
make_write
Other models:
make_learning
Other diffusion:
measure_diffusion_infection
,
measure_diffusion_net
,
measure_diffusion_node
,
member_diffusion
smeg <- generate_smallworld(15, 0.025)
plot(play_diffusion(smeg, recovery = 0.4))
#graphr(play_diffusion(ison_karateka))