本文介绍了igraph和tnet之间的集中度度量上的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to obtain centrality measures for a directed, weighted network. I've been using the igraph and tnet packages in R. However, I've discovered some differences in the results obtained using these two packages, and I'm a little confused about the cause of these differences. See below.

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

有人知道发生了什么事吗?

Anybody know what's going on?

推荐答案

发布此问题后,我偶然发现了博客tnet软件包的维护者Tore Opsahl维护.我在博客的此帖子.这是托尔的回应:

After posting this question, I stumbled upon a blog maintained by Tore Opsahl, maintainer of of the tnet package. I asked this same question of Tore using the comments on this post of the blog. Here is Tore's response:

因此,如果运行Tore提供的以下代码(在将权重传递给igraph之前采用权重的倒数),则可以获得tnetigraph的等效贴近度得分.

Thus, if you run the following code provided by Tore (which takes the inverse of the weights before passing them to igraph), you obtain equivalent closeness scores for both tnet and igraph.

> # 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

这篇关于igraph和tnet之间的集中度度量上的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 12:29