在r中生成随机图(Generating random graph in r)

编程入门 行业动态 更新时间:2024-10-28 07:21:19
在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

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

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

I would like to generate a grandom graph in R using any of the packages.

The desired output would be a two column matrix with the first column listing agents and the second column their connections of the following form:

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

I would like to be able to specify the average degree and minimum and maximum number of contacts.

What is the easiest way of doing this?

最满意答案

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

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

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

Since you don't specify the need for anything other than just a graph we ca do this very simply:

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

if you want something more specific have a look at igraph for instance

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

or using package bipartite which focuses specifically on two mode networks:

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

There are many things to take into account, for instance if you want to constrain the degree distribution, probablity of ties between agents etc.

更多推荐

本文发布于:2023-07-28 04:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1300339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Generating   random   graph

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!