1
$\begingroup$

I have a setup where I have a directed graph $G = (V,E)$ and a node attributes vector $\overrightarrow{x}$ with $|\overrightarrow{x}| = |V|$ and $\forall x_i \in \overrightarrow{x}$, it holds $x_i \in [-1, +1]$.

I would like to measure the homophily in the network with respect to the opinion values of each node, that is, measuring if nodes are likely to be connected with other nodes with the same/close opinion value.

I think that a measure that could help me is the assortativity implemented in networkx, where you can find a numeric version and an attribute version. The numeric version can't be used because it requests integers and not floats, the attribute one doesn't throw any error, but I think it treats each value like a category without considering the real distance, therefore it is not proper for me.

I have found a similar thread, but it seems like a different problem.

Can you suggest me some other network homophily measures for my case?

$\endgroup$
  • $\begingroup$ Even though the question you mention is different, its answers contain some information which is relevant to your own question. In particular, the igraph package can compute the assortativity for scalar attributes, did you try it? igraph.org/r/doc/assortativity.html $\endgroup$ – Vincent Labatut Apr 6 at 14:05
0
$\begingroup$

I agree with you @Balrog.

what about this little fun? I think it does what we need

import networkx as nx
import numpy as np


def att_assortativity(nx_graph,attribute):

    '''
    return corr. coeff. between node\'s and node\'s nearest neighbours average 'attribute', 
    for given networkX graph 
    '''

    att_mix_dict = nx.attribute_mixing_dict(nx_graph,attribute)
    aver_neigh_att = [np.mean(list(att_mix_dict[val].keys())) for val in att_mix_dict.keys()]
    return np.corrcoef(list(att_mix_dict.keys()),aver_neigh_att)[0,1]
New contributor
jjrr is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.