segway
segway

Reputation: 21

Replication of Erdos-Renyi graph

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

Upvotes: 1

Views: 381

Answers (1)

segway
segway

Reputation: 21

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))

Upvotes: 1

Related Questions