1

Is it possible to generate a graph in R given the number of edges and the number of nodes?

1 Answer 1

4

Does erdos.renyi.game, that generates graphs according to the Erdős–Rényi model, suit your needs?

erdos.renyi.game(n, p.or.m, type=c("gnp", "gnm"), directed = FALSE, loops = FALSE, ...)

Arguments

n: The number of vertices in the graph.

p.or.m: Either the probability for drawing an edge between two arbitrary vertices (G(n,p) graph), or the number of edges in the graph (for G(n,m) graphs).

type: The type of the random graph to create, either gnp (G(n,p) graph) or gnm (G(n,m) graph).

directed: Logical, whether the graph will be directed, defaults to FALSE.

loops: Logical, whether to add loop edges, defaults to FALSE. ...

[...]

In G(n,p) graphs, the graph has ‘n’ vertices and for each edge the probability that it is present in the graph is ‘p’.

In G(n,m) graphs, the graph has ‘n’ vertices and ‘m’ edges, and the ‘m’ edges are chosen uniformly randomly from the set of all possible edges. This set includes loop edges as well if the loops parameter is TRUE.

1
  • Yes, it suits. I did not realize that erdos-renyie model accepts (m , n) Thanks
    – M.M
    Nov 18, 2013 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.