Calculating the assortativity coefficient of a graph

In graph theory, similarity is measured by the degree distribution. Degree is the number of connections a node has to other nodes. In a directed graph, we have incoming and outgoing connections and corresponding indegree and outdegree. Friends tend to have something in common. In graph theory, this tendency is measured by the assortativity coefficient. This coefficient is the Pearson correlation coefficient between a pair of nodes, as given in the following equation:

Calculating the assortativity coefficient of a graph

qk (distribution of the remaining degree) is the number of connections leaving node k. ejk is the joint probability distribution of the remaining degrees of the node pair.

Getting ready

Install NetworkX with the instructions from the Introduction section.

How to do it...

The code is in the assortativity.ipynb file in this book's code bundle:

  1. The imports are as follows:
    import networkx as nx
    import dautil as dl
  2. Load the Facebook SPAN data into a NetworkX graph:
    fb_file = dl.data.SPANFB().load()
    G = nx.read_edgelist(fb_file,
                         create_using=nx.Graph(),
                         nodetype=int)
  3. Calculate the assortativity coefficient as follows:
    print('Degree Assortativity Coefficient',
          nx.degree_assortativity_coefficient(G))

We get the following result for the Facebook SPAN data:

Degree Assortativity Coefficient 0.0635772291856

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset