简体   繁体   English

顶点互惠-r上的社交网络分析

[英]Vertex reciprocity - social network analysis on r

I recently began working on r for social network analysis.我最近开始研究 r 用于社交网络分析。 Everything goes well and up until now, I found answers to my questions here or on google.一切顺利,直到现在,我在这里或谷歌上找到了我的问题的答案。 But not this time!但这次不是!

I am trying to find a way to calculate "vertex reciprocity" (% of reciprocal edges of each actor of the network).我正在尝试找到一种方法来计算“顶点互易性”(网络中每个参与者的互易边的百分比)。 On igraph, reciprocity(g) works fine to calculate the reciprocity of the whole network, but it doesn't help me with the score per actor.在 igraph 上,reciprocity(g) 可以很好地计算整个网络的互惠,但它对每个演员的得分没有帮助。 Does anybody know what I could do?有人知道我能做什么吗?

Thank you!谢谢!

I am going to assume that you have a simple graph, that is no loops and no multiple links between nodes.我将假设您有一个简单的图表,即节点之间没有循环并且没有多个链接。 In that case, it is fairly easy to compute this.在这种情况下,计算它相当容易。 What does it mean for a link to be reciprocated?链接被互惠是什么意思? When there is a link from a to b, there is a link back from b to a.当存在从 a 到 b 的链接时,存在从 b 到 a 的链接。 That means that there is a path of length two from a to itself a->b->a .这意味着从 a 到自身a->b->a有一条长度为 2 的路径。 How many such paths are there?这样的路径有多少? If A is the adjacency matrix, then the entries of A A gives the number of paths of length two.如果 A 是邻接矩阵,则 A A 的条目给出长度为 2 的路径数。 We only want the ones from a node to itself, so we want the diagonal of A A. This will only count a->b->a as one path, but you want to count it twice: once for the link a->b and once for b->a .我们只想要从一个节点到它自己的那些,所以我们想要 A A 的对角线。这只会将a->b->a计为一条路径,但您想计算两次:一次用于链接a->b和一次b->a So for each node you can get the number of reciprocated links from 2*diag(A*A) .因此,对于每个节点,您可以从2*diag(A*A)获得往复链接的数量。 You want to divide by the total number of links to and from a which is just the degree.您想除以与 a 的链接总数,这只是程度。

Let me show the computation with an example.让我用一个例子来展示计算。 Since you do not provide any data, I will use the Enron email data that is available in the 'igraphdata' package.由于您没有提供任何数据,我将使用“igraphdata”package 中提供的安然 email 数据。 It has loops and multiple links which i will remove.它有循环和多个链接,我将删除它们。 It also has a few isolated vertices, which I will also remove.它还有一些孤立的顶点,我也会将其删除。 That will leave us with a connected, directed graph with no loops.这将为我们留下一个没有循环的连接的有向图。

library(igraph)
library(igraphdata)

data(enron)
enron = simplify(enron)

## remove two isolated vertices
enron = delete_vertices(enron, c(72,118))

Now the reciprocity computation is easy.现在互易计算很容易。

EnronAM = as.matrix(as_adjacency_matrix(enron))
Path2 = diag(EnronAM %*% EnronAM)
degree(enron)
VertRecip = 2*Path2 / degree(enron)

Let's check it by walking through one node in detail.让我们通过一个节点详细检查它。 I will use node number 1.我将使用节点号 1。

degree(enron,1)
[1] 10
ENDS = ends(enron, E(enron))
E(enron)[which(ENDS[,1] == 1)]
+ 6/3010 edges from b72ec54:
[1] 1-> 10 1-> 21 1-> 49 1-> 91 1->104 1->151
E(enron)[which(ENDS[,2] == 1)]
+ 4/3010 edges from b72ec54:
[1]  10->1  21->1 105->1 151->1
Path2[1]
[1] 3

Node 1 has degree 10;节点 1 的度数为 10; 6 edges out and 4 edges in. Recip shows that there are three paths of length 2 from 1 back to itself. 6 个边缘向外,4 个边缘向内。Recip 显示从 1 回到自身有 3 条长度为 2 的路径。
1->10->1 1->10->1
1->21->1 1->21->1
1->151->1 1->151->1

That makes 6 reciprocated links and 4 unreciprocated links.这使得 6 个往复链接和 4 个非往复链接。 The vertex reciprocity should be 6/10 = 0.6 which agrees with what we computed above.顶点互易性应该是 6/10 = 0.6,这与我们上面计算的一致。

VertRecip[1]
[1] 0.6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM