Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences in centrality measures between igraph and tnet

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?

like image 333
Patrick S. Forscher Avatar asked Dec 04 '13 23:12

Patrick S. Forscher


People also ask

What are the different centrality measures?

Examples of A) Betweenness centrality, B) Closeness centrality, C) Eigenvector centrality, D) Degree centrality, E) Harmonic centrality and F) Katz centrality of the same graph.

What's the difference among degree betweenness and closeness centrality measures?

Closeness can be regarded as a measure of how long it will take to spread information from v to all other nodes sequentially. Betweenness centrality quantifies the number of times a node acts as a bridge along the shortest path between two other nodes.

Which centrality measure is best?

The authors of [58] conclude that “forest distance centrality has a better discrim- inating power than alternate metrics such as betweenness, harmonic centrality, eigenvector centrality, and PageRank.” They note that the order of node importance given by forest distances on certain simple graphs is in agreement with ...

What are the three measures of centrality?

The mean, median and mode are known as measures of centrality: an aim to identify the midpoint in a data set through statistical means.


1 Answers

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:

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.

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
like image 94
Patrick S. Forscher Avatar answered Sep 30 '22 03:09

Patrick S. Forscher