randDAG {pcalg} | R Documentation |
Random DAG Generation
Description
Generating random directed acyclic graphs (DAGs) with fixed expected
number of neighbours. Several different methods are provided, each
intentionally biased towards certain properties. The methods are based
on the analogue *.game
functions in the igraph package.
Usage
randDAG(n, d, method ="er", par1=NULL, par2=NULL,
DAG = TRUE, weighted = TRUE, wFUN = list(runif, min=0.1, max=1))
Arguments
n |
integer, at least |
d |
a positive number, corresponding to the expected number of neighbours per node, more precisely the expected sum of the in- and out-degree. |
method |
a string, specifying the method used for generating the random graph. See details below. |
par1 , par2 |
optional additional arguments, dependent on the method. See details. |
DAG |
logical, if |
weighted |
logical indicating if edge weights are computed according to |
wFUN |
a |
Details
A (weighted) random graph with n
nodes and expected number of
neighbours d
is constructed. For DAG=TRUE
, the graph is
oriented to a DAG. There are eight different random graph models
provided, each selectable by the parameters method
,
par1
and par2
, with method
, a string,
taking one of the following values:
regular
:Graph where every node has exactly
d
incident edges.par1
andpar2
are not used.watts
:Watts-Strogatz graph that interpolates between the regular (
par1->0
) and Erdoes-Renyi graph (par1->1
). The parameterpar1
is per default0.5
and has to be in(0,1)
.par2
is not used.er
:Erdoes-Renyi graph where every edge is present independently.
par1
andpar2
are not used.power
:A graph with power-law degree distribution with expectation
d
.par1
andpar2
are not used.bipartite
:Bipartite graph with at least
par1*n
nodes in group 1 and at most(1-par1)*n
nodes in group 2. The argumentpar1
has to be in[0,1]
and is per default0.5
.par2
is not used.barabasi
:A graph with power-law degree distribution and preferential attachement according to parameter
par1
. It must hold thatpar1 >= 1
and the default ispar1=1
.par2
is not used.geometric
:A geometric random graph in dimension
par1
, wherepar1
can take values from{2,3,4,5}
and is per default2
. Ifpar2="geo"
andweighted=TRUE
, then the weights are computed according to the Euclidean distance. There are currently no other option forpar2
implemented.interEr
:A graph with
par1
islands of Erdoes-Renyi graphs, every pair of those connected by a certain number of edges proportional topar2
(fraction of inter-connectivity). It is required thatn/s
be integer andpar2
in(0,1)
. Defaults arepar1=2
andpar2=0.25
, respectively.
Value
A graph object of class graphNEL
.
Note
The output is not topologically sorted (as opposed to the
output of randomDAG
).
Author(s)
Markus Kalisch (kalisch@stat.math.ethz.ch) and Manuel Schuerch.
References
These methods are mainly based on the analogue functions in the igraph package.
See Also
the package igraph
, notably help pages such as
sample_k_regular
or sample_smallworld
;
unifDAG
from package unifDAG for generating uniform random DAGs.
randomDAG
a limited and soon deprecated version of randDAG
;
rmvDAG
for generating multivariate data according to a DAG.
Examples
set.seed(37)
dag1 <- randDAG(10, 4, "regular")
dag2 <- randDAG(10, 4, "watts")
dag3 <- randDAG(10, 4, "er")
dag4 <- randDAG(10, 4, "power")
dag5 <- randDAG(10, 4, "bipartite")
dag6 <- randDAG(10, 4, "barabasi")
dag7 <- randDAG(10, 4, "geometric")
dag8 <- randDAG(10, 4, "interEr", par2 = 0.5)
## require("Rgraphviz")
par(mfrow=c(4,2))
plot(dag1,main="Regular graph")
plot(dag2,main="Watts-Strogatz graph")
plot(dag3,main="Erdoes-Renyi graph")
plot(dag4,main="Power-law graph")
plot(dag5,main="Bipartite graph")
plot(dag6,main="Barabasi graph")
plot(dag7,main="Geometric random graph")
plot(dag8,main="Interconnected island graph")
set.seed(45)
dag0 <- randDAG(6,3)
dag1 <- randDAG(6,3, weighted=FALSE)
dag2 <- randDAG(6,3, DAG=FALSE)
par(mfrow=c(1,2))
plot(dag1)
plot(dag2) ## undirected graph
dag0@edgeData ## note the uniform weights between 0.1 and 1
dag1@edgeData ## note the constant weights
wFUN <- function(m,lB,uB) { runif(m,lB,uB) }
dag <- randDAG(6,3,wFUN=list(wFUN,1,4))
dag@edgeData ## note the uniform weights between 1 and 4