How to simulate a graph with Assortativity or Homophily in R?

百般思念 提交于 2019-12-13 02:31:20

问题


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!


回答1:


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 (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)

You can move the network back into igraph with asIgraph from the intergraph package.



来源:https://stackoverflow.com/questions/50097720/how-to-simulate-a-graph-with-assortativity-or-homophily-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!