rgraph: Random generation of acyclic digraphs and undirected graphs

Description Usage Arguments Details Value Examples

View source: R/utils.R

Description

Wrapper of functionality from package igraph for random generation of graphs.

Usage

1
rgraph(p, d, dag = FALSE, ordered = TRUE)

Arguments

p

Number of vertices of the sampled graph.

d

Proportion of edges in the generated graph.

dag

Whether the generated graph should be acyclic directed.

ordered

When generating an acyclic directed graph, whether the nodes should follow the ancestral order 1, ..., p.

Details

When dag = FALSE, the graph is sampled from an Erdos-Renyi model. In the case where dag = TRUE, the upper triangle of the adjacency matrix of an Erdos-Renyi model is taken as the adjacency matrix for the acyclic digraph. This preserves the proportion of edges d.

Value

The generated graph.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Random undirected graph with 3 nodes and 50% density of edges
rgraph(p = 3, d = 0.5)

## Random directed acyclic graphs
# Following the natural ancestral order 1, ..., p
dag <- rgraph(p = 6, d = 0.5, dag = TRUE)
igraph::topo_sort(dag)

# Following a random ancestral order
dag <- rgraph(p = 6, d = 0.5, dag = TRUE, ordered = FALSE)
igraph::topo_sort(dag)

Example output

IGRAPH e467261 U--- 3 2 -- Erdos renyi (gnp) graph
+ attr: name (g/c), type (g/c), loops (g/l), p (g/n)
+ edges from e467261:
[1] 1--3 2--3
+ 6/6 vertices, from c09dbfe:
[1] 1 2 3 4 5 6
+ 6/6 vertices, from 2a01762:
[1] 2 6 1 4 3 5

gmat documentation built on Aug. 30, 2020, 9:07 a.m.