## Introduction

### Stability and perturbation in the microbiome

The human microbiome is a complex ecosystem. While stability is the norm in the gut microbiome, disturbances and their consequences are important when considering its impact on health [1]. A course of antibiotics is a major perturbation, typically leading to a marked reduction in species diversity before subsequent recovery [2]. Aside from concerns about the development of antibiotic resistance, even a brief course can result in long-term effects on community composition [3]. However, modelling the recovery of the microbiome is challenging, due to the difficulty of quantifying the in vivo effects of antibiotics on the hundreds of co-occurring species that make up microbial communities within the human body.

Artificial perturbation experiments are widely used to explore the underlying dynamics of macro-ecological systems [4]. In the context of the gut microbiome, the effects of antibiotics have previously been investigated [5,6,7], but despite interest in the application of ecological theory to the gut microbiome [8] the nature of this recovery remains unclear. While responses can appear highly individualized [7] this does not preclude the possibility of generalized models applicable at the population level.

Applying mathematical models to other ecological systems subject to perturbation can give useful insight [9,10,11]. Crucially, it allows the comparison of different hypotheses about the system using model selection. Developing a consistent mathematical framework for quantifying the long-term effects of antibiotic use would also facilitate comparisons between different antibiotics and different regimens, with the potential to inform approaches to antibiotic stewardship [12].

### Previous modelling approaches

A great deal of modelling work has focused on the gut microbiome’s response to antibiotic perturbation. We mention a few important examples here. Bucci et al. [13] used a two-compartment density model with species categorized as either antibiotic-tolerant or antibiotic-sensitive, and fitted their model to data from Dethlefsen and Relman [7]. In a later review, Bucci and Xavier argued that models of wastewater treatment bioreactors could be adapted for the gut microbiome, with a focus on individual-based models [14]. The most commonly-used individual-based model is the multispecies Generalized Lotka–Volterra (GLV) model, which describes pairwise interactions between bacterial species (or other groupings). In a pioneering work, Stein et al. [15] extended a GLV model to include external perturbations, and fitted their model to a study where mice received clindamycin and developed Clostridium difficile infection (CDI) [16]. The same approach was also subsequently applied to human subjects, identifying a probiotic candidate for treating CDI [17]. Bucci et al. [18] have combined and extended their previous work into an integrated suite of algorithms (MDSINE) to infer dynamical systems models from time-series microbiome data.

While all of these models have provided useful insights into microbiome dynamics, to make meaningful inference they require dense temporal sampling and restriction to a small number of species. For example, the examples of application of MDSINE had “26–56 time points” for accurate inference of dynamics, measurements of relative concentrations of bacteria, and frequent shifts of treatment—for these reasons the in vivo experiments were conducted in gnotobiotic mice [18]. Similarly, Stein et al. restricted their analysis of CDI to the ten most abundant bacterial genera [15]. Such restrictions reduce the suitability of these methods for opportunistic analysis of existing 16S rRNA gene datasets from the human microbiome, which currently comprise the majority of clinically relevant datasets. GLV models can undoubtedly be extremely useful for simple synthetic consortia, as shown by Venturelli et al. who inferred the dynamics of a 12-species community [19]. However, it has been shown that even for very small numbers of species, pairwise microbial interaction models do not always accurately predict future dynamics, suggesting that pairwise modelling has its own limitations [20].

Starting from broader ecological principles allows quantitative investigation of high-level statements and hypotheses about microbiome dynamics. For example, Coyte et al. built network models based on principles from community ecology to show that competitive interactions in the gut microbiome are associated with stable states of high diversity [21]. More recently, Goyal et al. took inspiration from the ‘stable marriage problem’ in economics and showed that multiple stable states in microbial communities can be explained by nutrient preferences and competitive abilities [22]. There is therefore great value in exploring alternative modelling approaches to GLV models as well as continuing to refine and extend them.

### A stability landscape approach

In a popular schematic picture taken from classical ecology, the state of the gut microbiome is represented by a ball sitting in a stability landscape [1, 23,24,25]. Perturbations can be thought of as forces acting on the ball to displace it from its equilibrium position [25] or as alterations of the stability landscape [26]. While this image is usually provided only as a conceptual model to aid thinking about the behaviour of the ecosystem, here we use it to derive a mathematical model.

