Calculating relative modularity

Im working on comparing segregation across a set of networks of different size using modularity. My issue is that modularity is strongly correlated to network size (nodes and edges).

I would like to know if there is a way to calculate a measure of relative modularity (for example as seen in this paper: https://www.pnas.org/content/114/16/4165)

Measuring Modularity.

We used modularity (QQ) proposed by Newman ([()) to measure the strength of modular organization in networks. Modularity can be defined as Q=∑Kk=1[LwkL−(LkL)2])Q=∑k=1K[LkwL−(LkL)2]), where LkLk is the total number of edges in a subgroup kk, of which LwkLkw are the edges within the subgroup, and LL is the number of total edges in the network. Community structure, or the number and composition of subgroups, for each animal social network was estimated by using the Louvain method (30). The highest possible modularity in a network (QmaxQmax) is achieved when all individuals in a subgroup kk only interact with each other and no edges are present between subgroups (i.e., subgroups are disjointed). In other words, QmaxQmax of a network is when LwkLkw = LkLk, and can be written as Qmax=∑Kk=1LkL(1−LkL)Qmax=∑k=1KLkL(1−LkL). We measured the relative modularity of networks as Qrel=QQmaxQrel=QQmax.

Any ideas ? Thanks for the help.

Assortativity is normalized modularity. See Newman (2010) section 7.13 or Newman (2018) (second edition) section 7.7. You can use assortativity_nominal in igraph, giving it the graph and the proposed partition (your “segregation” is a partition?), which normalizes to the maximum modularity possible for the given partition. But if you have networks of different sizes, they will have different partitions.
Note that we have to be careful about saying “the modularity of a network”. Every network has a maximum possible modularity, but that is based on the optimal partition, which is NP-Hard to find and hence intractable for all but small networks. Hence we use heuristic approximations, such as the Louvain method (what Gephi calls “modularity”). Since we don’t know the maximum, assortativity is normalizing relative to the given partition, not to the theoretical maximum.

Thanks for the response. I´ll check out assortativity and Newman(2010 & 2019) in depth.

To be more precise, I´m working with a national household survey. The nodes in my network are occupations (doctor, engineer, house cleaner, office clerk, etc…) and edges occur between occupations when people with said accupations live in the same household. I can graph the complete national network or subset it for each city.
What I want to do is to compare between cities to know if some cities have a more “segregated” structure of social ties than others. I was using modularity to compare but it was highly correlated to network size because cities vary in population size.
Maybe I could use unweighted modularity, but i´m not sure.