## Abstract

A modular pattern, also called community structure, is ubiquitous in biological networks. There has been an increased interest in unraveling the community structure of biological systems as it may provide important insights into a system’s functional components and the impact of local structures on dynamics at a global scale. Choosing an appropriate community detection algorithm to identify the community structure in an empirical network can be difficult, however, as the many algorithms available are based on a variety of cost functions and are difficult to validate. Even when community structure is identified in an empirical system, disentangling the effect of community structure from other network properties such as clustering coefficient and assortativity can be a challenge. Here, we develop a generative model to produce undirected, simple, connected graphs with a specified degrees and pattern of communities, while maintaining a graph structure that is as random as possible. Additionally, we demonstrate two important applications of our model: (a) to generate networks that can be used to benchmark existing and new algorithms for detecting communities in biological networks; and (b) to generate null models to serve as random controls when investigating the impact of complex network features beyond the byproduct of degree and modularity in empirical biological networks. Our model thus allows for the systematic study of the presence of community structure and its impact on network function and dynamics. This process is a crucial step in unraveling the functional consequences of the structural properties of biological systems and uncovering the mechanisms that drive these systems.

## Background

Network analysis and modeling is a rapidly growing area which is moving forward our understanding of biological processes. Networks are mathematical representations of the interactions among the components of a system. Nodes in a biological network usually represent biological units of interest such as genes, proteins, individuals, or species. Edges indicate interaction between nodes such as regulatory interaction, gene flow, social interactions, or infectious contacts [1]. A basic model for biological networks assumes random mixing between nodes of the network. The network patterns in real biological populations, however, are more heterogeneous than assumed by these simple models [2]. Some of the common non-trivial properties known to exist in biological networks are degree heterogeneity, assortative mixing, clustering coefficient, and community structure (see review by Proulx et al.[1]). Community structure, or the presence of groups of nodes that are highly connected within the group but only loosely connected to other groups, has especially been found to be a central topological property [3, 4]. These groups, called modules or communities, may correspond to well-known or understood partitions of the system, but are based, in the context of network science, only on the configuration of connections between and among these groups, without any *a priori*knowledge of the system’s processes.

Although community structure has been found to be a central topological feature of biological networks such as metabolic [5], protein [6, 7], genetic [8], food-web [9, 10] and pollination networks [11], a detailed understanding of its relationship with other network topological properties is still limited. This is perhaps because delineating community structure in empirical networks can prove to be a difficult task, and the numerous community detection algorithms that exist often yield very different results. Another approach has used empirical vertex features or labels to independently estimate the accuracy of detection algorithms [12]. However, such tests can have ambiguous value as a lack of correlation between observed features and the identified communities may simply indicate that the true features driving the network’s structure are unobserved, not that the identified communities are incorrect.

A more straightforward method of exploring the structural and functional role of a network property is to generate graphs which are random with respect to other properties except the one of interest. For example, network properties such as degree distribution, assortativity and clustering coefficient have been studied using the configuration model [13], and models for generating random graphs with tunable structural features [14, 15, 2]. These graphs serve to identify the network measures that assume their empirical values in a particular network due to the particular network property of interest. In this work, we propose a model for generating simple, connected random networks that have a specified degree distribution and level of community structure.

Random graphs with tunable strength of community structure can have several purposes such as: (1) serving as benchmarks to test the performance of community detection algorithms; (2) serving as null models for empirical networks to investigate the combined effect of the observed degrees and the latent community structure on the network properties; (3) serving as proxy networks for modeling network dynamics in the absence of empirical network data; and (4) allowing for the systematic study of the impact of community structure on the dynamics that may flow on a network. Among these, the use of random graphs with tunable strength of community structure to serve as benchmarks has received the most attention and several such models have been proposed [16, 17, 18, 19, 20, 21]. A few studies have also looked at the role of community structure in the flow of disease through contact networks [22, 23, 24, 25]. However, the use of modular random graphs, which can be defined as random graphs that have a higher strength of community structure than what is expected at random, is still relatively unexplored in other applications. In this study, therefore, we extend the scope of modular random graphs by using our model to estimate the residual structure in several empirical networks, after controlling for the degree distribution and community structure.

## Previous work

In 2002, Girvan and Newman proposed a simple model for generation of random network with a specific configuration and strength of community structure [3]. The model generates modular random graphs of 128 nodes, four modules (and thus average modular size = 32) and average degree = 16. The connection probability in each module, which corresponds to a Erdős-Rényi random graph, is *p _{in}* and connection probability between modules is

