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.`play_diffusions()`

runs multiple simulations of a compartment model for more robust inference.

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,
thresholds = 1,
transmissibility = 1,
latency = 0,
recovery = 0,
waning = 0,
immune = NULL,
steps
)
play_diffusions(
.data,
seeds = 1,
thresholds = 1,
transmissibility = 1,
latency = 0,
recovery = 0,
waning = 0,
immune = NULL,
steps,
times = 5,
strategy = "sequential",
verbose = FALSE
)
```

- .data
An object of a manynet-consistent class:

matrix (adjacency or incidence) from

`{base}`

Redgelist, a data frame from

`{base}`

R or tibble from`{tibble}`

igraph, from the

`{igraph}`

packagenetwork, from the

`{network}`

packagetbl_graph, from the

`{tidygraph}`

package

- seeds
A valid mark vector the length of the number of nodes in the network.

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

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

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

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

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

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

- steps
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.- times
Integer indicating number of simulations. By default

`times=5`

, but 1,000 - 10,000 simulations recommended for publication-ready results.- strategy
If

`{furrr}`

is installed, then multiple cores can be used to accelerate the simulations. By default "sequential", but if multiple cores available, then "multisession" or "multicore" may be useful. Generally this is useful only when times > 1000. See`{furrr}`

for more.- verbose
Whether the function should report on its progress. By default FALSE. See

`{progressr}`

for more.

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.

```
smeg <- generate_smallworld(15, 0.025)
plot(play_diffusion(smeg, recovery = 0.4))
#autographr(play_diffusion(ison_karateka))
plot(play_diffusions(smeg, times = 10))
#>
#> Attaching package: ‘purrr’
#> The following object is masked from ‘package:manynet’:
#>
#> is_list
```