0

I'm using R to generate a DAG (Directed Acyclic graph). With the following code I generate an Erdős–Rényi graph.

library(igraph)
aph <- erdos.renyi.game(12, 0.1, type=c("gnp", "gnm"),
                          directed = TRUE, loops = FALSE)

The problem is that even it says that

directed = TRUE ,`loops = FALSE`

the code is still generating loops and the graphs are not directed. In image 1 the vertex 2 and 11 contains an bidirectional edge. Also in image 2 there is a loop from nodes 6, 9 and 7.

First graph

Second graph

How can I solve this problem and generate a correct DAG?

Caleb
  • 179
  • 2
  • 17
  • Hi! The graph is directed, it can just have an edge that goes from A to B and another one that goes fromB to A. I'll look up about the loops :) What's your desired result? A DAG right? – Ale Jan 27 '17 at 11:07
  • Well a directed graph with orientation, i.e., If there is a path from A to B then it should not be a path from B to A. – Caleb Jan 27 '17 at 11:57

1 Answers1

0

To generate a random DAG you can use the pcalg library

library(pcalg)
set.seed(101)
myDAG <- randomDAG(n = 20, prob= 0.2, lB = 0.1, uB = 1)
plot(myDAG)
Ale
  • 946
  • 4
  • 17
  • 28
  • I'm using Ubuntu 16.04 and in this environment there are some errors when installing the pcalg package. There are missing packages that are not available in CRAN. Therefore, they have to be installed in this way. Please check [here](http://stackoverflow.com/questions/25434335/how-to-plot-a-complete-graph-in-r/25434810) and [here](http://stackoverflow.com/questions/18023300/is-rgraphviz-no-longer-available-for-r). – Caleb Jan 27 '17 at 12:30