## Introduction

Network thinking has become a prominent and convenient paradigm to unveil the properties of complex systems. Such a paradigm has been rapidly enriched, giving rise to variants that account for inherent features of real complex systems inferred by the availability of large, often time-resolved datasets1,2,3,4. Three are the main features that have captured the attention of researchers in the area. The first is heterogeneity in the statistical distributions of key topological properties such as the number of connections per node (degree) and the intensity of interactions (weight)3,4. This property is one of the hallmarks of complexity and is linked to a range of non-trivial dynamics3,5. For example, heterogeneity in the connectivity patterns makes networks extremely fragile to the spreading of infectious diseases and malicious attacks6,7. The second feature regards the presence of modules and communities8. Available datasets have highlighted that real networks are organized in modules, or communities, whereby the density of links within the community is much greater than the density of links between communities. On the one hand, communities can be treated as fairly independent entities within a large network, like the behaviour of different organs within the same body. On the other hand, from time to time, phenomena originating in a community may involve a huge portion, if not all, of the network. This is for example the case of pandemics originating from local outbreaks6,9,10,11. Nevertheless, the role played communities is still ambivalent. For example, the presence of communities might slow down or speed up the propagation of a disease and facilitate the spreading of social norms12,13,14,15,16,17,18,19,20. Detecting communities in a real system is not a trivial task, due to their fuzzy, vanishing, and overlapping nature. Also, in most of the available datasets communities are not explicitly labeled, so the validation of community detection algorithms cannot often be rigorously carried out8,21. Finally, networks are characterised by non trivial temporal dynamics22,23. The propensity of nodes to initiate and to attract interactions per unit time is typically heterogeneously distributed24,25. The same applies to the duration and the time interval between connections13,26. Furthermore, the creation or renewal of interactions might be correlated, and the dynamics driving the temporal evolution of networks are function of the time-scale considered27,28. However, the large majority of studies on dynamical processes unfolding on networks have been conducted under the hypothesis of time scale separation which effectively neglects all such features. In particular, the evolution of the process and the evolution of network are considered to take place at well-distinct time scales. Within this paradigm two opposite limits have been considered. In the first case, the dynamical process is assumed to be much faster than the evolution of the network. This is the limit of quenched/static networks29. Here, networks are fully characterised from an adjacency matrix, A ij whose entries are non-zero for all connected pairs i − j3. The second case instead, is the opposite limit where an annealed version of the network can be considered and averaging (mean-field) techniques can be applied30,31,32. Annealed networks are fully characterised by an average adjacency matrix $${\bar{A}}_{{k}_{i},{k}_{j}}$$ describing the probability of connection for nodes of degree k i and degree k j 33. In our case instead, the time scale regulating the dynamical process and the evolution of the network are comparable, the time scale approximation is not valid. This is the regime of time-varying networks23. Interestingly, the temporal nature of interactions might inhibit or facilitate spreading processes evolving at comparable time-scales11,24,34,35,36,37,38,39,40,41,42,43,44,45,46. The effects introduced by communities and time-varying connectivity patterns on dynamical processes have been mostly scrutinised separately. However, as few recent works pointed out, the two attributes are connected and their interplay introduces non-trivial effects, such as segregated behaviours and formation of hierarchical structures47; or the intricate competition between topological and temporal correlations48. The presence of groups, think for example the interaction network of students in a school, introduces specific dynamics that deeply affect spreading processes. A thorough modelling and study of these phenomena may be useful to define prioritisation of interventions and containment strategies in epidemic spreading49.

Altogether, these observations call for a general modelling framework aimed at characterising both features and single out their effects on real networks. The model presented in this paper leverages on the paradigm of Activity Driven Networks (ADNs) to model realistic temporal networks where the node and link dynamics coevolve at comparable time scales24,50 and includes the modularity phenomena, whereby connection patterns can be set to preferentially occur within a given community, rather than outside the community toward the rest of the population. While the coevolution of node and link dynamics is inherently considered in ADNs by construction, modularity is here modelled by a single parameter that regulates the interplay between the link formation within and outside of the community. In the context of epidemic processes on time-varying networks, our model is first characterised analytically. Then it is used to study the behaviour of different contagion processes on synthetic networks, and on a large, time-resolved dataset of scientific collaborations. Results and methods are discussed in detail in the following sections.

