Learn R Programming

gmat (version 0.2.1)

rgraph: Random generation of acyclic digraphs and undirected graphs

Description

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

Usage

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.

Value

The generated graph.

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.

Examples

Run this code
# NOT RUN {
## 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)
# }

Run the code above in your browser using DataLab