*p*. This model is one of the widely-accepted benchmarks to test community-detection algorithms, but has a limited scope due to its several assumptions such as small network size, constant number of modules, and fixed degree of each node in the network, which do not reflect the heterogeneity observed in real network systems. The model proposed by Lancichinetti et al [16] considers heterogeneity in degree and community size, but is restrictive as it assumes only a particular type of degree distribution (power law). A similar model by Bagrow[17] generates modular networks with power law degree distribution and constant community size. Yan et al[23]used a growth and preferential attachment model to generate scale-free networks comprised of communities with power-law degree distribution. Models for special graph types such as hierarchical networks [18], bipartite networks [21], and networks with overlapping modules [20] have also been proposed. These models remain limited due to their assumptions about degree heterogeneity of network and its communities. The stochastic block model is a popular generative model for producing synthetic networks with specified community structure, but like the Girvan and Newman model, it produces unrealistic degree distributions. More recently, Karrer and Newman [26] introduced a “degree-corrected” stochastic block model, which can be used to infer communities from networks with arbitrary degrees, and could, in principle, also generate networks, although this has not been systematically investigated yet. A recently proposed model [19] does generate networks with a broad range of degree distributions, modularity and community sizes, but it is unclear how model parameters map to desired properties (such as degree distribution and modularity).While these models may be sufficient for community-detection benchmarks, the model limitations constrain their use for other purposes.

_{out}### Our approach

Here, we develop and implement a simple simulation model for generating modular random graphs using only a few intuitive parameters. Our model can generate graphs over a broad range of distributions of network degree and community size. The generated graphs can range from very small (<100) to large (>10^{5}) network sizes and can be composed of a variable number of communities. In Methods below, we introduce our algorithm for generating modular random graphs. In Results, we show that our null modular graph remains random with respect to other important network properties such as assortativity, clustering coefficient and path length. We next demonstrate the applicability of the generated modular graphs to test the accuracy of extant community detection algorithms. The accuracy of communitydetection algorithms depends on several network properties such as the network mean degree and strength of community structure, which is evident in our analysis. Finally, using a few empirical biological networks we demonstrate that our model can be used to generate corresponding null modular graphs under two different models of randomization. We conclude the paper with some thoughts about other applications and present some future directions.

## Implementation

We present a model that generates undirected, simple, connected graphs with prescribed degree distributions and a specified level of community structure, while maintaining a graph structure that is otherwise as random (uncorrelated) as possible. Below, we introduce some notation and a metric for measuring community structure, followed by a description of our model and the steps of the algorithm used to generate graphs with this specified structure.

### Measure of community structure

We begin with a graph *G* = (*V*, *E*) that is comprised of a set of vertices or nodes *V* (*G*) = {*v*_{1},…, *v _{n}*} and a set of edges

*E*(

*G*) = {

*e*

_{1},…,

*e*}.

_{m}*G*is undirected and simple (i.e. a maximum of one edge is allowed between a pair of distinct nodes, and no “self” edges are allowed). The number of nodes and edges in

*G*is |

*V*(

*G*)| =

*n*and |

*E*(

*G*)| =

*m*, respectively. The neighborhood of a node

*v*is the set of nodes

_{i}*v*is connected to, . The degree of a node

_{i}*v*, or the size of the neighborhood connected to

_{i}*v*, is denoted as

_{i}*d*(

*v*) = |

_{i}*N*(

*v*)|. A

_{i}*degree sequence*,

*D*, specifies the set of all node degrees as tuples, such that