## Results

Here, we study the effect of modularity (i.e., the presence of communities in the network) on time-varying networks. To this extent, we introduce a model of time-varying networks with tunable modularity, able to capture several features of real temporal graphs. We derive an analytical characterisation of the model, and we study the behaviour of the Susceptible-Infected-Recovered (SIR) and the Susceptible-Infected-Susceptible (SIS) epidemic processes unfolding on its fabric51. Remarkably, while the presence of tightly connected clusters inhibits SIR processes, it favours the spreading of SIS-like diseases lowering the epidemic threshold. Interestingly, similar results have been recently obtained in models of time-varying networks characterised by correlated topological features induced by reinforcement of specific ties42. We confirm the theoretical picture emerging from synthetic networks by means of extensive simulations on a real word dataset of scientific collaborations within the American Physical Society (APS). Our results contribute to characterise the mechanisms, and their interplay, behind the complex, and often contradictory, behaviour of dynamical processes unfolding on real networks.

### Modular activity driven networks

The system under investigation is composed by N nodes. Each node i is characterised by an activity rate a i , that describes its propensity to engage in social interactions with other nodes. To capture empirical observations performed in a wide set of systems ranging from R&D to online interactions networks25,38,52,53, we consider activity rates heterogeneously distributed, and extracted from a continuous functional form F(a) = Baν, where a [ε, 1] and ε = 10−3 to avoid divergence in the distribution. Furthermore, each node is assigned to only one group/community. To take into account empirical evidences, the size of each community is extracted from a heavy-tailed distribution, i.e. P(s) = Csω with $$s\in [{s}_{min},\sqrt{N}]$$8,54. Therefore, we do not limit ourselves in studying a fixed number of modules55, whilst their number is driven from the model’s parameters. The assignment of nodes to communities is done as follow. A community of size s is extracted. The ID of s nodes is progressively assigned to the community. The processes is repeated until all N nodes are assigned to one community. Very rarely, all nodes can be perfectly assigned to the extracted community sizes. Indeed, in the last extraction we might have available only a fraction of the nodes necessary to fill the community. However, the average value of s is much smaller than the total number of nodes, thus the actual size of the last community can be only slightly smaller than the extracted value. The empirical distribution of community sizes in the network will then follow P(s). Given these settings, a generative network model is defined by the following steps (see Fig. 1).

• At each time t, the network, G t , starts with N disconnected nodes.

• With probability a i Δt each vertex i is active and willing to create m connections.

• Each link being generated points with probability μ within the node’s community, and with probability 1 − μ to one of any other groups. In both cases, the target node j of the link is randomly selected in the target community.

• At the next time step t + Δt all the edges in G t are deleted.

All the interactions have a constant duration Δt. In the model, neither self-loops nor multiple edges are allowed. In the following, without loss of generality, we fix Δt = 1. Furthermore, we consider the case m = 1.

Given an heterogeneous distribution of activity, at each time step, the model generates a random, structureless network in which few nodes are active. The modular features of the network emerge integrating connections in time. Such time-integrated properties, at different time regimes, can be computed analytically. In the following, we will report the results for the evolution of the average number of connections of each node 〈k i (t)〉 (average degree) and the overall degree distribution ρ(k). The complete set of results is shown in the Supplementary Information (SI).

To solve the average degree’s dynamics, let us introduce the effective activity $${\tilde{a}}_{i}={a}_{i}+\langle a\rangle$$ (where 〈a〉 is the average value of the activity distribution) and the mixing parameter μ′ = 1 − μ. We refer to the degree of node i at time t as k(a i , s, t), where s is the node’s community size. By defining an activity class as the group of nodes featuring similar activity values a, we set the average in-community degree 〈k c (a, s, t)〉 to be the average number of connections that nodes belonging to the activity class a and falling in communities of size s have toward nodes of their same community. The latter grows as

$$\langle {k}_{c}(a,s,t)\rangle =(s-\mathrm{1)}\,[1-\exp (-\frac{t}{\tau (a,s)})],$$
(1)

where τ(a, s) is the characteristic time that it takes for the degree k c (a, s, t) of nodes of activity a belonging to a community of size s to be $${k}_{c}(a,s,t)\sim (s-\mathrm{1)}$$, being s − 1 the maximum value of the in-community degree (see the Supplementary Information for the evaluation of τ(a, s)).

