如何在R中模拟具有分类性或同质性的图? [英] How to simulate a graph with Assortativity or Homophily in R?
问题描述
在R
中,我当前正在使用软件包igraph
.我想知道是否有任何方法可以模拟具有同构或分类结构的图-还是其他R
包允许这样做.谢谢!
In R
, I am currently working with the package igraph
. I am wondering if there are any ways to simulate graphs with a homophilic or assortativity structure to it -- or if other R
packages allow for this. Thanks!
推荐答案
您是否看过 ergm 包?使用指数随机图模型,您可以模拟带有nodematch
项的分类网络.有关该术语的说明,请参见?"ergm-terms"
.
Have you looked at the ergm package? Using an exponential random graph model you can simulate an assortative network with a nodematch
term. See ?"ergm-terms"
for a description of the term.
library(ergm)
test.net = as.network(matrix(0,10,10), directed = F) #10-node network
test.net%v%"class" = sample(c('1','2'), 10, replace = T) #nodal attribute
simulate
(或simulate.formula
)一个网络,该网络的节点属性控制密度(edges
),同质性控制(nodematch
):
simulate
(or simulate.formula
) a network with a term that controls density (edges
) and one that controls homophily (nodematch
) on the nodal attribute:
test.sim = simulate(test.net ~ edges + nodematch("class"), coef = c(-1, 4))
plot(test.sim, vertex.col = as.numeric(test.net%v%"class"), vertex.cex = 2)
您可以使用asIgraph
从 intergraph 包.
这篇关于如何在R中模拟具有分类性或同质性的图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!