We model the effect of a brief course of antibiotics on the microbial community’s phylogenetic diversity as the impulse response of an overdamped harmonic oscillator (Fig. 1; see Methods), and compare parameters for four widely-used antibiotics by fitting to empirical data previously published by Zaura et al. [3]. This model is significantly less complicated than previous models developed for similar purposes, but still captures some of the essential emergent features of such a system while avoiding the computational difficulties of fitting hundreds of parameters to a sparse dataset. After demonstrating the effectiveness of this modelling approach for the gut and oral microbiome, we also show that the framework can easily be used to test hypotheses about microbiome states. We compare a model variant, which allows a transition to a new equilibrium, and find that this model is better supported for clindamycin and ciprofloxacin, allowing us to conclude that these antibiotics can produce state transitions across different microbiomes. We also find a transition to a new equilibrium when reanalyzing a separate dataset from Palleja et al. [27], using a different diversity metric that had already been calculated by the authors (richness) based on applying a different sequencing approach (shotgun metagenomics) to an different antibiotic regimen (meropenem, gentamicin, and vancomycin). This modelling approach can therefore be easily applied to sparse datasets from different human microbiomes, antibiotics, and sequencing approaches, providing a simple but consistent foundational framework for quantifying the in vivo impacts of antibiotics.

## Results

### Ecological theory motivates a simplified representation of the microbiome

Taking inspiration from classical ecological theory, the microbiome can be considered as an ecosystem existing in a stability landscape: it typically rests at some equilibrium, but can be displaced (Fig. 1a). The shape of this landscape is determined by the extrinsic environmental factors; a change in these could produce a (reversible) change in the shape of the landscape e.g. shifts in the human gut microbiome when an individual temporarily relocates from the USA to Southeast Asia, which are reversed on return [28]. Here we assume that these environmental factors remain approximately constant at the timescales considered (<1 year), based on previous observations e.g. that the oral microbiome can exhibit stability over periods of at least 3 months [29], and the gut microbiome for up to 5 years [30]. Any quantitative model of the microbiome based on this concept then requires a definition of equilibrium and displacement. While earlier studies sought to identify a equilibrium core set of ‘healthy’ microbes, disturbances of which would quantify displacement, it has become apparent that this is not a practical definition due to high inter-individual variability in taxonomic composition [25]. More recent concepts of a healthy ‘functional core’ appear more promising, but characterization is challenging, particularly as many gut microbiome studies use 16S rRNA gene sequencing rather than shotgun metagenomic sequencing.

For these reasons, we choose a metric that offers a proxy for the general functional potential of the gut microbiome: phylogenetic diversity [25]. Diversity is commonly used as a summary statistic in microbiome analyses and higher diversity in the gut microbiome has previously been generally associated with health [31] and temporal stability [32]. Of course, describing the microbiome using only a single number loses a great deal of information. Furthermore, there is no general relationship between ‘diversity’ and ‘stability’: the relationship depends on the specific definitions of both quantities. We are interested in the scenario of fixed-length perturbations, where ‘stability’ can be quantified in terms of the rate of return to equilibrium after perturbation—this stability has been empirically observed to increase with greater species diversity [33]. If we are seeking to build a general model of microbiome recovery after perturbation, it seems appropriate to consider a simple metric first to see how such a model performs before developing more complicated definitions of equilibrium, which may generalize poorly across different niches and individuals. Other scenarios might require different definitions and correspondingly different assumptions.

We assume the equilibrium position to have higher diversity than the points immediately surrounding it i.e. creating a potential well (Fig. 1b). However, there may be alternative stable states (Fig. 1b) that perturbations may move the microbiome into (Fig. 1c). These states may be either higher or lower in diversity; for our purposes, all we assume is that they are separated from the initial equilibrium by a potential barrier of diversity, i.e. a decrease of diversity is required to access them, which helps to keep the microbiome at equilibrium under normal conditions. Our strong assumption here is obviously influenced by the specific perturbation scenario: we know a priori that antibiotics decrease diversity in the short-term, so we are not attempting to model other types of transition. However, considering the empirical evidence and the consensus view among ecologists that a diversity of species with a range of sensitivities to different environmental conditions should lead to greater stability [33, 34], we feel this rule may hold in a range of other scenarios: ecosystems may often exist at or near a (local) maximum value of diversity. An equilibrium does not have to be believed in as a true and eternal state; we attempt here to use insights from theoretical communities with well-defined mathematical equilibria to move to modelling empirical communities where they are approximate concepts, valid over some given time period.

