Learn R Programming

BCDAG (version 1.1.2)

rDAG: Generate a Directed Acyclic Graph (DAG) randomly

Description

This function randomly generates a Directed Acyclic Graph (DAG) with q nodes and probability of edge inclusion w.

Usage

rDAG(q, w)

Value

DAG \((q,q)\) adjacency matrix of the generated DAG

Arguments

q

number of nodes

w

probability of edge inclusion in \([0,1]\)

Details

The \(0-1\) adjacency matrix of the DAG is generated by drawing each element in the lower triangular part in \({0,1}\) with probability \({1-w, w}\). Accordingly, the DAG has lower-triangular adjacency matrix and nodes are numerically labeled according to a topological ordering implying \(u > v\) whenever \(u -> v\).

Examples

Run this code
# Randomly generate a DAG on q = 8 nodes with probability of edge inclusion w = 0.2
q = 8
w = 0.2
set.seed(123)
rDAG(q = q, w = w)

Run the code above in your browser using DataLab