2017-10-29 73 views
1

我真的很陌生,我已經爲我的課程分配了任務。我必須創建1000個Erdos-Renyi模型的網絡。事情是,我實際上可以創建一個模型,檢查它的參數,如度分佈,繪製等等。還可以檢查其傳遞性等。但是,我必須將這1000個網絡的平均聚類係數(本地傳遞性)與我們一直在Cytoscape中處理類的網絡進行比較。這是我已經知道的代碼:鄂爾多斯 - 仁義圖複製

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 

我必須從這1000個網絡計算標準偏差和平均ACC,然後進行比較。 我會很感激任何形式的幫助。

我嘗試了很多實際:

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 

而且,我已經嘗試統一圖的列表

glist<-1000*g 
acc<-union(glist, byname="auto") 
transitivity(acc) #outputs the same value as first function g (only one 
#erdos-renyi graph 
+1

到目前爲止您嘗試過什麼?嘗試給我們一個[最小可重現的例子](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。我通常不會放縱別人的功課......你需要付出努力。 –

+0

你的'replicate'似乎不太正確:你想'g2 < - replicate(1000,erdos.renyi.game( 1000,2000,type = c(「gnm」)),simplify = FALSE); sapply(g2,及物性)' – user20650

+0

非常感謝!它真的有效。現在我可以通過使用均值(sapply(g2,transitive))來計算1000張圖的均值 – segway

回答

1

要乘多圖使用複製功能如下

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) 

要計算平均度數或傳遞性使用等一些屬性的平均值:

mean(sapply(g2, transitivity))