繁体   English   中英

在r中生成随机图

[英]Generating random graph in r

我想使用任何软件包在R中生成一个grandom图。

所需的输出是两列矩阵,第一列列出代理,第二列是以下形式的连接:

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

我希望能够指定平均度数以及最小和最大联系人数。

这样做最简单的方法是什么?

由于您没有指定除图表以外的任何其他内容,因此我们可以非常简单地执行此操作:

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

如果你想要更具体的东西,请查看igraph

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

有许多事情需要考虑,例如,如果你想限制学位分布,代理人之间关系的可能性等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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