如何计算某个组节点之间的边数?

时间:2017-07-14 11:50:57

标签: r edge sna

我有以下数据集和以下脚本:

library(GGally)
library(ggnet)
library(network)
library(sna)
library(ggplot2)

# edgelist
e <- data.frame(sender = c(1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5),
                receiver = c(2, 3, 4, 5, 1, 3, 1, 1, 2, 2, 4, 3, 2, 4))

# information about the nodes (vertices)
v <- data.frame(actors = c(1, 2, 3, 4, 5),
                groups = c("A", "A", "B", "C", "D"))

net <- network(e, directed = TRUE)

x = data.frame(actors = network.vertex.names(net))
x = merge(x, v, by = "actors", sort = FALSE)$groups

net %v% "group" = as.character(x)

y = RColorBrewer::brewer.pal(9, "Set1")[ c(3, 1, 9, 6, 8) ]
names(y) = levels(x)

ggnet2(net, color = "group", palette = y, alpha = 0.75, size = 4, edge.alpha = 0.5, arrow.size = 8, arrow.gap = 0.01)

是否有一种简单快捷的方法来计算从一组节点(A,B,C,D)到同一组节点或另一组节点(即AA,AB,AC)的边数,AD,BA等)?

network.edgecount中有network-Package。但是我怎样才能将它应用到我的问题中呢?

1 个答案:

答案 0 :(得分:0)

来自mixingmatrix的{​​{1}}功能可以解决问题。它显示了组内和组之间的联系数量,实现了同质性和混合性。

network