### The model

Mathematically, small displacements of a mass from an equilibrium point can be approximated as a simple harmonic oscillator [35] for any potential function (continuous and differentiable). This approximation comes naturally from the first terms in the Taylor expansion of a function [36], and can be extremely accurate for small perturbations. By assuming the local stability landscape of the microbiome can be reasonably approximated as a harmonic potential, we are assuming a ‘restoring’ force proportional to the displacement x from the equilibrium position (−kx) and also a ‘frictional’ force acting against the direction of motion ($$- b\dot x$$). The system is a damped harmonic oscillator with the following equation of motion:

$$\frac{{d^2x}}{{dt^2}} + b\frac{{dx}}{{dt}} + kx = 0$$
(1)

Additional forces acting on the system—perturbations—appear on the right-hand side of this equation. Consider a course of antibiotics of duration τ. If we are interested in timescales of $$T \gg \tau$$ (e.g. the long-term recovery of the microbiome a year after a week-long course of antibiotics) we can assume that this perturbation is of negligible duration. This assumption allows us to model it as an impulse of magnitude D acting at time t = 0:

$$\frac{{d^2x}}{{dt^2}} + b\frac{{dx}}{{dt}} + kx = D\delta \left( t \right)$$
(2)

This second-order differential equation can be solved analytically and reparameterized (see Methods) to give a model with three parameters, with a general qualitative shape of sudden change followed by slower recovery (Model 1, Fig. 1c):

$$x_1\left( t \right) = \frac{{De^{\phi _1}e^{\phi _2}}}{{e^{\phi _2} - e^{\phi _1}}} \cdot \left( {e^{ - e^{\phi _1}t} - e^{ - e^{\phi _2}t}} \right)$$
(3)

### Fitting the model to empirical data

We fit the model to published data from a paper from Zaura et al. [3] where individuals received a 10-day course of either a placebo or one of four commonly-used antibiotics (Table 1). Faecal and saliva samples were taken at baseline (i.e. before treatment), directly after treatment, and then 1 month, 2 months, 4 months, and 1 year after treatment. Zaura et al. conducted pairwise comparisons between timepoints and comprehensively reported statistical associations, but did not attempt any explicit modelling of the time-response over the year. This dataset provides an ideal test case for our model. Not only does it allow us to simultaneously model the recovery of both the gut and oral microbiomes after different antibiotics, but it also demonstrates how our modelling framework permits further conclusions beyond the scope of the initial study. We additionally fit our model to a shotgun metagenomics dataset from a recent antibiotic perturbation experiment from Palleja et al. [27].

### A stability landscape framework successfully describes initial microbiome dynamics

Although individual microbiome responses were personalized (Supplementary Figure 1), normalized diversity trajectories followed the same general pattern for each antibiotic (Supplementary Figure 2). We used a Bayesian approach to fit the model to each treatment group and microbiome separately, successfully capturing the main features of the initial response to antibiotics (Fig. 2). Diversity decreased (i.e. positive displacement from equilibrium increased) before a slow return to equilibrium. Despite large variability between samples from the same treatment group, reassuringly the placebo group clearly did not warrant an impulse response model, whereas data from individuals receiving antibiotics were qualitatively in agreement with the model. Even without the model, it is apparent that clindamycin and ciprofloxacin represent greater disturbances to the microbiome than minocycline and amoxicillin, but a consistent model allows comparison of the values of various parameters (see ‘Comparison of parameters between antibiotics’ below).

