Use this if you are using igraph from R
The assortativity coefficient is positive is similar vertices (based on some external property) tend to connect to each, and negative otherwise.
assortativity(graph, types1, types2 = NULL, directed = TRUE) assortativity_nominal(graph, types, directed = TRUE) assortativity_degree(graph, directed = TRUE)
The input graph, it can be directed or undirected.
The vertex values, these can be arbitrary numeric values.
A second value vector to be using for the incoming edges when
calculating assortativity for a directed graph. Supply
Logical scalar, whether to consider edge directions for
directed graphs. This argument is ignored for undirected graphs. Supply
Vector giving the vertex types. They as assumed to be integer
numbers, starting with one. Non-integer values are converted to integers
The assortativity coefficient measures the level of homophyly of the graph, based on some vertex labeling or values assigned to vertices. If the coefficient is high, that means that connected vertices tend to have the same labels or similar assigned values.
M.E.J. Newman defined two kinds of assortativity coefficients, the first one
is for categorical labels of vertices.
calculates this measure. It is defines as
r=(sum(e(i,i), i) - sum(a(i)b(i), i)) / (1 - sum(a(i)b(i), i))
where e(i,j) is the fraction of edges connecting vertices of type i and j, a(i)=sum(e(i,j), j) and b(j)=sum(e(i,j), i).
The second assortativity variant is based on values assigned to the
assortativity calculates this measure. It is defined as
sum(jk(e(j,k)-q(j)q(k)), j, k) / sigma(q)^2
for undirected graphs (q(i)=sum(e(i,j), j)) and as
sum(jk(e(j,k)-qout(j)qin(k)), j, k) / sigma(qin) / sigma(qout)
for directed ones. Here qout(i)=sum(e(i,j), j), qin(i)=sum(e(j,i), j), moreover, sigma(q), sigma(qout) and sigma(qin) are the standard deviations of q, qout and qin, respectively.
The reason of the difference is that in directed networks the relationship is not symmetric, so it is possible to assign different values to the outgoing and the incoming end of the edges.
assortativity_degree uses vertex degree (minus one) as vertex values
A single real number.
Gabor Csardi email@example.com
M. E. J. Newman: Mixing patterns in networks, Phys. Rev. E 67, 026126 (2003) http://arxiv.org/abs/cond-mat/0209450
M. E. J. Newman: Assortative mixing in networks, Phys. Rev. Lett. 89, 208701 (2002) http://arxiv.org/abs/cond-mat/0205405/
# random network, close to zero assortativity_degree(sample_gnp(10000, 3/10000)) # BA model, tends to be dissortative assortativity_degree(sample_pa(10000, m=4))