Functions to play games on networks

```
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
)
play_learning(.data, beliefs, steps, epsilon = 5e-04)
play_segregation(
.data,
attribute,
heterophily = 0,
who_moves = c("ordered", "random", "most_dissatisfied"),
choice_function = c("satisficing", "optimising", "minimising"),
steps
)
```

- .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 used for quantile estimation. (Relevant to the null hypothesis test only - the analysis itself is unaffected by this parameter.) Note that, as for all Monte Carlo procedures, convergence is slower for more extreme quantiles. By default,

`times=1000`

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

`{furrr}`

is installed, then multiple cores can be used to accelerate the function. 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.- beliefs
A vector indicating the probabilities nodes put on some outcome being 'true'.

- epsilon
The maximum difference in beliefs accepted for convergence to a consensus.

- attribute
A string naming some nodal attribute in the network. Currently only tested for binary attributes.

- heterophily
A score ranging between -1 and 1 as a threshold for how heterophilous nodes will accept their neighbours to be. A single proportion means this threshold is shared by all nodes, but it can also be a vector the same length of the nodes in the network for issuing different thresholds to different nodes. By default this is 0, meaning nodes will be dissatisfied if more than half of their neighbours differ on the given attribute.

- who_moves
One of the following options: "ordered" (the default) checks each node in turn for whether they are dissatisfied and there is an available space that they can move to, "random" will check a node at random, and "most_dissatisfied" will check (one of) the most dissatisfied nodes first.

- choice_function
One of the following options: "satisficing" (the default) will move the node to any coordinates that satisfy their heterophily threshold, "optimising" will move the node to coordinates that are most homophilous, and "minimising" distance will move the node to the next nearest unoccupied coordinates.

`play_diffusion()`

: Playing compartmental diffusion on networks.`play_diffusions()`

: Playing multiple compartmental diffusions on networks.`play_learning()`

: Playing DeGroot learning on networks.`play_segregation()`

: Playing Schelling segregation on networks.

Other models:
`regression`

,
`tests`

```
smeg <- manynet::generate_smallworld(15, 0.025)
plot(play_diffusion(smeg))
plot(play_diffusion(smeg, recovery = 0.4))
plot(play_diffusions(smeg, times = 20))
play_learning(ison_networkers,
rbinom(manynet::network_nodes(ison_networkers),1,prob = 0.25))
#> # A tibble: 8 × 32
#> `Lin Freeman` `Doug White` `Ev Rogers` `Richard Alba` `Phipps Arabie`
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0 0 1 0 0
#> 2 0.198 0.181 0 0.263 0.258
#> 3 0.165 0.179 0.186 0.165 0.156
#> 4 0.182 0.177 0.167 0.183 0.184
#> 5 0.176 0.179 0.181 0.178 0.176
#> 6 0.178 0.178 0.177 0.178 0.179
#> 7 0.178 0.178 0.178 0.178 0.178
#> 8 0.178 0.178 0.178 0.178 0.178
#> # ℹ 27 more variables: `Carol Barner-Barry` <dbl>, `Gary Coombs` <dbl>,
#> # `Russ Bernard` <dbl>, `John Boyd` <dbl>, `Ron Burt` <dbl>,
#> # `Pat Doreian` <dbl>, `Claude Fischer` <dbl>, `Brian Foster` <dbl>,
#> # `Mark Granovetter` <dbl>, `Maureen Hallinan` <dbl>, `Paul Holland` <dbl>,
#> # `Jack Hunter` <dbl>, `Davor Jedlicka` <dbl>, `Charles Kadushin` <dbl>,
#> # `Ed Laumann` <dbl>, `Sam Leinhardt` <dbl>, `Joel Levine` <dbl>,
#> # `Nan Lin` <dbl>, `Nick Mullins` <dbl>, `Don Ploch` <dbl>, …
startValues <- rbinom(100,1,prob = 0.5)
startValues[sample(seq_len(100), round(100*0.2))] <- NA
latticeEg <- manynet::create_lattice(100)
latticeEg <- manynet::add_node_attribute(latticeEg, "startValues", startValues)
latticeEg
#> # A undirected network with 100 nodes and 342 ties
#> # A tibble: 100 × 1
#> startValues
#> <int>
#> 1 NA
#> 2 NA
#> 3 0
#> 4 0
#> 5 1
#> 6 NA
#> # ℹ 94 more rows
#> # A tibble: 342 × 2
#> from to
#> <int> <int>
#> 1 1 2
#> 2 1 11
#> 3 1 12
#> 4 2 3
#> 5 2 11
#> 6 2 12
#> # ℹ 336 more rows
play_segregation(latticeEg, "startValues", 0.5)
#> [1] "Moving node 20 to node 57"
#> [1] "Moving node 23 to node 98"
#> [1] "Moving node 74 to node 48"
#> [1] "Moving node 81 to node 64"
#> [1] "Moving node 96 to node 41"
#> # A undirected network with 100 nodes and 342 ties
#> # A tibble: 100 × 1
#> startValues
#> <int>
#> 1 NA
#> 2 NA
#> 3 0
#> 4 0
#> 5 1
#> 6 NA
#> # ℹ 94 more rows
#> # A tibble: 342 × 2
#> from to
#> <int> <int>
#> 1 1 2
#> 2 1 11
#> 3 1 12
#> 4 2 3
#> 5 2 11
#> 6 2 12
#> # ℹ 336 more rows
# manynet::autographr(latticeEg, node_color = "startValues", node_size = 5) +
# manynet::autographr(play_segregation(latticeEg, "startValues", 0.2),
# node_color = "startValues", node_size = 5)
```