I try to compare the output of local transitivity and Barrat transitivity using igragh. However, I have problems with how they are calculated for directed graph. The result seems different from what I expected.
When calculate local transitivity, the direction is ignored. I calculated the local transitivity by number of closed triads devided by all possible triads (refer to Wasserman & Faust, 1994). But the result is 0.1666667 NaN NaN 1 1, same as the output of Barrat transitivity. Can anyone kindly explain it? Thanks a lot!
Below are the codes and output.
< g_1 <- graph( edges=c(1,2,1,3,1,4,1,5,4,1,5,1,4,5), n=5, directed=T)
< transitivity(g_1, type="local", isolates = "NaN")
#[1] 0.06666667 NaN NaN 0.33333333 0.33333333
< transitivity(g_1, type="Barrat", isolates = "NaN")
#[1] 0.1666667 NaN NaN 1.0000000 1.0000000
Clustering coefficient calculations are supported only for simple undirected graphs. The next version of igraph will throw an error if you try to use them on something else.
Thanks a lot for the fast reply.
Is that mean the output of clustering coefficient (i.e., local transitivity) is wrong when the graph is directed?
Is Barrat transitivity also gives wrong number for directed graphs?
Right now I do not recall the details that led to forbidding non-simple graphs. To be sure that your results are correct, please use only simple graphs. You can use simplify(). I will create an issue for this so it won’t be forgotten and so that we can investigate if it would be easier to support multigraphs now.
As for directed graphs:
The concept of the clustering coefficient applied to undirected graphs only, and does not generalize to the directed case in a straightforward manner. There is no generally accepted definition of the “directed clustering coefficient” in the network science community. There are a few papers suggesting multiple different kinds of generalizations. If you think that you need to count directed triangles in your graph, take a look at motifs().
To get the undirected clustering for directed graphs, first convert the graph to an undirected one, and once again be sure to simplify the graph afterwards.
Do not simply apply the function to a directed graph. It will not be able to just ignore edge directions correctly, as reciprocal directed edges are effectively undirected multi-edges.
The barrat type of transitivity does not work for graphs with multiple and/or loop edges. If you want to calculate it for a directed graph, call as.undirected with the collapse mode first.
FYI we have improved the handling of multigraphs and directed graphs in unweighted transitivity calculations. Now edge multiplicities and edge directions are correctly ignored. It will take some time before this change makes it into the R interface of igraph though.