Problems with igraph, statnet and GEPHI?

268 views Asked by At

I'm working with some graph models in both Gephi, Python and R. Until by chance I decided to compare the results they gave me. So I had the following problem. When calculating the betweenness centrality with Gephi and R (using igraph and statnet), the three give me different results (igraph and statnet, not very different). Since I am working a very large network, I decided to take a small network and perform the calculation by hand, the figure shown below (taked from: enter link description here )

enter image description here

Using the adjacency list:

source  target
1   2
1   3
1   4
2   3
3   4
4   5
4   6
5   6
5   8
5   7
6   8
6   7
7   8
7   9

To then see what results I threw R and Gephi. I discovered that Gephi gives me the same results:

enter image description here

But R (both for igraph and statnet not).

> library('igraph')
> data <- read.csv(file.choose())
> set.seed(123456)
> graph_1<-graph.data.frame(data)
> summary(graph_1)
IGRAPH cfa51db DN-- 9 14 -- 
+ attr: name (v/c)

> graph_1
IGRAPH cfa51db DN-- 9 14 -- 
+ attr: name (v/c)
+ edges from cfa51db (vertex names):
 [1] 1->2 1->3 1->4 2->3 3->4 4->5 4->6 5->6 5->8 5->7 6->8 6->7 7->8 7->9

> betweenness(graph_1)
 1  2  3  4  5  6  7  8  9 
 0  0  6 15  6  6  6  0  0

> detach("package:igraph", unload=TRUE)
> library(statnet)
> library(intergraph)
> graph_2<-asNetwork(graph_1)

> betweenness(graph_2)
[1]  0  0  6 15  6  6  6  0  0

Am I doing something wrong by running my R code or is it using another algorithm to calculate the betweenness centrality? Thank you :)

1

There are 1 answers

0
G5W On BEST ANSWER

You are computing two different things.

First, to make your example reproducible, here is code that all of us can use to make your example.

library(igraph)
EL = matrix(c(1,2, 1,3, 1,4, 2,3, 3,4, 4,5, 4,6, 5,6, 5,8, 
    5,7, 6,8, 6,7, 7,8, 7,9), ncol=2, byrow=T)
graph_1 = graph_from_edgelist(EL)

Now, using your code, I get the same result.

betweenness(graph_1)
[1]  0  0  6 15  6  6  6  0  0

However,

betweenness(graph_1, directed=F)
[1]  3  0  3 15  6  6  7  0  0

Gives the same result as you got from Gephi.

The help page ?betweenness says:

directed
Logical, whether directed paths should be considered while determining the shortest paths.

Clearly, Gephi has different defaults than R.