In their original analysis, Zaura et al. noted significantly (p < 0.05) reduced Shannon diversity in individuals receiving ciprofloxacin comparing samples after a year to baseline. This reduced diversity could in principle merely be due to slow reconstitution and return to the original equilibrium. However, by taking into account each individual’s temporal response with a model rather than pairwise comparisons it appears that slow reconstitution cannot be the whole story. Instead, the skewed distribution of residuals after a year, when the response has flattened off, indicates that the longer-term dynamics of the system do not obey the same impulse response as the short-term dynamics. A scenario involving a long-term transition to an alternative stable state is consistent with this observation (Fig. 1). We therefore developed a variant of the model to take into account alternative equilibria, aiming to test the hypothesis that the microbiome had transitioned to an alternative stable state.

### Support for the existence of antibiotic-induced state transitions

In our approach, a transition to an alternative stable state means that the value of diversity displacement from the original equilibrium asymptotically tends to a non-zero value. There are many options for representing this mathematically; for reasons of simplicity, we add a single parameter A and a term that asymptotically grows over time (Model 2, Fig. 1c):

$$x_2\left( t \right) = \frac{{De^{\phi _1}e^{\phi _2}}}{{e^{\phi _2} - e^{\phi _1}}} \cdot \left( {e^{ - e^{\phi _1}t} - e^{ - e^{\phi _2}t}} \right) + A \cdot \left( {1 - e^{ - e^{\phi _1}t}} \right)$$
(4)

Qualitatively, this slightly more complex model gave a similar fit (Fig. 3) but some treatment groups had a clear non-zero final displacement from equilibrium, corresponding to an alternative stable state. We compared models with the Bayes factor BF, where BF > 1 indicates support for a state transition (Table 2). A state transition was supported in the ciprofloxacin and clindamycin treatment groups for both the gut (BFcipro = 3.06, BFclinda = 10.94) and oral (BFcipro = 16.87, BFclinda = 7.47) microbiomes. The posterior estimates for the asymptote parameter in the gut microbiome were positively skewed (Fig. 4), providing evidence of a transition to a state with lower phylogenetic diversity. Contrastingly, in the oral microbiome the asymptote parameter was negatively skewed, suggesting a transition to a state with greater phylogenetic diversity. Strikingly, these are the respective states associated with poorer health in both microbiomes.

### Comparison of parameters between antibiotics

Comparing the posterior distribution of parameters for model 2 fits allows quantification of the ecological impact of different antibiotics (Table 3, Fig. 4). Unsurprisingly, greater perturbation is correlated with the transition to an alternative stable state. We can also consider the ecological implications of the parameters we observe. The damping ratio $$\zeta = b/\left( {2\sqrt k } \right)$$ summarizes how perturbations decay over time, and is considered as an inherent property within the model. Therefore, if our modelling framework and ecological assumptions were valid we would expect to find a consistent damping ratio across both the clindamycin and ciprofloxacin groups in the gut microbiome. This is indeed what we observed with median (95% credible interval) damping ratios of $$\zeta _{{\mathrm{clinda}}}$$ = 1.07 (1.00–1.65) and $$\zeta _{{\mathrm{cipro}}}$$ = 1.07 (1.00–1.66), substantially different from the prior distribution, supporting the view that the gut microbiome dynamics can be approximated by a damped harmonic oscillator.

### Application to other sequencing approaches and diversity metrics

In a recent paper, Palleja et al. [27] used deep shotgun metagenomic sequencing to characterize the gut microbiomes of twelve healthy men for 180 days after a 4-day course of meropenem, gentamicin, and vancomycin. They observed that while there were no significant differences in the Shannon diversity between baseline and day 180, there was a significant difference in species richness. Furthermore, they noted that compositional changes between day 42 and day 180 were not significantly different when compared to paired samples in Human Microbiome Project controls. Both these two pieces of information suggest a state transition, although Palleja et al. do not use this terminology and instead refer to a return to “stable composition”. Reanalyzing this species richness data with our model shows that the gut microbiomes of these individuals had transitioned to a new alternative state (Supplementary Figure 3; Table 4), strengthening Palleja et al.’s conclusion that some bacteria may have been permanently lost [27]. Other future metagenomic datasets could also be analyzed using our model in this way.

### Connection to generalized Lotka–Volterra models

