Get parts of the transitivity ratio

Hi there. I’m trying to get both parts of the transitivity ratio, i.e. number:number, instead the 0-1 value. I tried using the triangles and graph.motifs.no function for motifs of triads but the code under provides results that are different from the transitivity function.

(length(triangles(exampleNet))/3)/graph.motifs.no(exampleNet, size=3))

For context I’m doing this because I would like to fit a binomial model to these results, so I need both parts of the ratio. Any help would be much appreciated.

The next major version of igraph will make it easy for you to get both parts of the ratio with different functions. This is already implemented in C and released with C/igraph 1.0, but it hasn’t made its way to R yet.

What you are trying to do is a fine workaround in the meantime, but it is not quite correct. You are calculating the fraction of unordered connected triplets that are closed. The global clustering coefficient, or global transitivity, is the fraction of ordered connected triplets that are closed.

Have a look at the explanation I wrote up here:

https://szhorvat.net/mathematica/IGDocumentation/#igglobalclusteringcoefficient

Here’s what you can do:

> g<-sample_gnm(20,50)
> mot<-motifs(g,3)
> mot
[1]  NA  NA 180  16

This tells us that there are 180 unordered triples with a connectivity pattern 1-2-3 (wedge) and 16 with the connectivity pattern 1-2-3-1 (fully closed triangles).

This is what you calculated:

> mot[4] / (mot[3] + mot[4])
[1] 0.08163265

But every triangle contains three wedges. The triangle 1-2-3-1 contains the wedges 1-2-3, 2-3-1, 3-1-2. So this is what you need:

> 3*mot[4] / (mot[3] + 3*mot[4])
[1] 0.2105263
> transitivity(g, 'global')
[1] 0.2105263
> 

Alternatively, you can think of this more simply as each triangle contains 6 ordered wedges (all 6 permutations) and every wedge has 2 orderings (1-2-3 and 3-2-1).

I hope this helps.