我正在尝试获取有向加权网络的中心性度量。我一直在使用igraph
and tnet
包在R
。然而,我发现使用这两个包获得的结果存在一些差异,并且我对这些差异的原因有点困惑。见下文。
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
有人知道发生了什么事吗?
发布这个问题后,我偶然发现了一个blog http://toreopsahl.com/由 Tore Opsahl 维护,tnet
包裹。我用评论问了托雷同样的问题this http://toreopsahl.com/2010/04/21/article-node-centrality-in-weighted-networks-generalizing-degree-and-shortest-paths/博客的帖子。以下是托尔的回应:
感谢您使用 tnet!igraph
能够承受重量;然而,距离函数igraph
期望代表“成本”而不是“强度”的权重。换句话说,领带重量被认为是穿过领带所需的能量。看加权网络中的最短路径 http://toreopsahl.com/tnet/weighted-networks/shortest-paths/.
因此,如果您运行 Tore 提供的以下代码(在将权重传递给igraph
),您将获得两者相同的紧密度分数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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)