rgraph: Random generation of acyclic digraphs and undirected graphs

View source: R/utils.R

rgraphR Documentation

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.

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

## 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)

irenecrsn/gmat documentation built on May 9, 2022, 1:11 a.m.