1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/structural.properties.R
3\name{transitivity}
4\alias{transitivity}
5\title{Transitivity of a graph}
6\usage{
7transitivity(
8  graph,
9  type = c("undirected", "global", "globalundirected", "localundirected", "local",
10    "average", "localaverage", "localaverageundirected", "barrat", "weighted"),
11  vids = NULL,
12  weights = NULL,
13  isolates = c("NaN", "zero")
14)
15}
16\arguments{
17\item{graph}{The graph to analyze.}
18
19\item{type}{The type of the transitivity to calculate. Possible values:
20\describe{ \item{"global"}{The global transitivity of an undirected
21graph (directed graphs are considered as undirected ones as well). This is
22simply the ratio of the triangles and the connected triples in the graph.
23For directed graphs the direction of the edges is ignored.}
24\item{"local"}{The local transitivity of an undirected graph, this is
25calculated for each vertex given in the \code{vids} argument. The local
26transitivity of a vertex is the ratio of the triangles connected to the
27vertex and the triples centered on the vertex. For directed graph the
28direction of the edges is ignored. Note that calculations do not work
29reliably in non-simple graphs, and since the presence of mutual edges in
30a directed graph becomes non-simple when treated as undirected, therefore
31it is advised to avoid using this function on non-simple and/or directed
32graphs. igraph prints a warning in these cases; the warning will be turned
33into an error in igraph 1.3.0.} \item{"undirected"}{This is the
34same as \code{global}.} \item{"globalundirected"}{This is the same as
35\code{global}.} \item{"localundirected"}{This is the same as
36\code{local}.} \item{"barrat"}{The weighted transitivity as defined A.
37Barrat. See details below.} \item{"weighted"}{The same as
38\code{barrat}.} }}
39
40\item{vids}{The vertex ids for the local transitivity will be calculated.
41This will be ignored for global transitivity types.  The default value is
42\code{NULL}, in this case all vertices are considered. It is slightly faster
43to supply \code{NULL} here than \code{V(graph)}.}
44
45\item{weights}{Optional weights for weighted transitivity. It is ignored for
46other transitivity measures. If it is \code{NULL} (the default) and the
47graph has a \code{weight} edge attribute, then it is used automatically.}
48
49\item{isolates}{Character scalar, defines how to treat vertices with degree
50zero and one. If it is \sQuote{\code{NaN}} then they local transitivity is
51reported as \code{NaN} and they are not included in the averaging, for the
52transitivity types that calculate an average. If there are no vertices with
53degree two or higher, then the averaging will still result \code{NaN}. If it
54is \sQuote{\code{zero}}, then we report 0 transitivity for them, and they
55are included in the averaging, if an average is calculated.}
56}
57\value{
58For \sQuote{\code{global}} a single number, or \code{NaN} if there
59are no connected triples in the graph.
60
61For \sQuote{\code{local}} a vector of transitivity scores, one for each
62vertex in \sQuote{\code{vids}}.
63}
64\description{
65Transitivity measures the probability that the adjacent vertices of a vertex
66are connected. This is sometimes also called the clustering coefficient.
67}
68\details{
69Note that there are essentially two classes of transitivity measures, one is
70a vertex-level, the other a graph level property.
71
72There are several generalizations of transitivity to weighted graphs, here
73we use the definition by A. Barrat, this is a local vertex-level quantity,
74its formula is
75
76\deqn{C_i^w=\frac{1}{s_i(k_i-1)}\sum_{j,h}\frac{w_{ij}+w_{ih}}{2}a_{ij}a_{ih}a_{jh}}{
77weighted C_i = 1/s_i 1/(k_i-1) sum( (w_ij+w_ih)/2 a_ij a_ih a_jh, j, h)}
78
79\eqn{s_i}{s_i} is the strength of vertex \eqn{i}{i}, see
80\code{\link{strength}}, \eqn{a_{ij}}{a_ij} are elements of the
81adjacency matrix, \eqn{k_i}{k_i} is the vertex degree, \eqn{w_{ij}}{w_ij}
82are the weights.
83
84This formula gives back the normal not-weighted local transitivity if all
85the edge weights are the same.
86
87The \code{barrat} type of transitivity does not work for graphs with
88multiple and/or loop edges. If you want to calculate it for a directed
89graph, call \code{\link{as.undirected}} with the \code{collapse} mode first.
90}
91\examples{
92
93g <- make_ring(10)
94transitivity(g)
95g2 <- sample_gnp(1000, 10/1000)
96transitivity(g2)   # this is about 10/1000
97
98# Weighted version, the figure from the Barrat paper
99gw <- graph_from_literal(A-B:C:D:E, B-C:D, C-D)
100E(gw)$weight <- 1
101E(gw)[ V(gw)[name == "A"] \%--\% V(gw)[name == "E" ] ]$weight <- 5
102transitivity(gw, vids="A", type="local")
103transitivity(gw, vids="A", type="weighted")
104
105# Weighted reduces to "local" if weights are the same
106gw2 <- sample_gnp(1000, 10/1000)
107E(gw2)$weight <- 1
108t1 <- transitivity(gw2, type="local")
109t2 <- transitivity(gw2, type="weighted")
110all(is.na(t1) == is.na(t2))
111all(na.omit(t1 == t2))
112
113}
114\references{
115Wasserman, S., and Faust, K. (1994). \emph{Social Network
116Analysis: Methods and Applications.} Cambridge: Cambridge University Press.
117
118Alain Barrat, Marc Barthelemy, Romualdo Pastor-Satorras, Alessandro
119Vespignani: The architecture of complex weighted networks, Proc. Natl. Acad.
120Sci. USA 101, 3747 (2004)
121}
122\author{
123Gabor Csardi \email{csardi.gabor@gmail.com}
124}
125\keyword{graphs}
126