Learn R Programming

pcalg (version 2.4-3)

randDAG: 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 2, indicating the number of nodes in the DAG.
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 TRUE, labelled graph is directed to a labelled acyclic graph.
weighted
logical indicating if edge weights are computed according to wFUN.
wFUN
a function for computing the edge weights in the DAG. It takes as first argument a number of edges m for which it returns a vector of length m containing the weights. Alternatively, wFUN can be a list consisting of the function in the first entry and of further arguments of the function in the additional entries. The default (only if weighted is true) is a uniform weight in $[0.1, 1]$. See the examples for more.

Value

A graph object of class graphNEL.

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:

References

These methods are mainly based on the analogue functions in the igraph package.

See Also

the package igraph, notably help pages such as random.graph.game or barabasi.game;

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

Run this code
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

Run the code above in your browser using DataLab