Transitivity measures the probability that the adjacent vertices of a vertex are connected. This is sometimes also called the clustering coefficient.
Arguments
- graph
The graph to analyze.
- type
The type of the transitivity to calculate. Possible values:
- "global"
The global transitivity of an undirected graph. This is simply the ratio of the count of triangles and connected triples in the graph. In directed graphs, edge directions are ignored.
- "local"
The local transitivity of an undirected graph. It is calculated for each vertex given in the
vids
argument. The local transitivity of a vertex is the ratio of the count of triangles connected to the vertex and the triples centered on the vertex. In directed graphs, edge directions are ignored.- "undirected"
This is the same as
global
.- "globalundirected"
This is the same as
global
.- "localundirected"
This is the same as
local
.- "barrat"
The weighted transitivity as defined by A. Barrat. See details below.
- "weighted"
The same as
barrat
.
- vids
The vertex ids for the local transitivity will be calculated. This will be ignored for global transitivity types. The default value is
NULL
, in this case all vertices are considered. It is slightly faster to supplyNULL
here thanV(graph)
.- weights
Optional weights for weighted transitivity. It is ignored for other transitivity measures. If it is
NULL
(the default) and the graph has aweight
edge attribute, then it is used automatically.- isolates
Character scalar, for local versions of transitivity, it defines how to treat vertices with degree zero and one. If it is ‘
NaN
’ then their local transitivity is reported asNaN
and they are not included in the averaging, for the transitivity types that calculate an average. If there are no vertices with degree two or higher, then the averaging will still resultNaN
. If it is ‘zero
’, then we report 0 transitivity for them, and they are included in the averaging, if an average is calculated. For the global transitivity, it controls how to handle graphs with no connected triplets:NaN
or zero will be returned according to the respective setting.
Value
For ‘global
’ a single number, or NaN
if there
are no connected triples in the graph.
For ‘local
’ a vector of transitivity scores, one for each
vertex in ‘vids
’.
Details
Note that there are essentially two classes of transitivity measures, one is a vertex-level, the other a graph level property.
There are several generalizations of transitivity to weighted graphs, here we use the definition by A. Barrat, this is a local vertex-level quantity, its formula is
Cwi=1si(ki−1)∑j,hwij+wih2aijaihajh
si is the strength of vertex i, see
strength()
, aij are elements of the
adjacency matrix, ki is the vertex degree, wij
are the weights.
This formula gives back the normal not-weighted local transitivity if all the edge weights are the same.
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.
References
Wasserman, S., and Faust, K. (1994). Social Network Analysis: Methods and Applications. Cambridge: Cambridge University Press.
Alain Barrat, Marc Barthelemy, Romualdo Pastor-Satorras, Alessandro Vespignani: The architecture of complex weighted networks, Proc. Natl. Acad. Sci. USA 101, 3747 (2004)
See also
Other structural.properties:
bfs()
,
component_distribution()
,
connect()
,
constraint()
,
coreness()
,
degree()
,
dfs()
,
distance_table()
,
edge_density()
,
feedback_arc_set()
,
girth()
,
is_acyclic()
,
is_dag()
,
is_matching()
,
k_shortest_paths()
,
knn()
,
laplacian_matrix()
,
reciprocity()
,
subcomponent()
,
subgraph()
,
topo_sort()
,
unfold_tree()
,
which_multiple()
,
which_mutual()
Author
Gabor Csardi csardi.gabor@gmail.com
Examples
g <- make_ring(10)
transitivity(g)
#> [1] 0
g2 <- sample_gnp(1000, 10 / 1000)
transitivity(g2) # this is about 10/1000
#> [1] 0.01046946
# Weighted version, the figure from the Barrat paper
gw <- graph_from_literal(A - B:C:D:E, B - C:D, C - D)
E(gw)$weight <- 1
E(gw)[V(gw)[name == "A"] %--% V(gw)[name == "E"]]$weight <- 5
transitivity(gw, vids = "A", type = "local")
#> A
#> 0.5
transitivity(gw, vids = "A", type = "weighted")
#> A
#> 0.25
# Weighted reduces to "local" if weights are the same
gw2 <- sample_gnp(1000, 10 / 1000)
E(gw2)$weight <- 1
t1 <- transitivity(gw2, type = "local")
t2 <- transitivity(gw2, type = "weighted")
all(is.na(t1) == is.na(t2))
#> [1] TRUE
all(na.omit(t1 == t2))
#> [1] FALSE