Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

randomDAG

Generate a Directed Acyclic Graph (DAG) randomly


Description

Generate a random Directed Acyclic Graph (DAG). The resulting graph is topologically ordered from low to high node numbers.

Usage

randomDAG(n, prob, lB = 0.1, uB = 1, V = as.character(1:n))

Arguments

n

Number of nodes, N >= 2.

prob

Probability of connecting a node to another node with higher topological ordering.

lB, uB

Lower and upper limit of edge weights, chosen uniformly at random, i.e., by runif(., min=lB, max=uB).

V

character vector length n of node names.

Details

The n nodes are ordered. Start with first node. Let the number of nodes with higher order be k. Then, the number of neighbouring nodes is drawn as Bin(k, prob). The neighbours are then drawn without replacement from the nodes with higher order. For each node, a weight is uniformly sampled from lB to uB. This procedure is repeated for the next node in the original ordering and so on.

Value

An object of class "graphNEL", see graph-class from package graph, with n named ("1" to "n") nodes and directed edges. The graph is topologically ordered. Each edge has a weight between lB and uB.

Author(s)

Markus Kalisch (kalisch@stat.math.ethz.ch) and Martin Maechler

See Also

randDAG for a more elaborate version of this function; rmvDAG for generating data according to a DAG; compareGraphs for comparing the skeleton of a DAG with some other undirected graph (in terms of TPR, FPR and TDR).

Examples

set.seed(101)
myDAG <- randomDAG(n = 20, prob= 0.2, lB = 0.1, uB = 1)
## require(Rgraphviz)
plot(myDAG)

pcalg

Methods for Graphical Models and Causal Inference

v2.7-2
GPL (>= 2)
Authors
Markus Kalisch [aut, cre], Alain Hauser [aut], Martin Maechler [aut], Diego Colombo [ctb], Doris Entner [ctb], Patrik Hoyer [ctb], Antti Hyttinen [ctb], Jonas Peters [ctb], Nicoletta Andri [ctb], Emilija Perkovic [ctb], Preetam Nandy [ctb], Philipp Ruetimann [ctb], Daniel Stekhoven [ctb], Manuel Schuerch [ctb], Marco Eigenmann [ctb], Leonard Henckel [ctb], Joris Mooij [ctb]
Initial release
2021-4-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.