Search code examples
rsocial-networking

Generating multiple random graphs in R with same number of nodes and ties?


I would like to generate a large number of random graphs with the same number of nodes and ties, and use the result to find the distributions etc of the standard metrics.

I found this link for generating random graphs with a given number of nodes and ties (Graph generation given number of edges and nodes). Is there an easy way to tell R to do this 1000x or so, and combine all of those into one object, that I can then analyze? (for things like av. distance, degree, diameter, etc).

Ultimately I want to be able to use this information for comparison with an empirical network.


Solution

  • I got this answer from a friend, and it appears to work:

    RR1 <- list()
     for(i in 1:1000) {
    RR1[[i]] <- erdos.renyi.game(559,9640,type=c("gnm"),directed=FALSE,loops=FALSE)
    }
    number_of_edges <- sapply(RR1, gsize)
    number_of_edges