attribute_assortativity_coefficient¶
-
attribute_assortativity_coefficient
(G, attribute, nodes=None)[source]¶ Compute assortativity for node attributes.
Assortativity measures the similarity of connections in the graph with respect to the given attribute.
Parameters: Returns: r – Assortativity of graph for given attribute
Return type: Examples
>>> G=nx.Graph() >>> G.add_nodes_from([0,1],color='red') >>> G.add_nodes_from([2,3],color='blue') >>> G.add_edges_from([(0,1),(2,3)]) >>> print(nx.attribute_assortativity_coefficient(G,'color')) 1.0
Notes
This computes Eq. (2) in Ref. [1] , trace(M)-sum(M))/(1-sum(M), where M is the joint probability distribution (mixing matrix) of the specified attribute.
References
[1] M. E. J. Newman, Mixing patterns in networks, Physical Review E, 67 026126, 2003