简体   繁体   中英

How to generate a series of random networks in R

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 (ie 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM