Differences in centrality measures between igraph and tnet

前端 未结 1 1904
鱼传尺愫
鱼传尺愫 2021-02-03 12:14

I\'m trying to obtain centrality measures for a directed, weighted network. I\'ve been using the igraph and tnet packages in R. However,

相关标签:
1条回答
  • 2021-02-03 13:15

    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
    
    0 讨论(0)
提交回复
热议问题