我想使用任何软件包在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 5I 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 networkor 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 nodeThere are many things to take into account, for instance if you want to constrain the degree distribution, probablity of ties between agents etc.
更多推荐
发布评论