r - 如何在 R 中模拟具有 Assortativity 或 Homophily 的图?
问题描述
在R
,我目前正在使用包igraph
。我想知道是否有任何方法可以模拟具有同质性或分类性结构的图形 - 或者其他R
软件包是否允许这样做。谢谢!
解决方案
你看过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 。
推荐阅读
- java - JEP286 - 在增强的 for 循环中使用索引
- powershell - Powershell - 努力从变量位置复制文件
- python - Python Plotly:如何将图像添加到 3D 散点图中
- python - Matplotlib:将 Y 轴更改为对数刻度后,将 Y 轴设置为非科学记数法
- laravel - Laravel 上的 url 在本地工作,但在 AWS EC2 linux centos 7 上不工作
- javascript - 如何在 HTML 中显示消息并关闭设置窗口?
- python - 整数值不变
- mysql - 休眠创建表但没有影响
- arrays - 从 api 获取数据但得到的属性 'data' 在类型 'object' 上不存在
- mysql - MySQL Join 查询:两个主表和一个链接表