问题
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