These functions are similar to the create_* functions, but include some element of randomisation. They are particularly useful for creating a distribution of networks for exploring or testing network properties. The networks here grow: nodes arrive one at a time, and each new node ties to nodes that arrived before it. The functions differ in how a new node chooses whom to tie to.

  • generate_scalefree() generates a scale-free structure via preferential attachment at some probability.

  • generate_fire() generates a forest fire model.

  • generate_citations() generates a citations model, in which each new node cites some of the nodes before it.

These functions can create either one-mode or two-mode networks. To create a one-mode network, pass the main argument n a single integer, indicating the number of nodes in the network. To create a two-mode network, pass n a vector of two integers, where the first integer indicates the number of nodes in the first mode, and the second integer indicates the number of nodes in the second mode. As an alternative, an existing network can be provided to n and the number of modes, nodes, and directedness will be inferred.

generate_scalefree(n, p = 1, directed = FALSE)

generate_fire(n, p = 0, directed = FALSE, contacts = 1, their_in = 1, ...)

generate_citations(
  n,
  p = 1,
  directed = FALSE,
  degree = sample(1:4, 1),
  agebins = max(1, n/10),
  ...
)

Arguments

n

Given:

  • A single integer, e.g. n = 10, a one-mode network will be created.

  • A vector of two integers, e.g. n = c(5,10), a two-mode network will be created.

  • A manynet-compatible object, a network of the same dimensions will be created.

p

The main probability of the model, which is what makes a network of it more or less random. It always follows n, and what it is the probability of depends on the model. For generate_scalefree(), it is the power of the preferential attachment, by default 1. For generate_fire(), it is the probability that the fire burns along each tie that a contact sends, and so that the new node ties to the node at its other end, by default 0. In a two-mode network, it is instead the probability of burning across each two-path, and so of closing a four-cycle. For generate_citations(), it is the probability that a node chooses each node that it cites at random, by default 1, where it otherwise cites the node that came most recently, so that 0 returns the same network every time.

directed

Logical whether the network should be directed. By default directed = FALSE, but for the functions that the usage above shows another default for. A network given as n sets the direction instead. If the opposite direction is desired, use to_redirected() on the output of these functions. In two-mode networks, the directed argument is ignored.

contacts

Number of contacts or ambassadors chosen from among existing nodes in the network. By default 1. See igraph::sample_forestfire().

their_in

Probability of tieing to a contact's incoming ties. By default 1. This is a factor on p rather than a probability in its own right, so p = 0 gives a tree whatever their_in is set to. In a two-mode network, p * their_in is instead the probability that a newly burned node re-ignites and spreads the fire further.

...

Arguments under the names they had in earlier versions, which still work: their_out for p in generate_fire(), and ties for degree in generate_citations().

degree

The number of ties that a node sends. For generate_citations(), this is how many of the nodes before it each new node cites, by default a random number from 1 to 4. Inf has each node cite every node before it. In a two-mode network, each new node of the first mode ties to this many nodes of the second mode.

agebins

Number of aging bins. By default either \(\frac{n}{10}\) or 1, whichever is the larger. See igraphr::sample_last_cit() for more.

Value

A stocnet object is returned, which can be coerced into other types of objects using as_edgelist(), as_matrix(), as_tidygraph(), as_igraph(), or as_network(). create_ring(), create_lattice(), generate_random(), generate_smallworld(), and generate_scalefree() return a tbl_graph or igraph object for now, since the released versions of the packages built on this one expect one from them.

By default, most networks are created as undirected. This can be overruled with the argument directed = TRUE. This will return a directed network in which the arcs are out-facing or equivalent. This direction can be swapped using to_redirected(). In two-mode networks, the directed argument is ignored.

Details

In a one-mode network, each burn step is a single hop, so each tie the fire creates closes a triangle. A tie in a two-mode network crosses modes, so the shortest closure there is the four-cycle rather than the triangle. In a two-mode network each burn step is therefore a two-path hop across the other mode, and each tie the fire creates closes a four-cycle. Both modes grow over the course of the simulation.

In generate_citations(), a node that chooses at random whom to cite prefers the nodes that were cited most recently. With p = 0 nothing is left to chance, and each node cites the degree nodes that arrived just before it. With degree = Inf as well, each node cites every node before it, which in a directed network is the complete citation network that tidygraph::create_citation() returns. With p = 1 a node can cite another more than once.

References

On scale-free networks

Barabasi, Albert-Laszlo, and Reka Albert. 1999. “Emergence of Scaling in Random Networks.” Science 286(5439):509–12. doi:10.1126/science.286.5439.509

On the forest-fire model

