2013-01-03 51 views
3

我想使用任何軟件包在R中生成一個grandom圖。在r中生成隨機圖

所需的輸出將是一個兩列的矩陣與所述第一列列出劑和第二列的以下形式的連接:

1 3 
1 4 
1 6 
1 7 
2 2 
2 5 
3 9 
3 11 
3 32 
3 43 
3 2 
4 5 

我想是能夠指定的平均程度和最小和最大聯繫人數量。

這樣做的最簡單方法是什麼?

回答

7

既然你不指定需要的不僅僅是一個圖形其他任何我們CA做到這一點很乾脆:如果您想更具體的東西看看igraph例如

actor  <- sample(1:4, 10, replace=TRUE) 
receiver <- sample(3:43, 10, replace=TRUE) 
graph  <- cbind(actor,receiver) 

library(igraph) 
graph <- erdos.renyi.game(21, 0.3, type=c("gnp", "gnm"), 
       directed = FALSE, loops = FALSE) 

# here the 0.3 is the probability of ties and 21 is the number of nodes 
# this is a one mode network 

或使用包bipartite這兩個模式網絡特別關注:

library(bipartite) 
web <- genweb(N1 = 5, N2 = 10, dens = 2) 
web2edges(web,return=TRUE) 

# here N1 is the number of nodes in set 1 and N2 the number of nodes in set 2 
# and dens the average number of ties per node 

有很多事情需要考慮,例如,如果你想約束程度分佈,代理人之間的聯繫的可能性等。

+0

是的,這是我想要的東西。這和社交網絡中的隨機圖本質上是一樣的嗎? PS。只是爲了獲得更多的洞察力:你指的是什麼樣的東西:「除了只是一個圖表之外的其他需求」? – user1723765

+0

對不起,我只是意識到我的問題缺少必要的部分。我編輯過它。抱歉 – user1723765