We sought to establish a link between our framework and the conventional ‘bottom-up’ approach of GLV models. We investigated the behaviour of a 3-species Lotka–Volterra system to establish if perturbation to an alternative state was possible in this simple case (see Methods: ‘Lotka–Volterra simulations’). We found that only 0.079% of 3-species Lotka–Volterra systems exhibit the behaviour required by our two-state model—because we assume that diversity is continuous, this model is unrealistic for small species numbers. However, for larger numbers, theoretical ecology gives strong justification for our assumptions. As the number of species n increases, the number of fixed points that are stable increases [37], and the proportion of simulations from random parameters that have multiple fixed points also increases e.g. with n = 400, this proportion is >97% [38]. This suggests that the overwhelming majority of mathematically possible systems at relevant numbers of species exhibit multiple fixed points; the fraction of biologically possible systems exhibiting this behaviour is likely even higher. Furthermore, when the realistic assumption of resource competition is incorporated, all these fixed points become stable or marginally stable [38]. Goyal et al. recently showed that multiple resilient stable states can exist in microbial communities if microbes utilize nutrients one at a time [22]. We can therefore state confidently that: the gut microbiome can be treated as having multiple stable equilibria; its community composition is history-dependent; and perturbations lead to transitions between the multiple possible stable states. These assumptions are the basis of the simplistic coarse-grained model we describe here, which effectively takes these high-level emergent properties of multispecies Lotka–Volterra models to build a substantially simpler model based on a single, commonly-used metric: diversity.

## Discussion

Starting from a conceptual picture of the microbiome resting in a stability landscape, we have developed a mathematical model of its response to antibiotic perturbation. Our framework, based on phylogenetic diversity, successfully captures the dynamics of a previously published 16S rRNA gene dataset for four common antibiotics [3], providing quantitative support for these simplifying ecological assumptions. Using model selection, our framework provides additional insight—we find that the effects of clindamycin persist for a year after exposure, and also identify a state transition in the oral microbiome with clindamycin, neither of which was detected by the initial authors. We also demonstrate the flexibility of our model by fitting it to data from a recent shotgun metagenomics antibiotic perturbation experiment [27].

While pairwise comparisons of diversity can still identify differences in microbiome state, they provide no information on dynamics. Our framework therefore gives additional insight in this regard. Zaura et al. observed that the lowest diversity in the gut microbiome was observed after a month rather than immediately after treatment [3]. This cannot be due to a persistence of the antibiotic effect, as all antibiotics used have short half-lives of the order of hours [39, 40]. Within our framework, this can be understood as an overdamping effect: we found a consistent damping ratio for both ciprofloxacin and clindamycin. This is not in itself a complete explanation (it does not identify a mechanistic biological process behind the ‘damping’) but it gives insight that such a process may exist.

We have also demonstrated how our framework could be used to compare different hypotheses about the long-term effects of antibiotic perturbation by fitting different models and using Bayesian model selection. Our model provides an additional line of evidence that while short-term restoration obeys a simple impulse response, the underlying long-term community state can be fundamentally altered by a brief course of antibiotics, as suggested previously [7], raising concerns about the long-term impacts of antibiotic use. While this state transition may not necessarily equate to any negative health impacts for the host (none of the participants involved in the original study [3] reported any gastrointestinal disturbance), the transition to a new state with reduced diversity in the gut microbiome may increase the risk of colonisation and overgrowth of pathogenic species. It has been shown experimentally in Drosophila that invasion and subsequent colonization is a stochastic process that is reduced by a more diverse gut [41]. Conversely, in the oral microbiome the state transition was to a state with increased diversity, which is correspondingly associated with a greater risk of disease in the oral cavity [42]. We believe this makes sense within a stability landscape framework. Even if only marginal, when considered at a population level, such effects may mean that antibiotics have substantial negative health consequences, which could support reductions in the length of antibiotic courses independently of concerns about antibiotic resistance [43]. Modelling the long-term impact on the microbiome of different doses and courses could help to influence antibiotic use in routine clinical care. Our sample size is small, so the precise posterior estimates for parameters that we obtain should not be over-interpreted, but comparing antibiotics using these parameter estimates represents another practical application.

