Generate a random graph

create_random_graph(
  n_vertices,
  strategy = c("gnp", "gnm"),
  p,
  m,
  directed = TRUE,
  graph = c("igraph", "network")
)

Arguments

n_vertices

integer, number of vertices to include in the graph

strategy

Character scalar, the type of the graph, ‘gnp’ creates a $G(n,p)$ graph, ‘gnm’ creates a $G(n,m)$ graph. See details below.

p

probability for $G(n,p)$ graphs. Should not be given for $G(n,m)$ graphs.

m

integer, the number of edges for $G(n,p)$ graphs. Should not be given for $G(n,p)$ graphs.

directed

logical, whether to create a directed graph

graph

character, the type of graph to be generated: igraph or network

Value

a graph of class network or igraph

Details

Generate a random network, either as a igraph or network object.

When using strategy 'gnp', a bipartite network is generated where each edge has probability 'p' of occuring. This means that consecutive runs of the algorithm will usually result in graphs with different numbers of edges.

When using strategy 'gnm', a bipartite network is generated with exactly 'm' edges. This means that consecutive runs of the algorithm will result in graphs with the same number of edges (but will occur between different vertices).

Examples

create_random_graph(n_vertices = 10, "gnp", p = .25, graph = "igraph")
#> IGRAPH ca4382b D--- 10 17 -- Erdos-Renyi (gnp) graph
#> + attr: name (g/c), type (g/c), loops (g/l), p (g/n)
#> + edges from ca4382b:
#>  [1]  8-> 1  1-> 2  6-> 2  2-> 3  8-> 3  2-> 4  4->10  6-> 4  5->10  6->10
#> [11]  1-> 7  3-> 7  4-> 7 10-> 7  1-> 8  4-> 8  9-> 8
create_random_graph(n_vertices = 10, "gnp", p = .25, graph = "network")
#>  Network attributes:
#>   vertices = 10 
#>   directed = TRUE 
#>   hyper = FALSE 
#>   loops = FALSE 
#>   multiple = FALSE 
#>   bipartite = FALSE 
#>   total edges= 24 
#>     missing edges= 0 
#>     non-missing edges= 24 
#> 
#>  Vertex attribute names: 
#>     vertex.names 
#> 
#> No edge attributes
create_random_graph(n_vertices = 10, "gnm", m = 15, graph = "igraph")
#> IGRAPH ca44d53 D--- 10 15 -- Erdos-Renyi (gnm) graph
#> + attr: name (g/c), type (g/c), loops (g/l), m (g/n)
#> + edges from ca44d53:
#>  [1]  1-> 7  1-> 9  3->10  4-> 1  4-> 2  5->10  6-> 4  7-> 2  8-> 4  8-> 5
#> [11]  8-> 7  9-> 1  9-> 3 10-> 6 10-> 7
create_random_graph(n_vertices = 10, "gnm", m = 15, graph = "network")
#>  Network attributes:
#>   vertices = 10 
#>   directed = TRUE 
#>   hyper = FALSE 
#>   loops = FALSE 
#>   multiple = FALSE 
#>   bipartite = FALSE 
#>   total edges= 15 
#>     missing edges= 0 
#>     non-missing edges= 15 
#> 
#>  Vertex attribute names: 
#>     vertex.names 
#> 
#> No edge attributes