These functions allow mobility games to be played upon networks.
play_mobility() moves the occupants of a network of places
to empty places, as in Schelling's model of segregation,
in vacancy chains, or in migration.
Each node is a place, which holds at most one occupant.
The nodal attributes describe the occupant of the place,
and a missing value of attribute marks a place as empty.
When an occupant moves, all its attributes move with it.
Only the attributes of the place stay where they are:
the node labels, which name the places, the nodes' mode (type),
and whether the place is active.
At each step, the occupants that are dissatisfied with their place are
checked in the order given by who_moves.
The first of them that has an empty place to go to,
within max_dist of its place,
moves to the place that choice_function chooses.
The game stops after steps moves,
or when no dissatisfied occupant has a place to go to.
A network.
For as_mobility(), a network of places with a record of occupant
in its changes, such as play_mobility() gives, or a 'mobilityModel'.
A string naming some nodal attribute in the network. A missing value marks an empty place. Currently only tested for binary attributes.
What satisfies an occupant with its place. Either a number, or a function.
A number is a threshold from -1 to 1 on the E-I index of the occupant's
neighbours on attribute,
above which the occupant is dissatisfied.
One number gives the same threshold to every occupant,
and a vector as long as the nodes of the network gives each occupant
its own threshold, which moves with it.
By default this is 0, meaning occupants will be dissatisfied if more than
half of their neighbours differ on the given attribute.
A function takes the network (as an 'igraph') and the index of a node, in this order, and returns the satisfaction of the occupant of that node as one number. An occupant with a satisfaction below 0 is dissatisfied. This allows other preferences, such as a continuous utility.
The order in which dissatisfied occupants are checked,
one of the following options:
"ordered" (the default) checks them in the order of the nodes,
"random" checks them in a random order,
and "most_dissatisfied" checks the most dissatisfied first.
Alternatively, a function that takes the network and returns
one score for each node, such as netrics::node_by_degree.
The occupants are then checked from the highest score to the lowest.
The empty place that a moving occupant chooses, one of the following options: "satisficing" (the default) chooses at random among the places that would satisfy it, "optimising" chooses the place that would satisfy it most, and "minimising" chooses the nearest of the places that would satisfy it. With "satisficing" or "minimising", an occupant that no empty place would satisfy does not move, and the next occupant is checked. Alternatively, a function that takes the network and returns one score for each node. The occupant then chooses the empty place with the highest score.
The maximum distance along ties from an occupant's place to
an empty place that it can move to.
By default Inf, so that an occupant can move to any empty place,
whether or not there is a path to it.
In a directed network, distances follow the direction of the ties.
With max_dist = 1 on a directed network of positions,
an occupant can move only to a next position,
so that vacancy chains follow from the empty places.
The maximum number of moves. By default the number of nodes in the network.
Former names of arguments, which still work but are deprecated:
heterophily for preference.
as_mobility() returns a 'mobilityModel' (a tibble),
with one row for each move:
the time of the move, the person who moves (the occupant),
the node index of the origin and of the destination,
the value of attribute for the person
(in a column with the name of the attribute,
or value if another column has that name),
and the number of occupants that are dissatisfied after the move.
dissatisfied is NA if the network has no satisfied record.
The network of the class it was given,
with the occupants in their start places,
and a record of the moves in its changes.
Each move is one step of time.
At each move, the record gives the new value of each attribute
of the occupant at the two places, and the satisfied value
of each occupant whose satisfaction changes.
Use to_time() to get the network at a step,
as_mobility() to get a table of the moves,
and to_mobility() to get the moves as a network of places.
Two node attributes are added at the start.
occupant names the occupant of each place, with NA for an empty place.
A network that already has an occupant attribute keeps it.
Otherwise, each occupant has the index of its start place as its name.
satisfied is TRUE for an occupant that is satisfied with its place,
FALSE for an occupant that is dissatisfied,
and NA for an empty place.
A 'stocnet' also keeps attribute, and preference if it is a number,
in info$mobility.
Schelling, Thomas C. 1971. "Dynamic Models of Segregation." Journal of Mathematical Sociology 1(2): 143-186. doi:10.1080/0022250X.1971.9989794
Other makes:
as_diffusion(),
as_opinion(),
make_bibliography,
make_create,
make_ego,
make_emails,
make_explicit,
make_groups,
make_growth,
make_packages,
make_random,
make_read,
make_statements,
make_text,
make_write
Other models:
as_diffusion(),
as_opinion()
startValues <- rbinom(100,1,prob = 0.5)
startValues[sample(seq_len(100), round(100*0.2))] <- NA
latticeEg <- create_lattice(100)
latticeEg <- add_node_attribute(latticeEg, "startValues", startValues)
latticeEg
#>
#> ── # Lattice network ───────────────────────────────────────────────────────────
#> # A undirected network of 100 nodes and 342 ties
#>
#> ── Nodes
#> # A tibble: 100 × 1
#> startValues
#> <int>
#> 1 0
#> 2 1
#> 3 NA
#> 4 0
#> 5 0
#> 6 1
#> # ℹ 94 more rows
#>
#> ── Ties
#> # 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
#>
schelling <- play_mobility(latticeEg, "startValues", 0.5)
# The network after the last move
to_time(schelling, max(as_changelist(schelling)$time))
#> ── # Lattice network ───────────────────────────────────────────────────────────
#> # A undirected network of 100 nodes and 342 ties
#>
#> ── Nodes
#> # A tibble: 100 × 3
#> startValues occupant satisfied
#> <dbl> <chr> <lgl>
#> 1 0 1 TRUE
#> 2 0 96 TRUE
#> 3 NA NA NA
#> 4 0 4 TRUE
#> 5 0 5 TRUE
#> 6 NA NA NA
#> # ℹ 94 more rows
#>
#> ── Ties
#> # 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
#>
# A vacancy chain: a person moves up one position when it is empty
ladder <- delete_ties(create_ring(10, directed = TRUE), 10)
ladder <- add_node_attribute(ladder, "person", c(LETTERS[1:9], NA))
chain <- play_mobility(ladder, "person",
preference = function(.data, node) -1,
choice_function = "optimising", max_dist = 1)
as_mobility(chain, "person")
#> # A tibble: 9 × 6
#> time person origin destination value dissatisfied
#> <dbl> <chr> <int> <int> <chr> <int>
#> 1 1 9 9 10 I 9
#> 2 2 8 8 9 H 9
#> 3 3 7 7 8 G 9
#> 4 4 6 6 7 F 9
#> 5 5 5 5 6 E 9
#> 6 6 4 4 5 D 9
#> 7 7 3 3 4 C 9
#> 8 8 2 2 3 B 9
#> 9 9 1 1 2 A 9