1

I'm really new to R and I have got an assignment for my classes. I have to create 1000 networks of Erdos-Renyi model. The thing is, I actually can create one model, check it parameters like degree distribution, plot it etc.. Also I can check its transitivity and so on. However, I have to compare the average clustering coefficient (local transitivity) of those 1000 networks to some network that we have been working on classes in Cytoscape. This is the code that I already know:

library(igraph) 
g<-erdos.renyi.game(1000,2000, type=c("gnm"))
transitivity(g) #and other atrributes...
g2<-replicate(g,1000)
transitivity(g2[[1]])
#now I have sort of list with every graph but when I try to analyze 
#I got the communicate that it is not a graph object

I have to calculate standard deviation and mean ACC from those 1000 networks, and then compare it. I will appreciate any kind of help.

I tried a lot actually:

g<-erdos.renyi.game(1026,2222,type=c("gnm"))
g2<-1000*g
transitivity(g2[2]) # this however ends in "not a graph object"error
g2[1] #outputs the adjacency matrix but instead of 1026 vertices,
#I've got 1026000 vertices, so multiplication doesn't replicate function
#but parameters 

Also, I have tried unifying the list of graphs

glist<-1000*g
acc<-union(glist, byname="auto")
transitivity(acc) #outputs the same value as first function g (only one 
#erdos-renyi graph
user20650
  • 24,654
  • 5
  • 56
  • 91
segway
  • 21
  • 3
  • 1
    What have you tried so far? Try giving us a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). I don't normally indulge doing other people's homework... you need to put the effort in. – Kevin Arseneau Oct 29 '17 at 03:11
  • your `replicate` doesn't seem quite correct : do you want `g2 <- replicate(1000, erdos.renyi.game(1000,2000, type=c("gnm")), simplify = FALSE) ; sapply(g2, transitivity)` – user20650 Oct 29 '17 at 12:24
  • Thank you so much!!! It really worked. Now I can calculate the mean from 1000 graphs by using mean(sapply(g2,transitivity)) – segway Oct 29 '17 at 13:15

1 Answers1

1

To multiply many graphs use replication function below

g<-erdos.renyi.game(100, 20, type=c("gnm"))
g2<-replicate(1000, erdos.renyi.game(100, 20, type=c("gnm")), simplify=FALSE); 
sapply(g2, transitivity)

To calculate mean of some attribute like average degree or transitivity use:

mean(sapply(g2, transitivity))
segway
  • 21
  • 3