0

I am an R beginner, so please bear with me.

I am attempting to create a set of around 100 random networks, to compare with my original network of 60 nodes and 246 weighted links.

I would like each network to have a random number of nodes between 0-100, each with a random density (i.e. random probability that any one node will connect with another), and randomly weighted edges between 1-5.

I'm very new to network analysis in R, so I am not sure how to create a script that allows me to output 100 of these (guessing with a loop), nor how to specify random edge densities and weights.

Any advice would be great.

epaul
  • 23
  • 6
  • Write a function that makes one random network with the characteristics you want. Then run it in a loop. What have you tried? What packages/class of networks are you using? Where exactly are you stuck? If you wanted to create a network with 2 nodes and a connection between them, can you do that? What about `n` nodes if you know `n`? Do you know how to draw random numbers in R? Do you know what distribution you would like to draw from for the number of nodes? Uniform on 0-100, or poisson with mean 50 or normal or something else? – Gregor Thomas Oct 05 '16 at 18:31
  • This isn't a great place for general advice - it is a good place to help you get past specific stumbling blocks. Maybe have a look at [How to make a reproducible example](http://stackoverflow.com/q/5963269/903061) and try asking a specific question relating to your immediate issue. – Gregor Thomas Oct 05 '16 at 18:33

1 Answers1

0

igraph is a good start:

library(igraph)
set.seed(1)
gs <- list()
for (x in seq_len(100L)) {
  gs[[x]] <- erdos.renyi.game(sample(1:100, 1), p.or.m = runif(1))
  E(gs[[x]])$weight <- sample(1:5, ecount(gs[[x]]), T)
}
plot(gs[[1]], edge.width = E(gs[[1]])$weight) # plot first graph

See ?erdos.renyi.game for the documentation on the random graph generation.

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • @lukaA that is fantastic, and I think should work perfectly for what I need to do. If not, I will try and see if I know enough to modify it. I was mostly stuck because I had never written a loop before, and had no idea how to approach it.@Gregor: Just to answer your question (and thank you for your advice) I have tried using igraph as my basis, specifically erdos.renyi.game. My limitations are knowing what the function can/can't do, or what I can/can't modify.Thank you both for your help, and I'll try to ask more specific questions as I work through this! – epaul Oct 05 '16 at 19:38