Our framework lends itself naturally to comparing different dynamical models. We see our two variant models as a starting point for stability landscape approaches, and would hope that better models can be constructed. Hierarchical mixed effects models may offer an improved fit, particularly if they take into account other covariates; we lacked the necessary metadata on the participants from the original study (Table 1) to explore such models. Furthermore, diversity as a single metric clearly fails to capture all the complexity of the microbial community and its interactions, and there are multiple issues with calculating it accurately. Nevertheless, the observation that treating phylogenetic diversity as the key variable in the stability landscape captures microbiome dynamics supports observations of functional redundancy in the microbiome [31]. An interesting extension of this work would be to systematically fit the model to a variety of diversity metrics or other summary statistics and assess the model fit to see which metric (or combination of metrics) is most appropriately interpreted as the state variable parameterising the stability landscape. A complementary approach could consider the ‘resistome’, which should conversely rise in diversity after antibiotic treatment [44].

Expanding the stability landscape approach to other microbiome datasets might require re-examining our assumptions. A non-diversity metric might well be superior in situations where the ‘ideal’ state of the microbiome can be clearly defined: for example, in a bioreactor where experimental conditions can be maintained to consistently produce a given equilibrium community composition, one could define displacement using ecological distance from this well-defined state. However, even a single microbial strain under constant conditions can exhibit astonishing and unpredictable complexity over time [45], so we feel that diversity is a good starting point. As a general guide for experiments, because an impulse response model for a perturbation of length τ assumes an experiment length $$T \gg \tau$$, we suggest the appropriate sampling effort for microbiomes undergoing perturbation should be to have samples immediately before and after, as well as samples out to T > 30τ. We recommend more dense sampling at longer times to firmly establish whether a new equilibrium state has been reached.

We would not expect the behaviour of the microbiome after longer or repeated courses of antibiotics to be well-described by our model, which assumes a course of negligible duration. Nevertheless, it would be possible to use the stability landscape framework given here to obtain an analytic form for the possible system response by convolving any given perturbation function with the impulse response, although the model might break down in such circumstances. If the model fails to give a good fit, the inclusion of higher-order terms in the Taylor expansion of the chosen potential function about equilibrium (and correspondingly modifying Eq. 1) could prove useful.

As we have demonstrated, while the precise nature of the gut microbiome’s response to antibiotics is individualized, a general model still captures important dynamics. We believe it would be a mistake to assume that our model is ‘too simple’ to provide insight on a complex ecosystem. At this stage of our understanding, creating a comprehensive inter-species model of the hundreds of members of the gut microbiome is intractable; it may also be unnecessary if the aim is to inform clinical treatment based on sparse data. We believe there is a place for both fine-grained models using pairwise interactions—particularly for systems of reduced complexity—and coarse-grained models built from high-level ecological principles, as we have demonstrated here. Shade has argued that microbiome diversity is “the question, not the answer” [46]; diversity can still be an extremely useful quantity for modelling, but the patterns we report here warrant more mechanistic investigation. We have argued that a ‘top-down’ framework with multiple stable states of different diversities is consistent with the emergent behaviour of a multispecies Lotka–Volterra model. Further mathematical work to connect these two extremes would be worthwhile.

## Materials and methods

### Mathematical model of trajectories in the potential landscape

Treating the microbiome as a unit mass resting in a stability landscape parameterized by phylogenetic diversity leads to a second-order differential equation. To solve this equation, we assume that b2 > 4k (the ‘overdamped’ case) based on the lack of any oscillatory behaviour previously observed in the microbiome. Then, subject to the initial conditions x(t = 0) = 0 and $$\dot x\left( {t = 0} \right) = D$$ we obtain the following equation describing the system’s trajectory:

$$x\left( t \right) = \frac{D}{{2 \cdot \sqrt {\left( {\frac{b}{2}} \right)^2 - k} }}\left( {e^{ - \left( {\frac{b}{2} - \sqrt {\left( {\frac{b}{2}} \right)^2 - k} } \right)t} - e^{ - \left( {\frac{b}{2} + \sqrt {\left( {\frac{b}{2}} \right)^2 - k} } \right)t}} \right)$$
(5)

