This measure is sometimes called clustering coefficient.
References
Barrat, A., Barthelemy, M., Pastor-Satorras, R. and Vespignani, A. (2004). The architecture of complex weighted networks. Proceedings of the National Academy of Sciences, 101(11), 3747–3752. doi:10.1073/pnas.0400087101
Wasserman, S. and Faust, K. (1994). Social network analysis: Methods and applications. Cambridge University Press.
Examples
A <- matrix(c(
0, 1, 0, 1, 0,
1, 0, 1, 1, 0,
0, 1, 0, 0, 0,
1, 1, 0, 0, 1,
0, 0, 0, 1, 0
), byrow = TRUE, ncol = 5)
rownames(A) <- letters[1:ncol(A)]
colnames(A) <- rownames(A)
trans_coef(A, method = "local")
#> $a
#> [1] 1
#>
#> $b
#> [1] 0.3333333
#>
#> $c
#> [1] NaN
#>
#> $d
#> [1] 0.3333333
#>
#> $e
#> [1] NaN
#>
# The weighted transitivity of Barrat et al. (2004) weighs each triangle
# by the strength of the two ties of the node
W <- matrix(c(
0, 4, 0, 2, 0,
4, 0, 1, 3, 0,
0, 1, 0, 0, 0,
2, 3, 0, 0, 5,
0, 0, 0, 5, 0
), byrow = TRUE, ncol = 5)
trans_coef(W, method = "barrat")
#> [1] 1.0000 0.4375 NA 0.2500 NA
