r - igraph和tnet之间的集中度度量上的差异

标签 r social-networking igraph

我正在尝试获得有针对性的加权网络的集中度度量。我一直在igraph中使用tnetR包。但是,我发现在使用这两个软件包获得的结果中存在一些差异,并且我对造成这些差异的原因有些困惑。见下文。

require(igraph)
require(tnet)
set.seed(1234)

m <- expand.grid(from = 1:4, to = 1:4)
m <- m[m$from != m$to, ]
m$weight <- sample(1:7, 12, replace = T)
igraph_g <- graph.data.frame(m)
tnet_g <- as.tnet(m)

closeness(igraph_g, mode = "in")

         2          3          4          1 
0.05882353 0.12500000 0.07692308 0.09090909 

closeness(igraph_g, mode = "out")

         2          3          4          1 
0.12500000 0.06250000 0.06666667 0.10000000 

closeness(igraph_g, mode = "total")

         2          3          4          1 
0.12500000 0.14285714 0.07692308 0.16666667 


closeness_w(tnet_g, directed = T, alpha = 1)

     node closeness n.closeness
[1,]    1 0.2721088  0.09070295
[2,]    2 0.2448980  0.08163265
[3,]    3 0.4130809  0.13769363
[4,]    4 0.4081633  0.13605442

有人知道发生了什么吗?

最佳答案

发布此问题后,我偶然发现了tnet软件包的维护者Tore Opsahl维护的blog。我使用博客的this帖子上的评论问了Tore的相同问题。这是Tore的回复:

Thank you for using tnet! igraph is able to handle weights; however, the distance function in igraph expects weights that represent 'costs' instead of 'strength'. In other words, the tie weight is considered the amount of energy needed to cross a tie. See Shortest Paths in Weighted Networks.



因此,如果您运行Tore提供的以下代码(在将权重传递给igraph之前先进行权重的反算),则您将获得tnetigraph的等效接近度得分。
> # Load packages
> library(tnet)
>   
> # Create random network (you could also use the rg_w-function)
> m <- expand.grid(from = 1:4, to = 1:4)
> m <- m[m$from != m$to, ]
> m$weight <- sample(1:7, 12, replace = T)
>   
> # Make tnet object and calculate closeness
> closeness_w(m)

     node closeness n.closeness
[1,]    1 0.2193116  0.07310387
[2,]    2 0.3809524  0.12698413
[3,]    3 0.2825746  0.09419152
[4,]    4 0.3339518  0.11131725

>   
> # igraph
> # Invert weights (transform into costs from strengths)
> # Multiply weights by mean (just scaling, not really)
> m$weight <- mean(m$weight)/m$weight
> # Transform into igraph object
> igraph_g <- graph.data.frame(m)
> # Compute closeness
> closeness(igraph_g, mode = "out")

        2         3         4         1 
0.3809524 0.2825746 0.3339518 0.2193116

关于r - igraph和tnet之间的集中度度量上的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20388087/

相关文章:

r - 将图形写入文件不保留顶点名称

r - 平行坐标的实现?

social-networking - Disqus 和 SEO 友好评论

r - 在 R 中设置检测到的社区的大小

r - 使用节点的 XY 坐标设置 (igraph) 图

r - 如何访问频率表中的值

r - 如何将文本粘贴到 R 中 ggplot2 图形的数字 y 轴刻度中?

javascript - 在 Javascript 中跟踪社交按钮点击

facebook - Facebook 的开源替代品是什么?

python - 使用 igraph for python 的共同邻居和优先依附分数矩阵