Fitting the model therefore requires fitting three parameters: b (the damping on the system), k (the strength of the restoring force), and D (how strong the perturbation is). For the purposes of fitting the model, having parameters be allowed values over all real numbers (−∞, +∞) is preferable to only positive numbers (0, +∞), so we choose to reparameterize the model using the following definitions:

$$b = e^{\phi _1} + e^{\phi _2}$$
(6)
$$k = e^{\phi _1 + \phi _2}$$
(7)

This results in Model 1 (Eq. 3, Fig. 1c).

Antibiotics may lead not just to displacement from equilibrium, but also state transitions to new equilibria [2]. To investigate this possibility, we also consider a model where the value of equilibrium diversity asymptotically tends to a new value A. To minimize model complexity, we add a single parameter with a term that asymptotically grows over time, resulting in Model 2 (Eq. 4, Fig. 1c).

### Main experimental dataset

To apply our framework, we fitted both models to two empirical datasets (see Supplementary Text 1). Zaura et al. [3] conducted a study on the long-term effect of antibiotics on the gut and oral microbiomes, where individuals were randomly assigned to one of five treatment groups: placebo, clindamycin, ciprofloxacin, minocycline, or amoxicillin (Table 1). Samples were collected at baseline (before treatment), immediately after exposure, then at 1 month, 2 months, 4 months, and 1 year after treatment.

### Phylogenetic diversity

There are many possible diversity metrics that could be used to compute the displacement from equilibrium. Because of our assumptions (see ‘Ecological theory motivates a simplified representation of the microbiome’), we chose to use Faith’s phylogenetic diversity [47] (see Supplementary Text 1).

### Bayesian model fitting

We used a Bayesian framework to fit our basic model 1 (Eq. 3) using Stan [48] and RStan [49] to the gut and oral microbiome samples for the five separate groups: placebo, ciprofloxacin, clindamycin, minocycline, and amoxicillin (i.e. n = 2 × 5 = 10 fits). In brief, our approach used four chains with a burn-in period of 1000 iterations and 9000 subsequent iterations, verifying that all chains converged ($$\hat R$$ = 1) and the effective sample size for each parameter was sufficiently large (n_eff  > 1000). We additionally fitted model 2 with a possible state transition (Eq. 4) to all non-placebo groups (n= 2 × 4 = 8 fits).

We used non-informative priors for all parameters in the original model 1 without a state transition (Eq. 3). For all groups, we used the same uniformly distributed prior for D (positive i.e. decrease in diversity) and uniform priors for ϕ1, ϕ2. For fitting model 2, we used an additional uniform prior centred at zero for the new equilibrium value A and the same priors for other parameters. In summary, the priors are as follows:

$$D\sim {\mathrm{uniform}}\left( {0,10} \right)$$
(8.1)
$$\phi _1\sim {\mathrm{uniform}}\left( { - 1.99,1,99} \right)$$
(8.2)
$$\phi _2\sim {\mathrm{uniform}}\left( { - 2,2} \right)$$
(8.3)
$$A\sim {\mathrm{uniform}}\left( { - 2,2} \right)$$
(8.4)

We compared models 1 and 2 (Supplementary Files 1 and 2). for each antibiotic treatment group using the Bayes factor [50, 51] after extracting the model fits using bridge sampling with the bridgesampling R package v0.2-2 [52]. A prior sensitivity analysis (not shown) showed that choice of priors did not affect our conclusions about model selection, although the strength of the Bayes factor varied.

Full code and data for fitting the models and reproducing figures is available with this article (Supplementary Files 15).

### Shotgun metagenomics dataset

For fitting to the dataset released by Palleja et al. [27], we used the published species richness data with an arbitrary scaling factor (see Supplementary Text 1 for details, Supplementary File 6 for code, Supplementary File 7 for downloaded data).

### Lotka–Volterra simulations

We numerically simulated 59 = 1953125 parameter sets of the GLV model with n = 3 species and investigated their behaviour and stable states. For more details see the corresponding supplementary discussion (Supplementary Text 2) and Mathematica notebook (Supplementary File 8).