用R(手动)计算顶点(节点)的局部聚类系数 [英] Calculate local clustering coefficient of a vertex (node) with R (by hand)

查看:395
本文介绍了用R(手动)计算顶点(节点)的局部聚类系数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现显示如何手工计算LCC的示例(参见图片)。

I found an example showing how to calculate LCC by hand (see image).

如何在R中复制这些步骤?重点是查找邻居之间的实际链接数(中间步骤)

How can I replicate these steps in R? Focus is on finding the "Actual number of links among Neighbors" (middle step)

我最好手动计算

* igraph包装是否提供此数字?

*Does the igraph package provide this number?

邻接矩阵示例:

matrix(data = c(0,1,0,1,1,0,0,1,1,1,0,1,1,0,1,0), ncol = 4)


推荐答案

所有这些操作都可以在<$ c中完成$ c> igraph 。举一个很好的例子,
很不错,但是由于图形是完全连接的,因此所有顶点的LCC = 1。我决定
使用稍微复杂一些的图形。我将详细介绍顶点1的手工
部分。

All of this can be done in igraph. It is nice that you gave an example, but since the graph is fully connected, all vertices have LCC=1. I decided to use a somewhat more complicated graph. I will go through the "by hand" part in detail for vertex 1.

样本图

library(igraph)

set.seed(1234)
g = erdos.renyi.game(5, 0.7)
LO = matrix(c(0,2,1,1,1,0,0,-1,1,0), nrow=5, ncol=2)
plot(g, layout=LO)

首先,是的,igraph具有用于LCC的内置功能传递性
对于我的示例图,您可以使用

To start with, yes, igraph has a built-in function transitivity for LCC. For my sample graph, you can get this with

transitivity(g, type="localundirected")
[1] 0.6666667 0.0000000 0.3333333 0.3333333 0.6666667

但您问题的主要部分是手工计算。
图中唯一需要的是前
两步-学位中心化邻居之间的实际链接

But the main part of your question is the hand computation. The only things that you need from the graph are the first two steps - the Degree Centrality and the Actual Links Among Neighbors.

学位中心度学位函数

degree(g)
[1] 3 2 3 3 3
degree(g, 1)        ## Vertex 1 only
[1] 3

正如您在问题中所建议的那样,唯一具有挑战性的部分是
邻居之间的实际链接。您可以通过获取由点的邻居引起的子图
,然后检查边数来获得此结果。
因此,对于顶点1,我们得到

As you suggested in your question, the only challenging part is the Actual Links Among Neighbors. You can get this by taking the subgraph induced by the neighbors of a point and then checking the number of edges. So for vertex 1 we get

ecount(induced_subgraph(g, neighbors(g, 1)))
[1] 2

这里是顶点1的完整计算

Here is the full computation for vertex 1

(DC   = degree(g, 1))
[1] 3
>(ALAN = ecount(induced_subgraph(g, neighbors(g, 1))))
[1] 2
(MaxPoss = DC*(DC-1)/2)
[1] 3
(LCC = ALAN/MaxPoss)
[1] 0.6666667

同意的传递性以上。

这篇关于用R(手动)计算顶点(节点)的局部聚类系数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