*D*= {(

*v*,

_{i}*d*(

*v*)} and follows a probability distribution called the

_{i}*degree distribution*with mean .

Each community or *module C _{k}* is defined as a subset of

*G*that contains both nodes,

*V*(

*C*) and edges

_{k}*E*(

*C*), where both the endpoints of each edge in

_{k}*E*(

*C*) are contained in

_{k}*V*(

*C*). Each node

_{k}*v*of

_{i}*G*has a

*within-degree*,

*d*(

_{w}*v*) = |

_{i}*N*(

*v*)

_{i}*∩V*(

*C*)|, which is the number of

_{k}*within-edges*connecting

*v*to other nodes of the same module

_{i}*C*; and a

_{k}*between-degree*,

*d*(

_{b}*v*) = |

_{i}*N*(

*v*)

_{i}*-V*(

*C*)|, i.e. the number of

_{k}*between-edges*connecting

*v*to nodes in different modules (here, the minus operator represents set difference). The strength of the community structure defined by a partition, {

_{i}*C*}, can be measured as

_{k}*modularity*,

*Q*, and is defined as where denotes the proportion of all edges that are within module

*C*, and

_{k}*a*= represents the fraction of all edges that touch nodes in community

_{k}*C*. When

_{k}*Q*= 0, the density of within-community edges is equivalent to what is expected when edges are distributed at random, conditioned on the given degree sequence. Values approaching

*Q*= 1, which is the maximum possible value of

*Q*, indicate networks with strong community structure. Typically, values for empirical network modularity fall in the range from about 0.3 to 0.7 [27]. However, in theory Good et al. [28] show that maximum Q values depend on the network size and number of modules.

In order to generate a graph with a specified strength of community structure, *Q*, equation (1) represents our first constraint, which we rewrite below in terms of the expected value of *Q*, (full derivation in Additional file 1):
where and are the average within-degree and average degree, respectively, and *s _{k}* is the module size for module

*k*. Thus, equation (2) allows us to specify in terms of

*Q*, ,

*m*and

*s*, assuming that the module-specific average degree and average within-degree are equal to and , respectively. When for all

_{k}*k*,

*E*[

*Q*] reduce to .

We note that as the average within-degree approaches the average degree , the graph, *G* becomes increasingly modular. Hence, the maximum modularity for *G* with *K* modules can be estimated as:

### Model

We present a model and an algorithm that generates undirected, unweighted, simple and connected modular random graphs. The model is specified by a network size (*n*), degree distribution (*p _{d}*, with mean ), an expected modularity (

*E*[

*Q*]), the number of modules (

*K*), and the module size distribution (

*P*(

*s*), with mean

*s*. Here the size of module

*C*is

_{k}*s*= |

*V*(

*C*)|). The algorithm proceeds in four steps:

_{k}Assign the

*n*network nodes to*K*modules based on the size distribution*P*(*s*).Assign degrees,

*d*(*v*), to each node_{i}*v*based on_{i}*p*and . We next assign within-degrees,_{d}*d*(_{w}*v*), to each node_{i}*v*by assuming that the within-degrees follow the same distribution as_{i}*p*with mean , which is estimated based on equation (2) above (Figure 1a)._{d}Connect between-edges based on a modified Havel-Hakimi model and randomize them. (Figure 1b)

Connect within-edges based on the Havel-Hakimi model and randomize them. (Figure 1c and 1d)

The generated graph then has a degree distribution that follows *p _{d}* with mean ,

*K*modules with sizes distributed as

*P*(

*s*), and a modularity

*Q ≈ E*[

*Q*]. We set an arbitrary tolerance of

*∊*= 0.01, such that the achieved modularity is . The graph is also as random as possible given the constraints of the degree and community structure, contains no self loops (edges connecting a node to itself), multi-edges (multiple edges between a pair of nodes), isolate nodes (nodes with no edges), or disconnected components. Below, we elaborate on each of the steps of this algorithm.

#### Assigning Nodes to Modules

We sample module sizes, *s _{k}*, for each of the

*K*modules from the specified module size distribution,

*P*(

*s*) so that . The

*n*nodes are then arbitrarily (without loss of generality) assigned to each module to satisfy the sampled module size sequence.

#### Assigning Degrees

Based on the degree distribution specified, a degree sequence is sampled from the distribution to generate a degree, *d*(*v _{i}*), for each node

*v*. To ensure that the degree sequence attains the expected mean of the distribution (within a specified threshold) and is

_{i}*realizable*, we verify the Handshake Theorem (the requirement that the sum of the degrees be even) and the Erdős-Gallai criterion (which requires that for each subset of the

*k*highest degree nodes, the degrees of these nodes can be “absorbed” within the subset and the remaining degrees) [29], and that no node is assigned a degree of zero.

We assume that the within-degree distribution follows the degree distribution specified, *p _{d}*, with mean based on equation (2). This assumption is considered reasonable as it holds true for several of the empirical networks we analyze (shown in Figure S1 in Additional File 1). However, our model can be extended for arbitrary within-degree distributions, although the space of feasible within-degree distributions given a specified degree distribution is restricted. Next, we sample a within-degree sequence,

*d*(

_{w}*v*), from this within-degree distribution. (We note that degree and within-degree sequences can be specified instead of a degree distribution as inputs to the algorithm.) Using rejection sampling, we ensure that the within-degree sequence attains the expected overall mean, within a tolerance (with details in the Additional file 1), and satisfies the following conditions:

_{i}Condition 1:

*d*(*v*)_{i}*≥ d*(_{w}*v*) for all_{i}*v*. To ensure this, we sort the degree sequence and within degree sequence, independently. If_{i}*d*(*v*) <_{i}*d*(_{w}*v*) for any_{i}*v*in the ordered lists, the condition is not satisfied._{i}Condition 2: a realizable within-degree sequence for each module,

*C*, as defined by the Handshake Theorem and the Erdos-Gallai criterion._{k}

In addition, to ensure that each module approximately achieves the overall mean within-degree, , we specify the following constraint: min{*s _{k}*} ≤. If the sampled module sizes do not satisfy this criteria, the module sizes are re-sampled or an error is generated. In Figure S2 of Additional File 1, we discuss the rejection rates for the rejection sampling of both the within degree sequence as well as the module size distribution.

The between-degree sequence is generated by specifying *d _{b}*(

*v*) =

_{i}*d*(

*v*) -

_{i}*d*(

_{w}*v*) for each node

_{i}*v*. To test if the between-degree sequence is realizable, we impose a criterion developed by Chungphaisan[30] (reviewed by Ivanyi [31]) for realizable degree sequences in multigraphs. To do so, we imagine a coarse graph,

_{i}*H*, where the modules of

*G*are the nodes of

*H*(i.e.

*V*(

*H*) = {

*C*

_{1},

*C*

_{2}, …

*C*}), and the between-edges that connect modules of

_{K}*G*are the edges of

*H*. We note that

*H*is a multigraph, because

*G*allows multiple between-edges of

*G*to connect each pair of modules. In this case, the degree sequence of

*H*is .

The Chungphaisan criterion then specifies that the multigraph degree sequence {*d*(*C _{k}*)} on

*H*is realizable if the following conditions are satisfied:

Condition 1: the Handshake theorem is satisfied for is even

Condition min[

*jb, d*(*C*)] for (_{k}*j*= 1,…,*K*− 1).

Here, *b* is defined as the maximum number of edges allowed between a pair of nodes in *H*; in our case, *b* = max[{*d _{b}*(

*v*)}], the maximum between-degree of any node

_{i}*v*∈

_{i}*G*.

We also generate network graphs with *Q* = 0 by assuming the network is composed of a single module with no between-edges. Thus, *d _{w}*(

*v*) =

_{i}*d*(

*v*) and

_{i}*d*(

_{b}*v*) = 0 for all

_{i}*v*∈

_{i}*G*.

#### Connecting edges

Based on the within-degree sequence and between-degree sequence specified above, edges are connected in two steps (Figure 1). Nodes that belong to different modules are connected based on their between-degree to form between-edges (Figure 1b) and nodes that belong to the same module are connected according to their within degree to form within-edges (Figure 1c and 1d).

We connect between-edges using a modified version of the Havel-Hakimi algorithm. The Havel-Hakimi algorithm [32, 33] constructs graphs by sorting nodes according to their degree and successively connecting nodes of highest degree with each other. After each step of connecting the highest degree node, the degree list is resorted and the process continues until all the edges on the graph are connected. Here, we modify this to construct between-edges by sorting nodes by highest between-degree, in order of highest total between-degree for the module to which they belong, and successively connecting the node at the top of the list randomly with other nodes. Connections are only made between nodes if they are not previously connected, belong to different modules, and do not both have within-degree of zero (to avoid disconnected components). After each step the between-degree list is resorted, and the process continues until all between-edges are connected. After all between-edges have been connected, the connections are randomized using a well-known method of rewiring through double-edge swaps [34]. Specifically, two randomly chosen between-edges (*u*, *v*) and (*x*, *y*) are removed, and replaced by two new edges (*u*, *x*) and (*v*, *y*), as long as *u* and *x*, and *v* and *y* belong to different modules, respectively. The swaps are constrained to avoid the formation of self loops and multi-edges. This process is repeated a large number of times to randomize edges.

We then connect within-edges using the standard Havel-Hakimi algorithm, applied to each module independently. Specifically, within-edges of a module are connected by sorting nodes of the module according to their within-degree and successively connecting nodes of highest within-degree with each other. Connections are only made between nodes if they are not previously connected, and do not both have a between-degree of zero (to avoid disconnected components). After each step the within-degree list is resorted and the process continues until all the within-edges of the module are connected. The connections are then randomized by rewiring through double-edge swaps [34]. We do not specify that each module be connected (only that the full graph is connected). However, if this is required, Taylor’s algorithm can be used to rewire pairs of edges until the module is connected [35]. Specifically, the algorithm selects two random edges (*u, v*) and (*x, y*) that belong to two different disconnected components of the module. As long as (*u, x*) and (*v, y*) are not existing edges, the (*u, v*) and (*x, y*) edges removed and (*u, x*) and (*v, y*) added. If *k′* is connected, then we perform the rewiring operation and let *k _{t}*

_{+1}=

*k′*. Taylor’s theorem proves that following such operation any disconnected module can be converted to a connected module with the same degree sequence.

## Results and Discussion

Using our simulation algorithm, we were able to generate modular random graphs of variable network size, number of communities, degree distribution, and community size distribution. In Figure 2, we show sample networks of varying levels of modularity, *Q* = 0.1, 0.3, 0.6. We note that a network with three modules can approach a maximum modularity value of 2*/*3 (from equation 3), and thus *Q* = 0.6 is a relatively high modularity for this particular network type.

### Performance & Properties of Generated Graphs

#### Performance

Our model generates graphs that closely match the expected modularity and degree distribution. The deviation of the observed modularity is less than 0.01 from the expected value, given the specified partition. The modular random graphs with Poisson degree distribution generated by our model are similar to the ones described by Girvan and Newman[3] with linking (*p _{in}*) and cross-linking probability (

*p*) equal to and respectively. However, our model overcomes several limitations of the model proposed by Girvan and Newman [3] and others [16, 17] by considering heterogeneity in total degree, within-module degree distribution, and module sizes. Unlike many of the existing models [19, 18, 21, 20], our model can generate modular random graphs with arbitrary degree distributions, including those obtained from empirical networks.

_{out}#### Structural Properties

There are several other topological properties (besides degree distribution and community structure) that can influence network function and dynamics. The most significant of these properties are degree assortativity (the correlation between a node’s degree and its neighbor’s degrees), clustering coefficient (the propensity of a node’s neighborhood to also have edges among them) and average path length (the typical number of edges between pairs of nodes in the graph). We have developed this model to generate graphs with specified degree distribution and modularity, while minimizing structural byproducts. Thus, it is important to confirm that we have reached this goal with the generative model above.

To evaluate the status of other structural properties due to the generative model, we specify graphs of *n* = 2000 following Poisson , geometric , and power-law degree distributions with []. We chose these particular types of degree distributions as they have widely studied in the context of biological networks[36, 37, 38]. Each network has *K* = 10 modules and a module size distribution *P*(*s* = 200) = 1. We generate modular random graphs with these specifications and modularity values that range from *Q* = 0 to *Q* = 0.8, in steps of 0.1. For each level of modularity, we generated 50 such modular random graphs and calculated the degree assortativity (*r)*, clustering coefficient (*C)*, and average path length (*L*) for each network, which is illustrated in Figure 3. In networks with random community structure ((*Q* = 0)), that is random graphs with specified degree distributions (such as those that would be generated by the configuration model [13]), the value of *r*, *C*, and *L* are what are expected at random. In Figure 3, we show that for increasing values of modularity, degree assortativity, clustering coefficient, and average path length remain relatively constant for all three network types (i.e. Poisson, geometric and power-law). At the highest levels of modularity, edge connections are constrained, particularly for the heavy-tailed geometric and power-law degree distributions, leading to an increase in clustering coefficient. Correlations between high clustering coefficient and high modularity have also been observed before [2]. The average path length for all network types also increases at the highest levels of modularity, likely reflecting the lack of many paths between modules, requiring additional steps to reach nodes in different modules. Thus, our model is able to increase levels of modularity in random graphs without altering other topological properties significantly.

Biological networks show remarkable variation in network size, connectivity and community size distribution, with some of them having particularly small network size, high degree, and small module sizes (e.g. food-web networks). We therefore tested the performance of our generated networks under deviations in the network specifications of size, mean degree and module size distribution (results presented in Additional file 1 Figure S3, S4 and S5). We find that the structural properties of our generated modular random graphs remain constant, except for two constraining conditions: a) high average degree and b) low average module size . At these parameter extremes, the modular random graphs become disassortative and have increased clustering coefficient. A similar observation of network disassortativity has been made in hierarchically modular networks [39]. In these two scenarios, the highest value of within-degree (*d _{w}*(

*v*)) that a node can attain is constrained by the community size, which reduces the number of possible high within-degree nodes. As a consequence high within-degree nodes must connect to low within-degree nodes more than expected, resulting in a disassortative network. In these two cases, modules also become more dense and thus create more triangles resulting in a gradual increase in clustering. Path length, on the other hand, is not affected by these conditions and shows a consistent dependence on network size and mean degree, which is well known [40, 41].

_{i}### Application: Null Analysis of Empirical Networks

It is crucial to have random controls in the study of biological systems. Our algorithm can be used to generate null models and applied to the detection of structure in empirical biological networks. These null networks can be used to test hypotheses regarding the role of modularity and other topological features of the empirical networks. To do so, one would first use our algorithm to generate an ensemble of networks that match the empirical degree structure and community structure, and then compare the structural, functional, or dynamical properties of the empirical network to those of the generated modular random graphs. We demonstrate this application using four classes of biological networks, namely: a) a food-web, representing the trophic interactions at Little Rock Lake in Wisconsin with a network size of 183 and average degree = 26.8 [42]; b) a protein-protein interaction network in *Saccharomyces cerevisiae* (a yeast) of size= 4713 and average degree = 6.3[43]; c) a metabolic interaction network of *Caenorhabditis elegans* of size = 453 and average degree 9.0 [44]; and d) a network of social interactions in a community of dolphins living off Doubtful Sound, New Zealand of size = 62 and average degree = 5.1 [45] (Figure 4, black bars). Visualizations of the dolphin social interaction network and the food-web trophic interaction network and its modular random counterpart are shown in Figure 5.

For each of these four empirical networks, we generate modular random graphs (Figure 4, light gray bars) with three parameters estimated from the empirical networks: (a) the degree sequence, *pk*(b) the modularity, *Q* and (c) the average community size, . We note that as our goal is to construct null models, we assume that communities are of constant size, i.e., and that the within-degree distribution matches the degree sequence (with estimated mean, . (A second class of null models can be constructed with P(s) and the within-degree distribution estimated from the empirical networks, and we do this in the Additional file 1). Specifically, we generate 25 such random graphs and measure structural properties of the generated graphs including clustering coefficient (*C*), average path length (*L*), degree assortativity (*r*).

We also generate simple random graphs based on the configuration model that have the same degree distribution and average network degree as the empirical network but are random with respect to other network properties for each of the four empirical networks (Figure 4, dark gray bars). Our modular random graph model identifies which network measures assume their empirical values in a particular network because of (i) the observed degrees and (ii) the latent community structure. The configuration model, on the other hand, only specifies (i) and not (ii). Comparison to these configuration model networks thus helps us highlight the utility of our model to identify which empirical patterns in a network are deserving of further investigation. Figure 4 shows the value of each of these properties for the empirical networks as well as the ensemble mean of modular random and simple random graphs.

From Figure 4 it is evident that none of the empirical biological networks have network structure identical to their null counterparts. This suggests that the structure of each of these biological systems is governed by more than what is specified by the degree distribution and community structure. However, the observed network properties of empirical networks are closer to the ensemble means of the modular random graphs, which indicates that modularity is an essential structural component of real biological networks and that it plays an important role in influencing other structural properties of the network. For instance, compartmentalization induced by modularity promotes species persistence and system robustness by containing localized perturbation [11, 46, 47], which might favor their selection during the course of evolution. Our results show that the empirical networks tested have a much higher modularity than the simple random graphs (Figure 4a) and therefore provide evidence for this selection. Out of the three network properties that we tested apart from modularity, we found clustering coefficient of the generated random graphs to be significantly different from each of the empirical counterparts. This may point to a functional role for “triangles” in these biological networks, significantly above or below what is prescribed by the degree and community structure.

*Little Rock Lake food web interactions (FW):* Among the four empirical networks that we tested, the properties of the ensemble mean of null models such as assortativity and path length closely match most of the observed properties of Little Rock food web. The observed clustering coefficient of food web is strikingly lower than either of the random graphs which confirm the observations of low clustering in food web made by earlier studies (Figure 4d). The observed path length of this food web is short (Figure 4c) and only slightly longer than the path lengths of random graphs, which has also been noted before [48, 49, 50]. We note that for this food web, the structural properties of the simple random graphs are quite similar to those of modular random graph counterparts, suggesting that the degree distribution, particularly the high density of edges in the network governs most of the other topological characteristics of this network. Modularity, on the other hand, seems to play a minor role in dictating the structural properties of this network.

*Yeast protein-protein interaction network (YP):* The empirical yeast protein network is more disassortative than the ensemble mean of null modular graphs (Figure 4b). Disassortative interactions in protein-protein interaction networks are known to reduce interferences between functional modules and thus increase the overall robustness of the network to deleterious perturbations [6], while also allowing for functions to be performed concurrently [51]. The results therefore suggest that disassortative interactions may be selected for in the evolution of biological networks. From Figure 4(d) it is also evident that the yeast protein network has a higher value of clustering coefficient than the expected value predicted by the modular random graphs. A high value of clustering coefficient indicates that there are several alternate interaction paths between two proteins, making the system more robust to perturbation[52].

*C.elegans metabolic interaction network (CM):* The emphC.elegans metabolic network demonstrates a shorter path length but higher clustering coefficient than both modular and simple random graphs (Figure 4c and 4d). A high clustering coefficient and short path length suggests that the graph has small-world properties, which has been observed in other metabolic networks as well [53]. A highly disassortative degree structure is also well known in metabolic networks, although the mechanism leading to this property is unclear (see review by [36]). As the predicted value of disassortativity of the modular random graphs is closer to the observed value, our results suggest that the strong community structure of the metabolic networks could be one of the factors contributing to high degree disassortativity. (As discussed earlier, community structure leads to significant degree correlations in small networks with long-tailed degree distributions; see Figure S3 in Additional file 1 for an example).

*Social interaction network of dolphins network at Doubtful Sound, New Zealand (DS):* The empirical social interaction network of dolphins that we investigated demonstrated a negative assortativity (or disassortativity) similar to other real biological networks (Figure 4b). Interestingly, the assortativity value of both null modular and simple random network counterparts of the dolphin network is *lower* than the observed value, which suggests that the network is more assortative than expected. Degree assortativity has also been observed in other animal [54] and human [4] social interaction networks. This result is quite intuitive for a social network and is also referred to as homophily: more gregarious individuals tend to interact with other gregarious individuals while introverted individuals prefer to associate with other introverts[14]. The empirical dolphin network also demonstrated a lower value of clustering coefficient than the expected values of either null model. Low clustering coupled with high degree assortativity indicates that dolphin populations may be more susceptible to the propagation of infection or information, as transmission may occur rapidly through the entire network with such properties [54, 55].

### Application: Benchmark graphs for community-detection algorithms

Detecting communities in networks has been an area of intensive research in the past decade [56] with Girvan and Newman’s seminal paper on community detection [3]. Extant techniques such as modularity maximization, hierarchical clustering, the clique-based method, the spin glass method etc. aim at achieving high levels of accuracy in detecting the correct partition (for a detailed review see [56]), but have their own set of strengths and weaknesses. Choosing the best algorithm can be a difficult task especially as algorithms often use distinct definitions of communities and perform well within that description. Thus, it is exceedingly important to test community-detection algorithms against a suitable benchmark. We propose our modular random graphs as benchmark graphs for the validation of existing and new algorithms of community detection.

To illustrate this use, we test the performance of six popular community detection algorithms: the Louvain method [57], fast modularity method [58], the spinglass based method [59], the infoMAP method [60], label propagation [61] and the random-walk based method [62] using our modular random graphs as benchmarks. Specifically, we generate 10 modular random graphs for each level of modularity and used these community detection algorithms to detect their community structure. We also tested the performance of the algorithms on random graphs with no modularity (i.e. *Q* = 0). We limit our discussion to the results of the Louvain[57] and fast modularity method [58] in this section; with the remaining results presented in Additional File 1s (Figures S6, S7 and S8). Figure 6 summarizes the performance of these two algorithms, as measured by the estimated *Q*, for modular random graphs with three different degree distributions (Poisson, geometric and power-law) and two levels of mean network degree Fig 6(a) and (c) and Fig 6(b) and (d)).

At , both the Louvain method (Figure 6a) and fast modularity algorithm (Figure 6c) overestimate the modularity for networks with weak community structure, and underestimate the modularity for networks of moderate community structure across all three network types. Both algorithms are accurate at the highest strengths of community structure across all network types and improve in accuracy for the more dense network , Figure 6b and 6d). In addition to comparing the estimated values of modularity to the known values in the modular random graphs, we can compare the similarity in the partitions detected by the algorithms to the true partitions. For this comparison, we use the *Jaccard index*, which measures the similarity between two partitions based on the proportion of the union of the partitions that is made up by the intersection of the partitions [63], and present results in the Additional File 1 (Figure S9). As reflected in the results above, we find that partitioning is inaccurate when the true community structure is weak but improves as the *Q _{true}*value increases. The accuracy also improves with a higher average network degree. Both these observations have also been noted before by Lacichinetti and Fortunato [64].

## Conclusions

In summary, the model that we propose in this study generates modular random graphs over a broad range of degree distribution and modularity values, as well as module size distributions. We highlight that our model is specifically designed to generate networks which have modularity evenly divided across its modules, modulo the impact of module size. This means that we are mitigating the resolution limit effect and indeed generating networks with the maximum modularity partition. We also confirm that structural properties of our generated modular graphs such as assortativity, clustering and path length remain unperturbed for a broad range of parameter values. This important feature allows these graphs to act as benchmark and control graphs to explicitly test hypotheses regarding the function and evolution of modularity in biological systems.

Compartmentalization of biological networks has been an area of great interest to biologists. What we refer to as community structure in this work is any segregation of a biological system into smaller subunits inter-connected by only a few connections. It has been suggested that modularity in a system promotes system robustness and enhances species persistence by containing localized perturbations [11, 47]. Metabolic networks of organisms living in a variable environment have indeed been found to be more modular [46]. Maintaining and selecting for modularity in biological networks, however, comes at a great cost of reducing system complexity [65], longer developmental time and cost of complete module replacement in case of failure [66]. It is therefore unclear why modularity would be strongly selected for as a structural feature of biological systems. There is also a lack of evidence to prove that the functional localization of sub-goals overlaps with the structural segregation of the network into community structure. Our work provides a tool for the systematic study of network structure (through benchmark graphs) and of the impact of connectivity and compartmentalization on system function and dynamics (through control graphs).

The detection of community structure plays a crucial role in our topological understanding of complex networks. Currently the performance of community detection methods is usually evaluated based on ground-truth from real networks. However, determining reference communities in real networks is often a difficult task. Also, ground truth data on empirical network partitions do not necessarily identify system features based on network topology and thus may create a bias when analyzing community structure. A more convenient technique of evaluating community detection method is to use artificial random graphs, but has been limited as most of the models fail to incorporate degree heterogeneity of real networks. By providing a systematic method to generate benchmark graphs, our model can aid in the development of more robust community detection algorithms, and therefore improve our topological understanding of empirical networks.

Beyond identifying the topological presence of community structure is the understanding of the evolution of community structure as well as the functional and dynamical role of community structure. We believe this process can be facilitated by using an appropriate class of control or null graphs. As a model for generating null networks, our method joins a suite of random graph models, each contributing to a hierarchy of null models. The simplest model for generating random graphs (based on only a single parameter) is the Erdős-Rényi random graph model, which produces graphs that are completely defined by their average degree and are random in all other respects. A slightly more complex and general model is one that generates graphs with a specified degree distribution (or degree sequence) and but are random in all other respects [67, 68, 13]. These models can be extended to sequentially include additional independent structural constraints, such as degree distribution and clustering coefficient [2], or degree structure and community structure, as we have demonstrated here. A further extension to this work will be designing models that generate random graphs with multiple structural constraints. For example, our model can be combined with the one proposed by Bansal [2009] to generate random graphs with specified degree distribution as well as tunable strength of modularity and clustering coefficient.

## Availability and requirements

*Project name:*Modular random graph generator*Project home page:*http://github.com/bansallab*Operating system(s):*Platform independent*Programming language:*Python 2.7*Other requirements:*Networkx Python package*License:*BSD-style*Any restrictions to use by non-academics:*None

### Competing interests

The authors declare that they have no competing interests.

### Author’s contributions

PS and SB contributed to algorithm design and implementation. PS, LOS, AC and SB contributed to manuscript writing. All authors read and approved the final manuscript.

## Acknowledgements

This work was supported by NSF award DEB-1216054.