Leskovec, Jure, Jon Kleinberg, and Christos Faloutsos. 2007. "Graph evolution: Densification and shrinking diameters". ACM transactions on Knowledge Discovery from Data, 1(1): 2-es. doi:10.1145/1217299.1217301

Examples

generate_scalefree(12, 0.25)
#> IGRAPH 6e46ef0 U--- 12 11 -- Barabasi graph
#> + attr: name (g/c), power (g/n), m (g/n), zero.appeal (g/n), algorithm
#> | (g/c)
#> + edges from 6e46ef0:
#>  [1]  1-- 2  1-- 3  1-- 4  1-- 5  2-- 6  4-- 7  3-- 8  3-- 9  4--10  9--11
#> [11] 10--12
generate_scalefree(12, 1.25)
#> IGRAPH 48adb44 U--- 12 11 -- Barabasi graph
#> + attr: name (g/c), power (g/n), m (g/n), zero.appeal (g/n), algorithm
#> | (g/c)
#> + edges from 48adb44:
#>  [1] 1-- 2 1-- 3 1-- 4 3-- 5 4-- 6 4-- 7 1-- 8 3-- 9 6--10 4--11 6--12
generate_fire(10)
#> 
#> ── # Forest fire network ───────────────────────────────────────────────────────
#> # A undirected network of 10 nodes and 9 ties
#> 
#> ── Ties 
#> # A tibble: 9 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     1     3
#> 3     3     4
#> 4     1     5
#> 5     5     6
#> 6     5     7
#> # ℹ 3 more rows
#> 
generate_fire(10, p = 0.3)
#> ── # Forest fire network ───────────────────────────────────────────────────────
#> # A undirected network of 10 nodes and 12 ties
#> 
#> ── Ties 
#> # A tibble: 12 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     2     3
#> 3     3     4
#> 4     2     4
#> 5     3     5
#> 6     4     6
#> # ℹ 6 more rows
#> 
generate_fire(c(10, 6))
#> ── # Forest fire network ───────────────────────────────────────────────────────
#> # A two-mode network of 10 FALSEs and 6 TRUEs and 15 ties
#> 
#> ── Nodes 
#> # A tibble: 16 × 1
#>   mode 
#>   <chr>
#> 1 FALSE
#> 2 FALSE
#> 3 FALSE
#> 4 FALSE
#> 5 FALSE
#> 6 FALSE
#> # ℹ 10 more rows
#> 
#> ── Ties 
#> # A tibble: 15 × 2
#>    from    to
#>   <int> <int>
#> 1     1    11
#> 2     1    15
#> 3     2    11
#> 4     2    14
#> 5     3    11
#> 6     3    12
#> # ℹ 9 more rows
#> 
generate_citations(10)
#> ── # Citations network ─────────────────────────────────────────────────────────
#> # A undirected network of 10 nodes and 18 ties (8 parallel)
#> 
#> ── Ties 
#> # A tibble: 18 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     1     2
#> 3     1     3
#> 4     2     3
#> 5     1     4
#> 6     3     4
#> # ℹ 12 more rows
#> 
generate_citations(10, p = 0.5, directed = TRUE, degree = 3)
#> ── # Citations network ─────────────────────────────────────────────────────────
#> # A directed network of 10 nodes and 24 arcs
#> 
#> ── Ties 
#> # A tibble: 24 × 2
#>    from    to
#>   <int> <int>
#> 1     2     1
#> 2     3     2
#> 3     3     1
#> 4     4     3
#> 5     4     1
#> 6     4     2
#> # ℹ 18 more rows
#> 
generate_citations(10, p = 0, directed = TRUE, degree = Inf)
#> ── # Citations network ─────────────────────────────────────────────────────────
#> # A directed network of 10 nodes and 45 arcs
#> 
#> ── Ties 
#> # A tibble: 45 × 2
#>    from    to
#>   <int> <int>
#> 1     2     1
#> 2     3     1
#> 3     3     2
#> 4     4     1
#> 5     4     2
#> 6     4     3
#> # ℹ 39 more rows
#> 
generate_citations(c(10, 6))
#> ── # Citations network ─────────────────────────────────────────────────────────
#> # A two-mode network of 10 FALSEs and 6 TRUEs and 9 ties
#> 
#> ── Nodes 
#> # A tibble: 16 × 1
#>   mode 
#>   <chr>
#> 1 FALSE
#> 2 FALSE
#> 3 FALSE
#> 4 FALSE
#> 5 FALSE
#> 6 FALSE
#> # ℹ 10 more rows
#> 
#> ── Ties 
#> # A tibble: 9 × 2
#>    from    to
#>   <int> <int>
#> 1     2    11
#> 2     3    11
#> 3     4    12
#> 4     5    12
#> 5     6    13
#> 6     7    14
#> # ℹ 3 more rows
#>