首页 > 解决方案 > 如何在 R 中模拟具有 Assortativity 或 Homophily 的图?

问题描述

R,我目前正在使用包igraph。我想知道是否有任何方法可以模拟具有同质性或分类性结构的图形 - 或者其他R软件包是否允许这样做。谢谢!

标签: rigraph

解决方案


你看过ergm包吗?使用指数随机图模型,您可以模拟带有nodematch术语的分类网络。有关该术语的说明,请参见?"ergm-terms"

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

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包将网络移回 igraph 。


推荐阅读