Similarly, we can define the average out-community degree 〈k o (a, t)〉 as the number of connections that nodes of activity class a have outside of their communities at time t. We expect this quantity to be independent of the nodes’ community size s so that, for large networks, we can write:

$$\langle {k}_{o}(a,t)\rangle ={\mu }^{\text{'}}\tilde{a}t$$
(2)

The average total degree 〈k(a, s, t)〉 can be computed as the simple sum between the two previous equations, obtaining

$$\langle k(a,s,t)\rangle =\langle {k}_{c}(a,s,t)\rangle +\langle {k}_{o}(a,t)\rangle \simeq \{\begin{array}{lll}\tilde{a}t & t\ll \tau (a,s) & \quad \phantom{\rule{11em}{0ex}}(3{\rm{a}})\\ \mu ^{\prime} \tilde{a}t+(s-1) & t\sim \tau (a,s) & \quad \phantom{\rule{11em}{0ex}}(3{\rm{b}})\\ \mu ^{\prime} \tilde{a}t & t\gg \tau (a,s) & \quad \phantom{\rule{11em}{0ex}}(3{\rm{c}})\end{array}$$

Three regimes are readily identified: an initial growth in which both the in-community and the out-community degrees are growing linearly in time, followed by the slowing down of the in-community degree, which saturates to s − 1, and then a further linear regime driven only by the out-community degree growth. Figure 2 shows that the numerical simulations perfectly match with the theoretical formulas (see the SI for details).

Noticeably, the long time evolution of the node degree is linear in time and proportional to its activity class a, so that we find the asymptotic degree distribution of the system to feature the same functional form of F(a) aν, as found in non-modular activity driven networks24,56:

$$F(a)da\mathop{\longrightarrow }\limits^{k(a,t)\propto a\cdot t}\rho (k)dk\propto {k}^{-\nu }dk\mathrm{.}$$
(4)

In Fig. 3, we integrate the network for T = 105 and we plot the three degree distributions. As expected, the out-community ρ(k o ) and the total ρ(k) degree distributions fall as power laws with exponent −ν. On the other hand, the in-community degree ρ(k c ) saturates to the community size distribution P(s), as all the nodes reach their maximum in-community degree value (s − 1), being that the modules’ size is far smaller than the network size $$({s}_{{\rm{\max }}}=\sqrt{N}\ll N)$$. On the contrary, the out-community degree takes longer times to saturate to its maximum value $$N-s\gg s$$.

It is worth stressing that the results presented in this section apply to the networks obtained integrating links over time. A process unfolding on such networks, in general, will be affected by the time-aggregated features of the graph. The extent to which this is true, is function of the interplay between the time-scale describing its evolution, τ P , and the various τ(a, s). In the limit $${\tau }_{p}\ll \tau (a,s)$$ the process would effectively evolve on the instantaneous, annealed networks that are characterised by a small average degree and modularity. In the opposite limit instead, the process would effectively unfold on static networks obtained integrating links over longer time characterised by high average degree and low modularity. Indeed, the average degree in this regime will be dominated by out-community links that make the connections between different communities increasingly stronger, thus increasingly destroying the identity of communities. In the limit $${\tau }_{p}\sim \tau (a,s)$$ the process would effectively evolve on maximally modular networks (for a given set of parameters). Arguably, this is the most interesting regime that we will consider in the following.

### Epidemic processes on modular activity driven networks

Let us turn our attention on the dynamical properties of SIR and SIS processes (see the Methods section for a detailed definition of the two) unfolding on the proposed model. Although similar, the two processes are intrinsically different33,57,58,59. Indeed, SIR processes are always characterised by the so called disease-free equilibrium, provided d t N = 0. The illness eventually disappear, i.e., I = 0 for t → ∞. SIS models instead allow the existence of an endemic state where a finite and constant fraction of infected individuals permanently colonise the population, i.e., I > 0 for t → ∞. Here, we focus on a central concept of contagion phenomena: the epidemic threshold. This quantity defines the conditions necessary for the spreading of the illness. In annealed networks, the threshold is determined by the moments of the degree distribution ρ(k). In static graphs the expression is given by the principle eigenvalue of the adjacency matrix57,60,61. In time-varying networks instead, the threshold is determined by the interplay between the time-scales of the contagion and network evolution processes24,41,45,50,62,63,64,65,66,67,68,69. In the case of SIR models, we also consider another important quantity: the epidemic size R which is defined as the final ratio of recovered nodes. This describes the fraction of nodes affected by the disease.

To develop a deeper understanding, let us derive the mean-field level dynamical equations describing the contagion process in modular activity driven networks. We define the activity block variables Sa,s, Ia,s, and Ra,s as the number of susceptible, infected and recovered individuals, respectively, in the class of activity a and community of size s at time t (to enhance readability, we omit to notate the dependence on time). This allows us to write the mean-field evolution of the number of infected individuals, for a SIR process, in each group of nodes with activity a as:

$$\begin{array}{rcl}{d}_{t}{I}_{a,s} & = & -\gamma {I}_{a,s}+\lambda {S}_{a,s}[\mu a\frac{{I}_{s}}{s}+\mathrm{(1}-\mu )a\frac{I}{N}]\\ & & +\lambda \sum _{a^{\prime} }\,a^{\prime} [\mu {I}_{a^{\prime} ,s}\frac{{S}_{a,s}}{s}+\mathrm{(1}-\mu ){I}_{a^{\prime} ,s}\frac{{S}_{a,s}}{N}],\end{array}$$
(5)

where I s and I are the number of infected in communities of size s and in the whole network, respectively. The first term in the r.h.s. accounts for the recovery of infected individuals. The other four terms account for the probability that a Susceptible node in a community of size s connects to an Infected node inside (first) or outside (second) its community acquiring the infection, and for the probability that an Infected node of class a′ connects to a Susceptible node inside (third) or outside (forth) a community of size s, contracting the disease. For simplicity, we consider that N − s ~ N and, at least initially, I − I s  ~ I. Summing over all the activities and community sizes, and considering only the first order terms in a, Ia,s, Ra,s and their products, we obtain

$${d}_{t}I=-\gamma I+\lambda \langle a\rangle I+\lambda {\rm{\Theta }}+\lambda \mu \,\sum _{s}\,({\langle a\rangle }_{s}-\langle a\rangle ){I}_{s},$$
(6)
$$\begin{array}{rcl}{d}_{t}{\rm{\Theta }} & = & -\gamma {\rm{\Theta }}+\lambda \langle {a}^{2}\rangle I+\lambda \langle a\rangle {\rm{\Theta }}\\ & & +\lambda \mu \,\sum _{s}\,[({\langle {a}^{2}\rangle }_{s}-\langle {a}^{2}\rangle ){I}_{s}+({\langle a\rangle }_{s}-\langle a\rangle {){\rm{\Theta }}}_{s}],\end{array}$$
(7)

where we defined $${\rm{\Theta }}={\sum }_{a}\,a{I}_{a}$$, and $${{\rm{\Theta }}}_{s}={\sum }_{a}\,a{I}_{a,s}$$. The term $${\langle {a}^{x}\rangle }_{s}={\sum }_{a}\,{N}_{a,s}{a}^{x}/s$$ describes the moments of the activity distribution in any community of size s. The second, auxiliary, equation is obtained from the first by multiplying both sides by a and summing over all s and a. The epidemic threshold, in principle, can be derived evaluating the principle eigenvalue of the Jacobian matrix of the system of differential equations in I and Θ24,41,45,50,69,70. In general, a closed expression for the threshold does not exist. However, we can point out some interesting observations.

First of all, the terms associated to Ra,s vanish, implying that, at the first order, the thresholds of both SIR and SIS are equal50. Furthermore, the terms in μ weight a comparison between the moments of the activity distribution in the network with the corresponding quantities evaluated inside each community. If fluctuations of these terms are negligible, due for example to very large community sizes or to narrow distribution of activity, the equations become equivalent to the case μ = 0. In the limit μ → 0 the network has no modular structure, and the threshold, for both SIR and SIS, becomes $$\beta /\gamma \ge \mathrm{2/}(1+\sqrt{\chi })$$ as derived with different approaches in refs24,41,45,71. We defined χ = 〈a2〉/〈a2, where the moments are evaluated over the whole network. As expected, the spreading condition is determined by the interplay between the time-scale of the contagion process and the time-scale of the network. Furthermore, the threshold is significantly larger with respect to the case in which the disease would spread in static or annealed networks generated integrating connections over time24. Indeed, the concurrency of contacts in the two time scale separation regimes drastically facilitates the spreading of diseases23,72. It is important to notice how the threshold is not function of m even in the case of m > 1. This is due to the fact that we absorbed the contact rates in the definition of β. As detailed in the methods section, this is defined as the per capita rate of infection. By adopting such definition, we are able to estimate the spreading power of a disease independently of possible differences in contacts rates. The expression could be easily changed to explicitly account this aspect obtaining $$\lambda /\gamma \ge \frac{1}{m\langle a\rangle \,(1+\sqrt{\chi })}$$24,46,73. In the opposite limit μ → 1 networks are extremely modular, fluctuations become important and the symmetry between SIR and SIS breaks. In order to understand this limit, let us consider first a SIR process started from a single infected node in a community of size s. The large majority of connections are towards a small number of vertices in the same group. As soon as the disease start to spread within the community the number of infected and then recovered nodes grows, thus the probability of links I − I and I − R increases. Such connections cannot help the spreading of the disease. In fact they hamper the contagion process. In case instead of a network characterised by smaller values of modularity the growth of infected and recovered nodes has a much smaller effect. Indeed, the connectivity between communities would guarantee access to larger pool of susceptible nodes to sustain the spreading. From these simple observations we can expect that SIR processes are inhibited by highly modular connectivity patterns. Except for few exceptions in particular topologies17, this is the case on static and annealed graphs12,13,14,15,16,17. As we will show below, the same arguments hold also in time-varying connectivity patterns. On the other hand, in case of SIS processes, the repetition of contacts does not lead to such “pair annihilation”: contacts between infected nodes do not help the spreading of the disease, but they are only temporary (eventually, all infected nodes become susceptible again). Thus, we expect that modularity plays a different role in SIS dynamics. This is what has been found also in the case of one annealed network model18. Below we will show how this applies also in the case of time-varying networks. In order to numerically characterise SIR models, we study the epidemic size, R, as a function of β/γ. This quantity acts as the order parameter of a second-order phase transition6. For SIS processes instead, the order parameter is the final fraction of infected individuals, I6. The numerical estimation of this quantity is challenging, since it requires the precise determination of endemic states. For these reasons, we follow ref.74, measuring the life time of the disease, L, that acts as the susceptibility in phase transitions74,75. This quantity is defined as the average time it takes for the disease to either die out or reach a macroscopic fraction, Y, of the populations. Without loss of generality, we start our simulations by setting 1% of randomly selected nodes as initial infected seed. Other parameters are set as: γ = 0.01, m = 1, ν = 2.1, ω = 2.1, N = 105 and Y = 0.5 (see SI for similar plots obtained fixing ω = 1.5).

Results obtained from SIR models are represented in Fig. 4A,B, whilst results from SIS models are shown in Fig. 5A,B. In Figs 4B and 5B we study different community structure, either by considering a constant community size (dashed curves) or by drawing community sizes directly from the community size distribution P(s) (solid curves). In general, red curves represents a network with bigger communities than the one represented with blue curves.

For SIR models, Fig. 4A tells us that, as expected, the higher β/γ the higher the epidemic size. The figure also confirm the intuitions about the threshold. Indeed, we observe a dependence on μ: the higher μ the higher the threshold. However, it is important to notice how such dependence is weak especially when compared with the SIS case (see below). Moreover, the higher the fraction of links created between pair of nodes sharing the same community (i.e. the higher μ), the lower the epidemic size. This second observation is confirmed studying different community structures, as done in Fig. 4B, in which we plot the maximum epidemic size (corresponding to the largest value of β/μ in our settings), Rmax, as a function of μ. In the limit μ → 0, we observe that the disease impact is the same: the networks behave as if no community structure was present. Instead, when μ → 1, the modular structure influences the spread of the disease. As mentioned before, repeating contacts within communities significantly narrows the chances of having new infected individuals. Indeed, in SIR models, once a node recovers, it cannot be infected again. Repeating contacts with nodes already recovered does not favour the spread of the disease. Overall, the main observations are four. (i) Increasing the modularity reduces the epidemic size. (ii) A network with, on average, larger modules is likely to yield a higher epidemic size. (iii) The larger the modules the weaker the dependence on μ of the epidemic size. (iv) In case of small modules, the distribution of community sizes seems to influence the spreading of the disease. In particular, a network organised in small groups of constant sizes leads to smaller epidemic size respect to a network in which the average community size is the same, but individual sizes are extracted from a power-law distribution.

For SIS models, the lower μ, the lower the life time L (see Fig. 5). Inter-community links speed up the disease spreading and an endemic state, i.e. Y = 0.5, is reached faster. Moreover, the higher μ, the lower the epidemic threshold. This last observation, which implies that increasing values of modularity favour the survival of the disease, is confirmed in Fig. 5B where we also test the effects of different community structures. In the limit μ → 0, there is no community structure and the curves converge to the same epidemic threshold. On the contrary, when μ → 1, the community structure becomes increasingly important and influences the spreading. Qualitatively, higher levels of modularity diminish the epidemic threshold. This is due to the repetition of the same contacts within a community which becomes increasingly more likely. Indeed, in SIS models, reinfection is allowed and nodes can become infected many times: communities act as a reservoir for the disease and favour the contagion process pushing the epidemic threshold to smaller values. Besides this last point, there are two main observations. (i) A network with larger modules is likely to have an higher epidemic threshold. (ii) In case of communities with smaller average sizes and high values of modularity, having the community size extracted from a power-law seems to slightly increase the threshold. Thus, the disease is able to spread more easily in modular networks with communities of similar or equal sizes. With the exception of one data point, this is observed for μ > 0.5 (see the dashed blue line in Fig. 5B).

### Real networks

Although the modelling framework presented captures realistic activity and community size distributions of real networks, it neglects other important features such as burstiness76,77,78,79,80, and more complex temporal/structural correlations81,82,83,84,85. It is then crucial grounding the picture emerging from synthetic models with a real world system. To this extent, we consider a temporal and modular network about scientific collaborations in the American Physical Society (APS). We study 96940 scholars connected by 692667 links (see the Supplementary Information for more details)86. We focus on ten years of data (January 1997–December 2006) coarse-grained at a time resolution of one month. To single out the effects introduced by communities on contagion processes, we consider also a randomised version of the dataset. Here, the interactions at each time are shuffled, destroying the community structure, but the sequence of activation times for each node and the degree distribution at each time step are preserved87. In order to make sure that the randomisation process removes topological structures, we integrate the two networks over all time steps and we use OSLOM88 to find the communities. The modularity89 of the real APS network is Q = 0.6685, and of its randomised counterpart Q = 0.0937. As expected, the degree preserving randomisation reduces the modularity significantly. Using these two networks, we study the dynamical properties of SIR and SIS processes unfolding on their structure. In Fig. 6A,B we present the results. The modular properties of the real network do not influence the threshold of SIR models. Considering the weak dependence on the modularity observed in synthetic networks this results is not surprising. Even more, in this case the maximum value of modularity is defined by the data. We cannot increase it manually as done in our model. Nevertheless, the presence of communities reduces the impact of the disease, i.e. lowers the epidemic size. In the case of SIS processes instead, communities have a larger effect shifting the threshold to smaller values. These results qualitatively confirm what observed in synthetic systems.

## Discussion

In both processes nodes are divided in different classes according to their disease status. In SIR models nodes are either Susceptible (S), Infected (I) or Recovered (R). Susceptible nodes describe healthy individuals. Infected nodes contract the disease and are infectious. Recovered nodes are no longer infected and acquire complete immunity to the illness. The model is fully characterized by two transitions: $$S+I\mathop{\to }\limits^{\beta }2I$$ and $$I\mathop{\to }\limits^{\gamma }R$$. The first describes the infection propagation and β is the capita infection rate. This quantity is defined by the average contacts per node 〈k〉 and by the per contact probability of transmission λ, i.e. β = λk〉. The second transition describes the recovery process. Infected individuals recover spontaneously and permanently with rate γ. In SIS models instead we have just Susceptible and Infected nodes. While the contagion process is equivalent to the SIR case, the recovery is different and described by the following transition: $$I\mathop{\to }\limits^{\gamma }S$$. Infected nodes spontaneously return in the susceptible compartment with rate γ.