# graph_tool.correlations.assortativity#

graph_tool.correlations.assortativity(g, deg, eweight=None)[source]#

Obtain the assortativity coefficient for the given graph.

Parameters:
gGraph

Graph to be used.

degstring or VertexPropertyMap

Degree type (“in”, “out” or “total”) or vertex property map, which specifies the vertex types.

eweightEdgePropertyMap (optional, default: None)

If given, this will specify the edge weights, otherwise a constant value of one will be used.

Returns:
assortativity coefficienttuple of two floats

The assortativity coefficient, and its variance.

assortativity

assortativity coefficient

scalar_assortativity

scalar assortativity coefficient

corr_hist

vertex-vertex correlation histogram

combined_corr_hist

combined single-vertex correlation histogram

avg_neighbor_corr

average nearest-neighbor correlation

avg_combined_corr

average combined single-vertex correlation

Notes

The assortativity coefficient [newman-mixing-2003] tells in a concise fashion how vertices of different types are preferentially connected amongst themselves, and is defined by

$r = \frac{\sum_i e_{ii} - \sum_i a_i b_i}{1-\sum_i a_i b_i}$

where $$a_i=\sum_je_{ij}$$ and $$b_j=\sum_ie_{ij}$$, and $$e_{ij}$$ is the fraction of edges from a vertex of type i to a vertex of type j.

The variance is obtained with the jackknife method.

If enabled during compilation, this algorithm runs in parallel.

References

M. E. J. Newman, “Mixing patterns in networks”, Phys. Rev. E 67, 026126 (2003), DOI: 10.1103/PhysRevE.67.026126 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["pgp-strong-2009"]
>>> g = gt.GraphView(g, directed=False)
>>> gt.assortativity(g, "out")
(0.0240578552..., 0.0003272847...)