1 Introduction

Birth-death processes have been used extensively in many applications including evolutionary biology, ecology, population genetics, epidemiology, and queuing theory (see e.g. Novozhilov et al. 2006; Crawford and Suchard 2012; Doss et al. 2013; Rabier et al. 2014; Crawford et al. 2015). However, establishing analytic and computationally practical formulae for their transition probabilities is usually difficult (Novozhilov et al. 2006). The state-of-the-art method for computing the transition probabilities of birth-death processes proposed in Crawford and Suchard (2012) enables statistical estimation for general birth-death processes using likelihood-based inference (Crawford et al. 2014). Unfortunately, birth-death processes inherently only track one population, and extending this technique beyond the univariate case is nontrivial. Many applied models require the consideration of two or more interacting populations simultaneously to model behavior such as competition, predation, or infection. Examples of such bivariate models include epidemic models (McKendrick 1926; Kermack and McKendrick 1927; Griffiths 1972), predator-prey models (Hitchcock 1986; Owen et al. 2015), genetic models (Rosenberg et al. 2003; Xu et al. 2015), and within-host macro-parasite models (Drovandi and Pettitt 2011).

The most general extensions of birth-death processes to bivariate processes are competition processes (Reuter 1961). These processes allow not only “birth” and “death” events in each population, but also “transition” events where an individual moves from one population to the other. Unlike birth-death processes, few attempts have been made to compute the transition probabilities of competition processes or their special cases. Hence, researchers usually rely on classical continuous-time Markov chain methods such as matrix exponentiation and diffusion approximation. Unfortunately, these methods fail to leverage the specific structure of competition processes, and have several intrinsic limitations. Matrix exponentiation methods compute the transition probability matrix \({\mathbf {P}}(t)\) by solving the matrix form of Kolmogorov’s forward equation \({\mathbf {P}}'(t) = {\mathbf {P}}(t) {\mathbf Q}\) with initial condition \({\mathbf {P}}(0) = {\mathbf {I}}\), where \({\mathbf {Q}}\) is the instantaneous rate matrix of the process. While this equation admits a unique solution \({\mathbf {P}}(t) = \exp ({\mathbf {Q}}t)\) (Ephraim and Mark 2012), numerical evaluation of the matrix exponential is often troublesome (Moler and Loan 2003). Its computational cost via eigenvalue decomposition, for instance, is cubic in the size of the state-space and thus becomes computationally prohibitive even with moderately sized state-spaces (Drovandi and Pettitt 2011; Crawford and Suchard 2012). For example, Keeling and Ross (2008) demonstrate that computing transition probabilities via matrix exponentiation for the simplest epidemic models is practical only when modeling spread of an infectious disease through a very small population (e.g., 100 people). Moreover, matrix exponentiation can introduce serious rounding errors for certain rate matrices even for biologically reasonable values (Schranz et al. 2008; Crawford and Suchard 2012; Crawford et al. 2014). Diffusion approximations, on the other hand, require the state-space to be large in order to justify approximating a discrete process by a continuous-valued diffusion process (Karev et al. 2005; Golightly and Wilkinson 2005), and can often remain inaccurate for simulation even in settings with large state-spaces (Golightly and Wilkinson 2005). Branching processes form another closely related class of processes, and have been used in a likelihood-based framework to study bivariate populations (Xu et al. 2015). Branching processes are at once more general than competition processes, permitting events that increment populations by more than one, and also more restrictive in that linearity is implied by an assumption that particles act independently. The latter assumption is limiting in epidemiological applications, for instance, which commonly feature non-linear interactions between populations.

The lack of a reliable method for computing transition probabilities in bivariate processes forces researchers to apply alternative likelihood-free approaches such as approximate Bayesian computation (ABC) (Blum and Tran 2010; Drovandi and Pettitt 2011; Owen et al. 2015). The ABC approach uses simulated and observed summary statistics to bypass likelihood evaluation. Nonetheless, this is not a panacea approach that can completely replace traditional likelihood-based methods. The ABC method itself has several sources for loss of information such as non-zero tolerance, and non-sufficient summary statistics (Sunnåker et al. 2013). The tolerance is an ad hoc threshold to decide whether ABC accepts a new proposal. If the tolerance is zero and the summary statistics are sufficient, ABC is guaranteed to return the correct posterior distribution. In practice, however, tolerance is always positive which often leads to bias. In the context of counting processes, sufficient summary statistics usually do not exist because the data are observed partially. Thus, credible interval estimates under ABC are potentially inflated due to the loss of information (Csilléry et al. 2010). Also, when sufficient summary statistics are not available, the ABC method can not be trusted in selecting between models (Robert et al. 2011). Because of all these limitations, direct likelihood-based methods are often more favorable.

In this paper, we develop an efficient method to compute the transition probabilities of a subclass of competition processes with two interacting populations of particles, enabling likelihood-based inference. We call this subclass birth(death)/birth-death processes, whose first population is increasing (decreasing). It is worth mentioning that we do not impose linearity condition for the rates of these processes. A rigorous characterization of this class of processes and derivation of recursive formulae to compute their transition probabilities are provided in Sect. 2. Our main tools are the Laplace transform and continued fractions that have been successfully applied for univariate birth-death processes in Crawford and Suchard (2012). These formulae enable accurate and computationally efficient numerical computation of transition probabilities. We implement this method in the new R package MultiBD https://github.com/msuchard/MultiBD. In Sect. 3, we discuss multiple scientifically relevant applications of birth(death)/birth-death processes including stochastic susceptible-infectious-removed (SIR) models in epidemiology (McKendrick 1926; Kermack and McKendrick 1927; Raggett 1982), monomolecular reaction systems (Jahnke and Huisinga 2007), a birth-death-shift model for transposable elements (Rosenberg et al. 2003; Xu et al. 2015), and a within-host macro-parasite model (Riley et al. 2003; Drovandi and Pettitt 2011). We examine the accuracy of our method in simulation studies, including comparisons to branching process, matrix exponentiation method, and Monte Carlo approximations. Finally, we apply our method to estimate infection rates and death rates during the plague of Eyam in 1666 within a likelihood-based Bayesian framework in Sect. 4.

Previous work on computing the transition probabilities: Analytic expressions of the transition probabilities have only been found for some special cases such as linear birth-death processes (see e.g. Novozhilov et al. 2006) and monomolecular reaction systems (Jahnke and Huisinga 2007). Therefore, matrix exponentiation is still the most common method for computing the transition probabilities of general Markov processes. The state-of-the-art software package for exponentiating sparse matrices is Expokit (Sidje 1998; Moler and Loan 2003), which uses Krylov subspace projection method. Eshof and Hochbruck (2006) propose a modified version using a simple preconditioned transformation to improve the convergence behavior of this method. Although matrix exponentiation has the advantage of generality in that it can be applied to any Markov process, it is not the most efficient method in many scenarios. Recently, Crawford and Suchard (2012) propose an efficient method for evaluating the transition probabilities of general birth-death processes using Laplace transform and continued fraction. However, efficient methods that extend this result to general bivariate birth-death processes have yet to be found.

2 Birth(death)/birth-death processes

2.1 Birth/birth-death processes

A birth/birth-death process is a bivariate continuous-time Markov process \(\mathbf{X}(t) = (X_1(t), X_2(t))\), \(t \ge 0\), whose state-space is in \({\mathbb {N}} \times {\mathbb {N}}\), the Cartesian product of the non-negative integers. We can describe a birth/birth-death process as governing dynamics of a system consisting two types of particles, where one out of four possible events can happen in infinitesimal time: (1) a new type 1 particle enters the system; (2) a new type 2 particle enters the system; (3) a type 2 particle leaves the system; or (4) a type 2 particle becomes a type 1 particle. In this system, \(X_1(t)\) and \(X_2(t)\) track the number of type 1 and type 2 particles at time t respectively. Mathematically, there are five possibilities for \(\mathbf{X}(t)\) during a small time interval \((t,t+dt)\):

$$\begin{aligned}&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a+1 &{} X_1(t)= a \\ X_2(t+dt) = b &{} X_2(t) = b \end{array} \right\} = \lambda ^{(1)}_{ab} dt + o(dt) \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a &{} X_1(t)= a \\ X_2(t+dt) = b+1 &{} X_2(t) = b \end{array} \right\} = \lambda ^{(2)}_{ab} dt + o(dt) \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a &{} X_1(t)= a \\ X_2(t+dt) = b-1 &{} X_2(t) = b \end{array} \right\} = \mu ^{(2)}_{ab} dt + o(dt) \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a+1 &{} X_1(t)= a \\ X_2(t+dt) = b-1 &{} X_2(t) = b \end{array} \right\} = \gamma _{ab}dt + o(dt) \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a~~~~~ &{} X_1(t) = a \\ X_2(t+dt) = b &{} X_2(t) = b \end{array} \right\} = 1 - (\lambda ^{(1)}_{ab} +\lambda ^{(2)}_{ab} + \mu ^{(2)}_{ab} + \gamma _{ab})dt + o(dt), \end{aligned}$$
(1)

where \(a,b \in {\mathbb {N}}\), \(\lambda ^{(1)}_{ab} \ge 0\) is the birth rate of type 1 particles given a type 1 particles and b type 2 particles, \(\lambda ^{(2)}_{ab} \ge 0\) is the equivalent birth rate of type 2 particles, \(\mu ^{(2)}_{ab} \ge 0\) is the death rate of type 2 particles, and \(\gamma _{ab}\) is the transition rate from type 2 particles to type 1 particles. We fix \(\lambda ^{(1)}_{-1,b} = \lambda ^{(2)}_{a,-1} = \mu ^{(2)}_{a0} = \gamma _{-1,b} = \gamma _{a0} = 0\).

Letting \(P^{a_0b_0}_{ab}(t) = \Pr \{\mathbf{X}(t)= (a,b)~ |~\mathbf{X}(0)=(a_0,b_0)\}\), the forward Kolmogorov’s equations for the birth/birth-death process are

$$\begin{aligned} \frac{dP^{a_0b_0}_{ab}(t)}{dt}&= \lambda ^{(1)}_{a-1,b} P^{a_0b_0}_{a-1,b}(t) + \lambda ^{(2)}_{a,b-1} P^{a_0b_0}_{a,b-1}(t) + \mu ^{(2)}_{a,b+1}P^{a_0b_0}_{a,b+1}(t) \nonumber \\&\quad \,+ \gamma _{a-1,b+1}P^{a_0b_0}_{a-1,b+1}(t) - (\lambda ^{(1)}_{ab} + \lambda ^{(2)}_{ab} + \mu ^{(2)}_{ab} + \gamma _{ab})P^{a_0b_0}_{ab}(t), \end{aligned}$$
(2)

for all (ab). In practice, we can usually only observe the process discretely. In this scenario, the likelihood function is the product of transition probabilities between consecutive observations. Therefore, computing \(P^{a_0b_0}_{ab}(t)\) is an important step for any direct likelihood-based analysis.

In general, a birth/birth-death process is a special case of a competition process (Reuter 1961) with rate matrix \(\mathbf{Q} = \{ q_{ij} \}\) where \(i,j \in {\mathbb {N}} \times {\mathbb {N}}\) and

j

Competition process

Birth/birth-death

\((a+1,b)\)

\(q_{(a,b)(a+1,b)~~}\)

\(\lambda ^{(1)}_{ab}\)

\((a-1,b)\)

\(q_{(a,b)(a-1,b)}~~\)

0

\((a,b+1)\)

\(q_{(a,b)(a,b+1)}~~\)

\(\lambda ^{(2)}_{ab}\)

\((a,b-1)\)

\(q_{(a,b)(a,b-1)}~~\)

\(\mu ^{(2)}_{ab}\)

\((a+1,b-1)\)

\(q_{(a,b)(a+1,b-1)}\)

\(\gamma _{ab}\)

\((a-1,b+1)\)

\(q_{(a,b)(a-1,b+1)}\)

0

(ab)

\(\displaystyle - \sum _{k, l \in \{-1, 0, 1\}}^{k \ne l}{q_{(a,b)(a+k,b+l)}}\)

\(- (\lambda ^{(1)}_{ab} + \lambda ^{(2)}_{ab} + \mu ^{(2)}_{ab} + \gamma _{ab})\)

other

0

0

for \(i = (a,b)\). Competition processes are the most general bivariate Markov processes that only allow transitions between neighboring states. Many practical models in biology are special cases of these processes such as epidemic models (McKendrick 1926; Kermack and McKendrick 1927; Griffiths 1972) and predator-prey models (Hitchcock 1986; Owen et al. 2015).

2.1.1 Sufficient condition for regularity

Definition 1

A birth/birth-death process is regular if there is a unique set of transition probabilities \(P^{a_0b_0}_{ab}(t)\) satisfying the system of Eq. (2).

Here, we establish the sufficient condition for regularity of a birth/birth-death process. For \(k \in \mathbb N\), we denote:

$$\begin{aligned}&D_k = \{ (a,b): a + b = k \} \in {\mathbb {N}} \times {\mathbb {N}},~\text {and} \nonumber \\&\lambda _k = \max _{(a,b) \in D_k} \{ \lambda ^{(1)}_{ab} + \lambda ^{(2)}_{ab} \}. \end{aligned}$$
(3)

Theorem 1

The sufficient condition for regularity of a general birth/birth-death process is \( \sum _{k=1}^\infty {1/\lambda _k} = \infty \).

Proof

We will apply the following Reuter’s condition (Reuter 1957):

Lemma 1

Let \(\mathbf{Q} = \{q_{ij}\}\) be a conservative matrix, such that \( - q_{ii} = \sum _{j \ne i}{q_{ij}} < \infty \). A continuous-time Markov chain associated with \(\mathbf{Q}\) is regular if and only if for some \(\zeta > 0\), the equation \( \mathbf{Q}{} \mathbf{y} = \zeta \mathbf{y}\) subject to \(0 \le y_i \le 1\) has only trivial solution \(\mathbf{y} = \mathbf{0}\).

For a general birth/birth-death process, states i and j are in \({\mathbb {N}} \times {\mathbb {N}}\). Let \(\{y_{ab}\}_{a,b \in {\mathbb {N}}}\) be a solution of \(\mathbf{Q}{} \mathbf{y} = \zeta \mathbf{y}\) such that \(y_{ab} \in [0,1]\) for any a and b. Then, we have

$$\begin{aligned} (\zeta + \lambda ^{(1)}_{ab} + \lambda ^{(2)}_{ab} + \mu ^{(2)}_{ab} + \gamma _{ab}) y_{ab} = \lambda ^{(1)}_{ab} y_{a+1,b} + \lambda ^{(2)}_{ab} y_{a,b+1} + \mu ^{(2)}_{ab}y_{a,b-1} + \gamma _{ab}y_{a+1,b-1} . \end{aligned}$$
(4)

Defining \(y_k = \max _{(a,b) \in D_k} \{ y_{ab} \}\) and \((a_k,b_k) = {\text {argmax}}_{(a,b) \in D_k} \{ y_{ab} \}\), we deduce that

$$\begin{aligned} (\zeta + \lambda ^{(1)}_{a_kb_k} + \lambda ^{(2)}_{a_kb_k} + \mu ^{(2)}_{a_kb_k}) y_k&\le (\lambda ^{(1)}_{a_kb_k} + \lambda ^ {(2)}_{a_kb_k}) y_{k+1} + \mu ^{(2)}_{a_kb_k}y_{k-1}, ~\text{ and } \nonumber \\ \zeta y_k + \mu ^{(2)}_{a_kb_k}(y_k - y_{k-1})&\le (\lambda ^{(1)}_{a_kb_k} + \lambda ^{(2)}_{a_kb_k}) (y_{k+1} - y_k). \end{aligned}$$
(5)

Since \(\mu ^{(2)}_{a_{-1}b_{-1}} = 0\), \(y_k\) is an increasing sequence. Thus,

$$\begin{aligned} \frac{\zeta }{\lambda _k} y_k \le y_{k+1} - y_k. \end{aligned}$$
(6)

Assuming that there exists \(k_0\) such that \(y_{k_0} > 0\), we obtain

$$\begin{aligned} y_k \ge y_{k_0} + \zeta \sum _{i=k_0}^{k-1}{\frac{y_i}{\lambda _i}} \ge y_{k_0}\left( 1 + \zeta \sum _{i=k_0}^{k-1}{\frac{1}{\lambda _i}}\right) , \end{aligned}$$
(7)

that is larger than 1 if k is big enough. Hence \(y_k = 0\) for every k. Then, the theorem is proved by applying Lemma 1.

Note that the condition in Theorem 1 generalizes the classical regularity condition of a pure birth process (Feller 1968). From now on, we assume that our birth/birth-death processes are regular.

2.1.2 Recursive formula for transition probabilities

In this section, we establish a recursion to calculate the transition probabilities \(P^{a_0b_0}_{ab}(t)\) of a birth/birth-death process. Since we assume that our birth/birth-death process is regular, these transition probabilities are unique.

We first note that \(P^{a_0b_0}_{ab}(t) = 0\) for all \(a<a_0\). Let \(f_{ab}(s),~s \in \mathbb {C}\), be the Laplace transform of \(P^{a_0b_0}_{ab}(t)\), that is

$$\begin{aligned} f_{ab}(s) = {\mathcal {L}}[P^{a_0b_0}_{ab}(t)](s) = \int _0^\infty {e^{-st}P^{a_0b_0}_{ab}(t)dt}. \end{aligned}$$
(8)

From (2), we have

$$\begin{aligned} s f_{ab}(s) - P^{a_0b_0}_{ab}(0)&= \lambda ^{(1)}_{a-1,b} f_{a-1,b}(s) + \lambda ^{(2)}_{a,b-1} f_{a,b-1}(s) + \mu ^{(2)}_{a,b+1} f_{a,b+1}(s) \nonumber \\&\qquad + \gamma _{a-1,b+1} f_{a-1,b+1}(s) - (\lambda ^{(1)}_{ab} + \lambda ^{(2)}_{ab} + \mu ^{(2)}_{ab} + \gamma _{ab})\nonumber \\&\qquad f_{ab}(s),~(a,b) \in {\mathbb {N}}^2. \end{aligned}$$
(9)

Note that \(f_{ab}(s)\) is the unique solution of (9) by the uniqueness of \(P^{a_0b_0}_{ab}(t)\). We construct the recursive approximation formulae for \(f_{ab}(s)\) using continued fractions. “Appendix A” provides necessary background on continued fractions and their convergents. Denote

$$\begin{aligned}&x_{a1} = - \frac{1}{\mu ^{(2)}_{a1}};~x_{ab} = - \frac{\lambda ^{(2)}_{a,b-2}}{\mu ^{(2)}_{ab}},~b \ge 2 \nonumber \\&y_{ab} = - \frac{s + \lambda ^{(1)}_{a,b-1} + \lambda ^{(2)}_{a,b-1} + \mu ^{(2)}_{a,b-1} + \gamma _{a,b-1}}{\mu ^{(2)}_{ab}},~b \ge 1, \end{aligned}$$
(10)

and consider the following continued fraction

$$\begin{aligned} \phi ^{(0)}_{a0}(s) = \frac{x_{a1}}{ y_{a1} + \frac{x_{a2}}{ y_{a2} + \frac{x_{a3}}{ y_{a3} + \cdots }~.}} \end{aligned}$$
(11)

We can construct the sequence \(\{ \phi ^{(0)}_{ab}(s) \}_{b=0}^\infty \) (Definition A.3, “Appendix A”) as follows:

$$\begin{aligned}&(s + \lambda ^{(1)}_{a0} + \lambda ^{(2)}_{a0})\phi ^{(0)}_{a0}(s) - \mu ^{(2)}_{a1}\phi ^{(0)}_{a1}(s) = 1,~\text{ and } \nonumber \\&(s + \lambda ^{(1)}_{a,b-1} + \lambda ^{(2)}_{a,b-1} + \mu ^{(2)}_{a,b-1} + \gamma _{a,b-1} )\phi ^{(0)}_{a,b-1}(s)\nonumber \\&\qquad - \lambda ^{(2)}_{a,b-2}\phi ^{(0)}_{a,b-2}(s) - \mu ^{(2)}_{ab}\phi _{ab}(s) = 0,~b \ge 2. \end{aligned}$$
(12)

Comparing the sequences in (12) with (9), we deduce that \( {\mathcal {L}}^{-1}\left[ \phi ^{(0)}_{ab}(s)\right] = P^{a_00}_{ab}(t)\). Since \(P^{a_00}_{ab}(t)\) is a probability distribution, we have \(\sum _{(a,b) \in {\mathbb {N}} \times {\mathbb {N}}}{P^{a_00}_{ab}(t)} = 1\). Taking the Laplace transform of the previous equation, we get \( \sum _{(a,b) \in {\mathbb {N}} \times {\mathbb {N}}}{\phi ^{(0)}_{ab}(s)} = 1/s\). Hence, \(\lim _{b \rightarrow \infty } \phi ^{(0)}_{a_0b}(s) = 0\) for every \(s > 0\). By Lemma A.4 (“Appendix A”), \(\phi ^{(0)}_{a0}(s)\) converges for every \(s > 0\), and

$$\begin{aligned} \phi ^{(0)}_{ab}(s) = \prod _{i=1}^{b}{x_{ai}} \frac{x_{a,b+1}}{ Y_{a,b+1} + \frac{x_{a,b+2} Y_{ab}}{ y_{a,b+2} + \frac{x_{a,b+3}}{ y_{a,b+3} + \frac{x_{a,b+4}}{ y_{a,b+4} + \cdots }~,}}} \end{aligned}$$
(13)

where \(Y_{ab}\) is the denominator of the bth convergent of \(\phi ^{(0)}_{a0}(s)\).

From (9), we note that

$$\begin{aligned}&(s + \lambda ^{(1)}_{a_0b} + \lambda ^{(2)}_{a_0b} + \mu ^{(2)}_{a_0b} +\gamma _{a_0b})f_{a_0b} - \lambda ^{(2)}_{a_0,b-1}f_{a_0,b-1}(s)\nonumber \\&\quad -\mu ^{(2)}_{a_0,b+1}f_{a_0,b+1}(s) = 1_{\{b = b_0\}},~b \in {\mathbb {N}}. \end{aligned}$$
(14)

By Lemma A2 (“Appendix A”), \(f_{a_0b}(s) = \phi ^{(b_0)}_{a_0b}(s)\) where

$$\begin{aligned} \phi ^{(m)}_{ab}(s) = {\left\{ \begin{array}{ll} \frac{(-1)^{m-b+1} Y_{ab}}{\mu ^{(2)}_{a,m+1} \prod _{i=1}^{m+1}{x_{ai}}} \phi ^{(0)}_{am}(s), &{} \text{ if } b \le m \\ \frac{- Y_{am}}{\mu ^{(2)}_{a,m+1} \prod _{i=1}^{m+1}{x_{ai}}}\phi ^{(0)}_{ab}(s), &{} \text{ if } b \ge m. \end{array}\right. } \end{aligned}$$
(15)

Next, we obtain formulae for approximating \(f_{ab}(s)\) recursively assuming that we already have evaluated \(f_{a-1,b}(s)\). Again, from (2), we have

$$\begin{aligned}&(s + \lambda ^{(1)}_{ab} + \lambda ^{(2)}_{ab} + \mu ^{(2)}_{ab} + \gamma _{ab})f_{ab}(s) - \lambda ^{(2)}_{a,b-1}f_{a,b-1}(s) - \mu ^{(2)}_{a,b+1}f_{a,b+1}(s)\nonumber \\&\qquad = \lambda ^{(1)}_{a-1,b}f_{a-1,b}(s) + \gamma _{a-1,b+1}f_{a-1,b+1}(s), \end{aligned}$$
(16)

for \(b \in {\mathbb {N}}\). We approximate \(f_{ab}(s)\) by solving a truncated version of (16) for \(0 \le b \le B\), where B is sufficiently large. The intuition of how to choose B follows from the observation that we want \(\sum _{a=a_0}^\infty \sum _{b=B+1}^\infty {P^{a_0b_0}_{ab}(t)}\) to be small. By Lemma A2 (“Appendix A”), we have the following approximation:

$$\begin{aligned} f_{ab}(s) \approx \sum _{m=0}^B{\left[ \lambda ^{(1)}_{a-1,m}f_{a-1,m}(s) + \gamma _{a-1,m+1}f_{a-1,m+1}(s)\right] \phi ^{(m)}_{ab}(s)}. \end{aligned}$$
(17)

Therefore, the transition probabilities of a birth/birth-death process can be computed recursively using the following Theorem:

Theorem 2

Let \(\phi ^{(m)}_{ab}(s)\) be defined as in (11), (13), and (15). We have

$$\begin{aligned} P^{a_0b_0}_{ab}(t) = {\left\{ \begin{array}{ll} 0, &{} \text{ if } a < a_0 \\ {\mathcal {L}}^{-1}\left[ f_{ab}(s)\right] (t), &{} \text{ if } a \ge a_0, \end{array}\right. } \end{aligned}$$
(18)

where \(f_{a_0b}(s) = \phi ^{(b_0)}_{a_0b}(s)\) and

$$\begin{aligned} f_{ab}(s) \approx \sum _{m=0}^B{\left[ \lambda ^{(1)}_{a-1,m}f_{a-1,m}(s) + \gamma _{a-1,m+1}f_{a-1,m+1}(s)\right] \phi ^{(m)}_{ab}(s)},~a>a_0. \end{aligned}$$
(19)

Here, \({\mathcal {L}}^{-1}(.)\) denotes the inverse Laplace transform and B is the truncation level.

If the number of type 2 particles is bounded by \(B^*\), we choose \(B=B^*\). In this case, the approximation in Theorem 2 is exact. We prove that the output of our approximation scheme (19) converges to \(f_{ab}(s)\) as B goes to infinity in “Appendix C”. Further, the transition probability returned by Theorem 2 converges to the true transition probability. This truncation error can be bounded explicitly by extending the coupling argument in Crawford et al. (2016) to multivariate processes. However, we leave it as a subject of future work because a complete treatment is beyond the scope of this paper.

2.1.3 Numerical approximation of the transitions probabilities

To approximate \(P^{a_0b_0}_{ab}(t)\) using Theorem 2, we need to compute two quantities: the continued fractions \(\phi ^{(m)}_{ab}(s)\), and the inverse Laplace transform \({\mathcal {L}}^{-1}\left[ f_{ab}(s)\right] (t)\). We efficiently evaluate the continued fractions \(\phi ^{(m)}_{ab}(s)\) through the modified Lentz method (Lentz 1976; Thompson and Barnett 1986); see “Appendix B” for more details. This algorithm enables us to control for and limit truncation error. To approximate the inverse Laplace transform \({\mathcal {L}}^{-1}\left[ f_{ab}(s)\right] (t)\), we apply the method proposed in Abate and Whitt (1992) using a Riemann sum:

$$\begin{aligned} {\mathcal {L}}^{-1}\left[ f_{ab}(s)\right] (t) \approx \frac{e^{H/2}}{2t} \mathcal{R} \left[ f_{ab} \left( \frac{H}{2t} \right) \right] + \frac{e^{H/2}}{t} \sum _{k=1}^\infty {(-1)^k \mathcal{R} \left[ f_{ab} \left( \frac{H + 2k \pi i}{2t} \right) \right] }. \end{aligned}$$
(20)

Here \(\mathcal{R} [z]\) is the real part of z and H is a positive real number. Abate and Whitt (1992) show that the error that arises in (20) is bounded by \(1/(e^H - 1)\). Moreover, we can use the Levin transform (Levin 1973) to improve the rate of convergence because the series in (20) is an alternating series when \( \mathcal{R} \{ f_{ab} [(H + 2k \pi i)/(2t)] \}\) have the same sign. These numerical methods have been successfully applied by Crawford and Suchard (2012) to compute the transition probabilities of birth-death processes.

In practice, to handle situations where \(\mu ^{(2)}_{ab}\) can possibly equal to 0 for some (ab), we re-parametrize \(x_{ab}\) and \(y_{ab}\) as follows:

$$\begin{aligned}&x_{a1} = 1;~x_{ab} = - \lambda ^{(2)}_{a,b-2} \mu ^{(2)}_{a,b-1},~b \ge 2,~\text{ and } \nonumber \\&y_{ab} = s + \lambda ^{(1)}_{a,b-1} + \lambda ^{(2)}_{a,b-1} + \mu ^{(2)}_{a,b-1} + \gamma _{a,b-1},~b \ge 1. \end{aligned}$$
(21)

With this new parametrization, we obtain

$$\begin{aligned} \phi ^{(m)}_{ab}(s) = {\left\{ \begin{array}{ll} \frac{(\prod _{i=b+1}^m{\mu ^{(2)}_{ai}}) Y_{ab}}{ Y_{a,m+1} + \frac{x_{a,m+2} Y_{am}}{ y_{a,m+2} + \frac{x_{a,m+3}}{ y_{a,m+3} + \frac{x_{a,m+4}}{ y_{a,m+4} + \cdots }}}}~, &{} \text{ if } b \le m \\ \frac{(\prod _{i=m+1}^b{\lambda ^{(2)}_{ai}}) Y_{am}}{ Y_{a,b+1} + \frac{x_{a,b+2} Y_{ab}}{ y_{a,b+2} + \frac{x_{a,b+3}}{ y_{a,b+3} + \frac{x_{a,b+4}}{ y_{a,b+4} + \cdots }}}}~, &{} \text{ if } b \ge m. \end{array}\right. } \end{aligned}$$
(22)

Our complete algorithm to compute the transition probabilities of birth/birth-death processes is implemented in the function bbd_prob in a new R package called MultiBD. The function takes t, \(a_0\), \(b_0\), \(\lambda ^{(1)}_{ab}\), \(\lambda ^{(2)}_{ab}\), \(\mu ^{(2)}_{ab}\), \(\gamma _{ab}\), A, B as inputs and returns the transition probability matrix \(\{ P^{a_0b_0}_{ab}(t) \}_{a_0 \le a \le A, 0 \le b \le B}\). Here, there is no requirement for A while B needs to be large enough such that \(\sum _{a=a_0}^A \sum _{b=B+1}^\infty {P^{a_0b_0}_{ab}(t)}\) is small. We can check to see if B is large enough by checking if \(\sum _{a=a_0}^A {P^{a_0b_0}_{aB}(t)}\) is sufficiently small.

In practice, the computational complexity of evaluating each term \((f_{ab}(s))_{a_0 \le a \le A, 0 \le b \le B}\) is \(\mathcal {O}((A-a_0)B^2)\) because the Lentz algorithm terminates quickly. Let K be the number of iterations required by the Levin acceleration method (Levin 1973) to achieve a certain error bound for the Riemann sum in (20). Then, the total complexity of our algorithm is \(\mathcal {O}((A-a_0)B^2K)\). However, evaluation of \(\{ f_{ab} [(H + 2k \pi i)/(2t)] \}_{k=1}^K\) can be efficiently parallelized across different values of k, and we exploit this parallelism via multicore processing, delegating most of the computational work to compiled C++ code.

2.2 Death/birth-death processes

Similar to the birth/birth-death process, a death/birth-death process is also a special case of competition processes. The only difference is that the number of type 1 particles is decreasing instead of increasing. Mathematically, possible transitions of a death/birth-death process \(\mathbf{X}(t) = (X_1(t),X_2(t))\) during \((t,t+dt)\) are:

$$\begin{aligned}&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a-1 &{} X_1(t)= a \\ X_2(t+dt) = b &{} X_2(t) = b \end{array} \right\} = \mu ^{(1)}_{ab} dt + o(dt) \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a &{} X_1(t)= a \\ X_2(t+dt) = b+1 &{} X_2(t) = b \end{array} \right\} = \lambda ^{(2)}_{ab} dt + o(dt) \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a &{} X_1(t)= a \\ X_2(t+dt) = b-1 &{} X_2(t) = b \end{array} \right\} = \mu ^{(2)}_{ab} dt + o(dt) \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a-1 &{} X_1(t)= a \\ X_2(t+dt) = b+1 &{} X_2(t) = b \end{array} \right\} = \gamma _{ab}dt + o(dt) \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_1(t+dt) = a~~~~~ &{} X_1(t)= a \\ X_2(t+dt) = b &{} X_2(t) = b \end{array} \right\} = 1 - (\mu ^{(1)}_{ab} +\lambda ^{(2)}_{ab} + \mu ^{(2)}_{ab} + \gamma _{ab})dt + o(dt),\end{aligned}$$
(23)

where \(\mu ^{(1)}_{ab} \ge 0\) is the death rate of type 1 particles given a type 1 particles and b type 2 particles, \(\lambda ^{(2)}_{ab} \ge 0\) is the birth rate of type 2 particles, \(\mu ^{(2)}_{ab} \ge 0\) is the death rate of type 2 particles, and \(\gamma _{ab}\) is the transition rate from type 1 particles to type 2 particles. Again, we fix \(\mu ^{(1)}_{0,b} = \lambda ^{(2)}_{a,-1} = \mu ^{(2)}_{0,b} = \gamma _{0,b} = \gamma _{a,-1} = 0\).

Following a similar argument as in Sect. 2.1.1, we obtain a sufficient condition for regularity of a death/birth-death process. Denote

$$\begin{aligned} \begin{aligned} D_k&= \{ (a,b): a + b = k, a \le a_0 \} \in {\mathbb {N}} \times {\mathbb {N}} \\ \lambda _k&= \max _{(a,b) \in D_k} \{ \lambda ^{(2)}_{ab} \} \\ \mu _k&= \min _{(a,b) \in D_k} \{ \mu ^{(1)}_{ab} + \mu ^{(2)}_{ab} \} \\ \sigma _0&=1,~ \sigma _k = \frac{\lambda _0 \ldots \lambda _{k-1}}{\mu _1 \ldots \mu _k} , \end{aligned} \end{aligned}$$
(24)

where \(a_0\) is the number of type 1 particles at time \(t = 0\). The following Theorem is a direct application of Theorem 1 in Iglehart (1964)

Theorem 3

A sufficient condition for regularity of a death/birth-death process is

$$\begin{aligned} \sum _{k=0}^\infty { \left( \frac{1}{\lambda _k \sigma _k} \sum _{i=0}^k{\sigma _i} \right) } = \infty . \end{aligned}$$
(25)

We note that if we do a transformation for a death/birth-death process \(\mathbf{X}(t) = (X_1(t),X_2(t))\) as follows:

$$\begin{aligned} \begin{aligned} Y_1(t)&= a_0 - X_1(t) \\ Y_2(t)&= B - X_2(t). \end{aligned} \end{aligned}$$
(26)

Then, \(\mathbf{Y}(t) = (Y_1(t),Y_2(t))\) can be considered as a birth/birth-death process. Therefore, the transition probabilities of a death/birth-death process can also be computed using the R function bbd_prob and the transformation (26). Again, we want to choose B such that \(\sum _{a=0}^{a_0} \sum _{b=B+1}^\infty {P^{a_0b_0}_{ab}(t)}\) is small. We implement this procedure in the function dbd_prob in our R package MultiBD. The function takes t, \(a_0\), \(b_0\), \(\mu ^{(1)}_{ab}\), \(\lambda ^{(2)}_{ab}\), \(\mu ^{(2)}_{ab}\), \(\gamma _{ab}\), A, B as inputs and returns the transition probability matrix \(\{P^{a_0b_0}_{ab}(t)\}_{A \le a \le a_0, 0 \le b \le B}\). As for birth/birth-death processes, there is no requirement for A.

3 Applications

Birth(death)/birth-death processes are appropriate for modeling two-type populations where the size of the first population is monotonically increasing (decreasing). Here we examine our methods in four applications: a within-host macro-parasite model, a birth-death-shift model for transposable elements, monomolecular reaction systems, and the stochastic SIR epidemiological model. We demonstrate that a birth (death)/birth-death process well captures the dynamics of these common biological problems, and inference using its transition probabilities often outperforms existing approximations. In particular, we emphasize that the birth (death)/birth-death process approach allows us to compute finite-time transition probabilities in the stochastic SIR model that were previously considered unknown or intractable without model simplification (Cauchemez and Ferguson 2008).

3.1 Monomolecular reaction systems

We illustrate the performance of our computational method by considering the following monomolecular reactions:

$$\begin{aligned} \begin{aligned}&\text {Reaction} ~~R_{ab}:~~A \xrightarrow {r_{ab}} B \\&\text {Reaction} ~~R_{ba}:~~B \xrightarrow {r_{ba}} A \\&\text {Outflow} ~~~O_{b}:~~B \xrightarrow {o_{b}} * \end{aligned} \end{aligned}$$
(27)

where \(r_{ab}, r_{ba}\) is the reaction rates, and \(o_{b}\) is the outflow rate. Denote

$$\begin{aligned} Q = \begin{pmatrix} - r_{ab} &{} r_{ba} \\ r_{ab} &{} -r_{ba} - o_{b} \end{pmatrix}, \quad p^{(a)} = e^{Q t} \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \quad p^{(b)} = e^{Q t} \begin{pmatrix} 0 \\ 1 \end{pmatrix}. \end{aligned}$$

By Theorem 1 in Jahnke and Huisinga (2007), the transition probabilities of the reaction system (27) at time \(t > 0\) is

$$\begin{aligned} P_{ab}^{a_0 b_0}(t) = \mathcal {M}(~.~, a_0, p^{(a)}) \star \mathcal {M}(~.~, b_0, p^{(b)}) \end{aligned}$$
(28)

where \(\mathcal {M}(x,N,p)\) is the multinomial distribution and \(\star \) denotes the convolution operator. As analytic expressions for transition probabilities exist for this class of reactions, this example serves as a baseline for comparison to assess the accuracy of our method.

To study these processes in our framework, let A(t) denote the total number of particle A at time t and L(t) be the total number of particle B leaving the system up to t. Then, \(\{L(t), A(t)\}\) is a birth/birth-death process with the following possible transitions during \((t, t + dt)\):

$$\begin{aligned}&\Pr \left\{ \begin{array}{l | l} L(t+dt)~ = i+1 &{} L(t)= i \\ A(t+dt) = j~ &{} A(t) = j \end{array} \right\} = o_b (a_0 + b_0 - i - j)^+ dt + o(dt), \\&\Pr \left\{ \begin{array}{l | l} L(t+dt)~ = i &{} L(t)= i \\ A(t+dt) = j+1~ &{} A(t) = j \end{array} \right\} = r_{ba} (a_0 + b_0 - i - j)^+ dt + o(dt), \\&\Pr \left\{ \begin{array}{l | l} L(t+dt)~ = i &{} L(t)= i \\ A(t+dt) = j-1~ &{} A(t) = j \end{array} \right\} = r_{ab}j dt + o(dt),~\text{ and } \\&\Pr \left\{ \begin{array}{l | l} L(t+dt)~ = i &{} L(t)= i \\ A(t+dt) = j~~~~~~ &{} A(t) = j \end{array} \right\} \\&\quad = 1 - [r_{ab}j + (o_b + r_{ba}) (a_0 + b_0 - i - j)^+ ]dt + o(dt). \end{aligned}$$

Here \(x^+ = \max (0,x)\). Therefore, \(P_{ab}^{a_0 b_0}(t)\) can be computed using our method implemented in the R function bbd_prob.

We use bbd_prob to calculate \(\{P^{20,0}_{ab}(1)\}_{0 \le a \le 20, 0 \le b \le 20}\) of the reaction system (27) with \(r_{ab} = 2, r_{ba} = 0.5\) and \(o_b = 1\). The \(L_1\) distance between our result and the analytic result (28) is less than \(4.7 \times 10^{-9}\), thus confirming the accuracy of our method compared to explicit analytic solutions.

3.2 Birth-death-shift model for transposable elements

Transposable elements or transposons are genomic sequences that can either duplicate, with a new copy moving to a new genomic location, move to a different genomic location, or be deleted from the genome. Rosenberg et al. (2003) model the number of copies of a particular transposon using a linear birth-death-shift process; a birth is a duplication event, a death is a deletion event, and shift is a switching position event. Xu et al. (2015) propose representing this birth-death-shift process by a linear multi-type branching process \(\mathbf{X}(t) = (X_{\text {\tiny old}}(t), X_{\text {\tiny new}}(t))\) tracking the number of occupied sites where \(X_{\text {\tiny old}}(t)\) is the number of initially occupied sites and \(X_{\text {\tiny new}}(t)\) is the number of newly occupied sites. Let \(\lambda \), \(\mu \), and \(\nu \) be the birth, death, and shift rates respectively. The transitions of \(\mathbf{X}(t)\) during a small time interval occur with probabilities

$$\begin{aligned}&\Pr \left\{ \begin{array}{l | l} X_{\text {\tiny old}}(t+dt) = x_{\text {\tiny old}} - 1~ &{} X_{\text {\tiny old}}(t)~ = x_{\text {\tiny old}} \\ X_{\text {\tiny new}}(t+dt) = x_{\text {\tiny new}} &{} X_{\text {\tiny new}}(t) = x_{\text {\tiny new}} \end{array} \right\} = (\mu x_{\text {\tiny old}}) dt + o(dt), \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_{\text {\tiny old}}(t+dt) = x_{\text {\tiny old}} &{} X_{\text {\tiny old}}(t)~ = x_{\text {\tiny old}} \\ X_{\text {\tiny new}}(t+dt) = x_{\text {\tiny new}} - 1 &{} X_{\text {\tiny new}}(t) = x_{\text {\tiny new}} \end{array} \right\} = (\mu x_{\text {\tiny new}})dt + o(dt), \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_{\text {\tiny old}}(t+dt) = x_{\text {\tiny old}} &{} X_{\text {\tiny old}}(t)~ = x_{\text {\tiny old}} \\ X_{\text {\tiny new}}(t+dt) = x_{\text {\tiny new}} + 1 &{} X_{\text {\tiny new}}(t) = x_{\text {\tiny new}} \end{array} \right\} = \lambda (x_{\text {\tiny old}} + x_{\text {\tiny new}}) dt + o(dt), \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_{\text {\tiny old}}(t+dt) = x_{\text {\tiny old}} - 1 &{} X_{\text {\tiny old}}(t)~ = x_{\text {\tiny old}} \\ X_{\text {\tiny new}}(t+dt) = x_{\text {\tiny new}} + 1 &{} X_{\text {\tiny new}}(t) = x_{\text {\tiny new}} \end{array} \right\} = (\nu x_{\text {\tiny old}}) dt + o(dt),~\text{ and } \nonumber \\&\Pr \left\{ \begin{array}{l | l} X_{\text {\tiny old}}(t+dt) = x_{\text {\tiny old}}~~~~~~~ &{} X_{\text {\tiny old}}(t)~ = x_{\text {\tiny old}} \\ X_{\text {\tiny new}}(t+dt) = x_{\text {\tiny new}} &{} X_{\text {\tiny new}}(t) = x_{\text {\tiny new}} \end{array} \right\} \nonumber \\&= 1 - (\mu + \lambda + \nu ) x_{\text {\tiny old}} - (\mu + \lambda ) x_{\text {\tiny new}} dt + o(dt). \end{aligned}$$
(29)

Equivalent to the branching process representation, notice that in this case \(\mathbf{X}(t)\) is also a death/birth-death process. Hence, we can effectively compute its transition probabilities. In contrast, Xu et al. (2015) consider the probability generating function

$$\begin{aligned} \Phi _{a_0b_0}(t, s_1, s_2)= & {} {\mathbb E} \left( s_1^{X_{\text {\tiny old}}(t)} s_2^{X_{\text {\tiny new}}(t)} | X_{\text {\tiny old}}(0) = a_0, X_{\text {\tiny new}}(0) = b_0 \right) \nonumber \\= & {} \sum _{a = 0}^\infty \sum _{b=0}^\infty {P^{a_0b_0}_{ab}(t) s_1^a s_2^b}, \end{aligned}$$
(30)

where

$$\begin{aligned} P^{a_0b_0}_{ab}(t) = \Pr \left\{ \begin{array}{l | l} X_{\text {\tiny old}}(t)~ = a ~~ &{} X_{\text {\tiny old}}(0)~ = a_0 \\ X_{\text {\tiny new}}(t) = b &{} X_{\text {\tiny new}}(0) = b_0 \end{array} \right\} . \end{aligned}$$
(31)

Because of the model-specific linearity in terms of a and b of the birth and death rates, one can evaluate \(\Phi _{jk}(t, s_1, s_2)\) by solving an ordinary differential equation. Further transforming \(s_1 = e^{2 \pi i w_1}\), \(s_2 = e^{2 \pi i w_2}\), the generating function becomes a Fourier series

$$\begin{aligned} \Phi _{a_0b_0}(t, e^{2 \pi i w_1}, e^{2 \pi i w_2}) = \sum _{a = 0}^\infty \sum _{b=0}^\infty {P^{a_0b_0}_{ab}(t)e^{2 \pi i a w_1}e^{2 \pi i b w_2}}. \end{aligned}$$
(32)

Therefore, Xu et al. (2015) retrieve the transition probabilities through approximating the integral as a Riemann sum

$$\begin{aligned} P^{a_0b_0}_{ab}(t)&= \int _0^1 \int _0^1 {\Phi _{a_0b_0}(t, e^{2 \pi i w_1} , e^{2 \pi i w_2})e^{-2 \pi i a w_1} e^{-2 \pi i b w_2} dw_1 dw_2} \nonumber \\&\approx \frac{1}{H^2} \sum _{u=0}^{H-1} \sum _{v=0}^{H-1} {\Phi _{jk}(t, e^{2 \pi i u/H}, e^{2 \pi i v/H})e^{-2 \pi i a u/H} e^{-2 \pi i b v/H}} , \end{aligned}$$
(33)

and show that choosing H as the smallest power of 2 greater than \(\max (a,b)\) produces accurate estimates of the true transition probabilities of the model. The authors implement this method in the R package bdsem. Using their method, evaluating \(\{P^{a_0b_0}_{ab}(t)\}_{0 \le a,b \le H}\) requires numerically solving \(H^2\) linear ordinary differential equations (ODEs). We perform a simulation to compare the performance between bdsem and our function dbd_prob. Because Xu et al. (2015) already provide a thorough empirical validation that bdsem produces accurate transition probabilities compared to Monte Carlo estimates from the true model, we consider a comparison to their method and omit a complete reproduction of their simulation study. Using both routines to compute the transition probabilities of a birth-death-shift process with rates \(\lambda = 0.0188\), \(\mu = 0.0147\), \(\nu = 0.00268\) (estimated from the IS6110 data by Rosenberg et al. (2003)) repeatedly over one hundred trials leads to a negligible difference in estimated probabilities. Specifically, we computed \(\{P^{10,0}_{ab}(t)\}_{0 \le a \le 10, 0 \le b \le 50}\) at three different observation period lengths \(t = 1, 5, 10\), and found that the \(L_1\) distance between probabilities estimated by each method is less than \(4 \times 10^{-8}\) across all cases. Here, the \(L_1\) distance between two matrices \(\mathbf{U} = (u_{ij})\) and \(\mathbf{V} = (v_{ij})\) are defined as \(\Vert \mathbf{U} - \mathbf{V} \Vert = \sum _{i,j}{|u_{ij} - v_{ij}|}\).

Having validated the accuracy of our approach, we turn to a runtime comparison. The ratios of CPU time required using bdsem compared to dbd_prob are summarized in Fig. 1, and note that this result is obtained using a single-thread option for dbd_prob. We see that dbd_prob is about 15 to 30 times faster than the bdsem implementation, while producing very similar results.

While there is a large performance difference in wall clock time, we cannot immediately conclude that our method is faster then the method in Xu et al. (2015) because computation time may depend heavily on implementation. Nonetheless, we can make some remarks about the performance of both methods that are platform-independent. Notably, the bdsem implementation grows slower as t increases while dbd_prob does not. This is expected because solving ODEs is slower when the domain increases. However, it is worth mentioning that we can use the solution paths to get the solutions of these ODEs at other time points in the domain. For example, when we solve the ODEs at \(t = 10\), we also get the solutions at \(t = 1\) and 5 for free. This point becomes important in applications where we need to compute the transition probabilities at several time points. Another downside of bdsem is that it computes \(\{P^{10,0}_{ab}(t)\}_{0 \le a,b \le 50}\) instead of evaluating \(\{P^{10,0}_{ab}(t)\}_{0 \le a \le 10, 0 \le b \le 50}\) directly as is done by dbd_prob.

Fig. 1
figure 1

CPU compute time ratios of bdsem to dbd_prob over 100 replications

Fig. 2
figure 2

The dynamic of \(\{L(t), M(t)\}\) under the deterministic model (35) with \(\mu _L = 0.0682, \mu _M = 0.0015, \eta = 0.0009, \gamma = 0.04\) and \(\{L(0), M(0)\} = \{100, 0\}\)

3.3 Within-host macro-parasite model

Riley et al. (2003) posit a stochastic model to describe a within-host macro-parasite population where Brugia pahangi is the parasite and Felis catus is the host. Brugia pahangi is closely related to Brugia malayi which infects millions of people in South and Southeast Asia. The model tracks the number of B. pahangi larvae L(t), the number of mature parasites M(t), and hosts experience of infection I(t) at time t. The dynamics of \(\{ L(t), M(t), I(t) \}\) follow a system of differential equations:

$$\begin{aligned} \frac{dL}{dt}(t)&= - \mu _L L(t) - \beta I(t) L(t) - \gamma L(t), \nonumber \\ \frac{dM}{dt}(t)&= \gamma L(t) - \mu _M M(t),~\text{ and } \nonumber \\ \frac{dI}{dt}(t)&= \nu L(t) - \mu _I I(t) \end{aligned}$$
(34)

where \(\mu _L\) is the natural death rate and \(\gamma \) is the maturation rate of larvae; \(\beta \) is the death rate of larvae due to the immune response from the host; \(\mu _M\) is the death rate of mature parasites; \(\nu \) is the acquisition rate and \(\mu _I\) is the loss rate of immunity.

Drovandi and Pettitt (2011) propose a simplification of this model by applying a pseudoequilibrium assumption for immunity, such that the immunity is constant over time. Under this pseudoequilibrium assumption, the dynamics of \(\{L(t), M(t)\}\) becomes

$$\begin{aligned} \frac{dL}{dt}(t)&= - \mu _L L(t) - \eta [L(t)]^2 - \gamma L(t),~\text{ and } \nonumber \\ \frac{dM}{dt}(t)&= \gamma L(t) - \mu _M M(t) \end{aligned}$$
(35)

where \(\eta = \beta \nu /\mu _I\). We illustrate the dynamic of (35) in Fig. 2. The corresponding stochastic formulation of this model is:

$$\begin{aligned}&\Pr \left\{ \begin{array}{l | l} L(t+dt)~ = i-1 &{} L(t)= i \\ M(t+dt) = j+1~ &{} M(t) = j \end{array} \right\} = (\gamma i) dt + o(dt), \nonumber \\&\Pr \left\{ \begin{array}{l | l} L(t+dt)~ = i-1 &{} L(t)= i \\ M(t+dt) = j~~~~~~ &{} M(t) = j \end{array} \right\} = (\mu _L i + \eta i^2) dt + o(dt), \nonumber \\&\Pr \left\{ \begin{array}{l | l} L(t+dt)~ = i &{} L(t)= i \\ M(t+dt) = j-1~ &{} M(t) = j \end{array} \right\} = (\mu _M j) dt + o(dt),~\text{ and } \nonumber \\&\Pr \left\{ \begin{array}{l | l} L(t+dt)~ = i &{} L(t)= i \\ M(t+dt) = j~~~~~~ &{} M(t) = j \end{array} \right\} = 1 - (\gamma i + \mu _L i + \eta i^2 + \mu _M j)dt + o(dt). \end{aligned}$$
(36)

Notably, \(\{L(t), M(t)\}\) follow a death/birth-death process.

For this model, \(\gamma \) and \(\mu _M\) has been estimated at 0.04 and 0.0015 previously (see Drovandi and Pettitt 2011 for more details). To estimate the remaining parameters, Drovandi and Pettitt (2011) examine the number of mature parasites at host autopsy time (at most 400 days) of those injected with approximately 100 juveniles, assume a priori \(\mu _L\) and \(\eta \) are uniform[0,1) and apply ABC to draw inference because the traditional matrix exponentiation method is computationally prohibitive here. The basic idea of ABC involves sampling from an approximate posterior distribution

$$\begin{aligned} f(\varvec{\theta }, Y | \rho (Y,Y_s) \le \epsilon ) \propto f(Y_s | \varvec{\theta }) \pi (\varvec{\theta }) 1_{ \rho (Y,Y_s) \le \epsilon }, \end{aligned}$$
(37)

where \(\varvec{\theta }\) is the vector of unknown parameters, \(\epsilon > 0\) is an ad hoc tolerance, and \(\rho (Y,Y_s)\) is a discrepancy measure between summary statistics of the observed data Y and the simulated data \(Y_s\). Because the sufficient statistics are not available for this problem, the authors use a goodness-of-fit statistic. However, the ABC method suffers from loss of information because of non-zero tolerance and non-sufficient summary statistics (Sunnåker et al. 2013). Therefore, credible intervals obtained by the ABC approach are potentially inflated (Csilléry et al. 2010).

Fig. 3
figure 3

Posterior density surface of \((\log \mu _L, \log \eta )\) under within-host macro-parasite model. The “\(\times \)” symbol represents the estimate from Drovandi and Pettitt (2011) using the ABC method

In contrast, our method makes direct likelihood computation and in turn evaluation of the posterior density feasible. Figure 3 displays a visualization of the posterior density surface of \((\log \mu _L, \log \eta )\) computed using our method, given the collection of numbers of mature parasites M(t) at autopsy under this model (see Drovandi and Pettitt 2011 for more details about the data). Importantly in this example, we are able to efficiently integrate out the unobserved larvae counts L(t) at autopsy. The approximate estimate obtained by Drovandi and Pettitt (2011) using ABC is overlaid on this density surface for comparison, and does not align with the highest density region of our computed posterior. Note that the posterior is flat when \(\eta \) is close to 0, and has an unusual tail toward the region where the ABC estimate lies. This suggests that the previous ABC approach fails to explore the region with high posterior probability well, likely due to loss of information incurred by the method, resulting in a poor estimate from the data.

Finally, we consider this example toward a second runtime comparison between our method and Expokit, a state-of-the-art matrix exponentiation package with efficient implementation. In particular, we compute the transition probability matrix \(\{P^{100,0}_{ij}(t)\}_{0 \le i \le 100, 0 \le j \le 100}\) of \(\{L(t), M(t)\}\) with \(\mu _L = 0.0682, \mu _M = 0.0015, \eta = 0.0009, \gamma = 0.04\) at \(t = 100, 200, 400\) using our function dbd_prob and the function expv in expoRkit, an R-interface to the Fortran package Expokit. Both methods produce similar results: the \(L_1\) distance between the two estimated transition probability matrices is less than \(3 \times 10^{-9}\) across all cases. In terms of speed, we see that dbd_prob is roughly twice as fast as expv when \(t=100, 200\), but about 9-fold faster when \(t=400\) (Fig. 4). It is worth mentioning that dbd_prob can be further accelerated via parallelization.

Fig. 4
figure 4

CPU compute time ratios of expv to dbd_prob over 100 replications

3.4 Stochastic SIR model in epidemiology

McKendrick (1926) models the spread of an infectious disease in a closed population by dividing the population into three categories: susceptible persons (S), infectious persons (I) and removed persons (R). Since the population is closed, the total population size N obeys the conservation equation \(N = S(t) + I(t) + R(t)\) for all time t. The deterministic dynamics of these three subpopulations follow a system of nonlinear ordinary differential equations (Kermack and McKendrick 1927):

$$\begin{aligned} \frac{dS}{dt}(t)&= - \beta S(t)I(t), \nonumber \\ \frac{dI}{dt}(t)&= \beta S(t)I(t) - \alpha I(t),~\text{ and } \nonumber \\ \frac{dR}{dt}(t)&= \alpha I(t), \end{aligned}$$
(38)

where \(\alpha > 0\) is the removal rate and \(\beta > 0\) is the infection rate of the disease. This system of equations cannot be solved analytically, but we can obtain its solution numerically. An important quantity for the SIR model is the basic reproduction number \(R_0 = \beta N / \alpha \) (Earn 2008). This quantity determines whether a spread of an infectious disease becomes an epidemic. In particular, an epidemic can only occur when \(R_0 > 1\).

Unfortunately, the deterministic model is not suitable when the community is small (Britton 2010). In these situations, the original stochastic SIR model (McKendrick 1926) becomes more appropriate. Moreover, Andersson and Britton (2000) argue that stochastic epidemic models are preferable when their analysis is possible because (1) stochastics are the most natural way to describe a spread of diseases, (2) some phenomena do not satisfy the law of large numbers and can only be analyzed in the stochastic setting (for example, the extinction of endemic diseases only occurs when the epidemic process deviates from its expected value), and (3) quantifying the uncertainty in estimates requires stochastic models. Nonetheless, one can bypass Andersson and Britton’s third argument by imposing random sampling errors around the deterministic compartments. Therefore, it is important to distinguish between the deterministic SIR model with sampling errors and the stochastic SIR model.

Without loss of generality, the stochastic SIR model needs only track S(t) and I(t) because \(S(t) + I(t) + R(t)\) remains constant. All possible transitions of \(\{S(t),I(t)\}\) during a small time interval \((t,t + dt)\) occur with probabilities

$$\begin{aligned}&\Pr \left\{ \begin{array}{c | c} S(t+dt) = s~~~~~ &{} S(t)= s \\ I(t+dt) = i-1 &{} I(t) = i \end{array} \right\} = (\alpha i) dt + o(dt), \nonumber \\&\Pr \left\{ \begin{array}{c | c} S(t+dt) = s - 1 &{} S(t)= s \\ I(t+dt) = i+1 &{} I(t) = i \end{array} \right\} = (\beta s i) dt + o(dt),~\text{ and } \nonumber \\&\Pr \left\{ \begin{array}{c | c} S(t+dt) = s~~~~~ &{} S(t)= s \\ I(t+dt) = i~~~~~ &{} I(t) = i \end{array} \right\} = 1 - (\alpha i + \beta s i)dt + o(dt). \end{aligned}$$
(39)

We see that \(\{S(t),I(t)\}\) is a death/birth-death process with \(\mu ^{(1)}_{si} = \lambda ^{(2)}_{s,i} = 0\), \(\mu ^{(2)}_{s,} = \alpha i \), \(\gamma _{si} = \beta s i\).

Due to the interaction between populations and nonlinear nature of the model, mechanistic analysis of the stochastic SIR model is difficult, and the lack of an expression for transition probabilities has been a bottleneck for statistical inference. Renshaw (2011) remarks that while one can write out the Kolmogorov forward equation for the system, the “associated mathematical manipulations required to generate solutions can only be described as heroic.” Instead, the majority of efforts involve either simulation based methods or simplifications and tractable approximations to the SIR model. For instance, the stochastic SIR model can be analyzed using ABC (McKinley et al. 2009), but we have already mentioned limitations of this approach. Particle filter methods can be used to analyze SIR models within maximum likelihood (Ionides et al 2006; Ionides et al. 2015) and Bayesian frameworks (Andrieu et al. 2010; Dukic et al. 2012), but these methods are computationally very demanding and often suffer from convergence problems. When examining large epidemics, to make the likelihood tractable it is reasonable to apply a continuous approximation to the large populations, modeled as a diffusion process with exact solutions (Cauchemez and Ferguson 2008). However, such an approach is a poor proxy for the SIR model when observed counts are low. When data are collected at regular intervals and coincide with disease generation timescales, it is also possible to study discrete-time epidemic models—the time-series SIR (TSIR) model is one well-known example (Finkenstädt and Grenfell 2000). However, these simplifications also have their shortcomings, relying on the relatively strong assumption that populations are constant over each interval between observation times.

In the death/birth-death framework, our method enables practical computation of these quantities without any simplifying model assumptions. In Sect. 4, we will apply our method to analyze the population of Eyam during the plague of 1666 (Raggett 1982) to estimate the infection and the death rates of this disease, using the death/birth-death transition probabilities within a Metropolis-Hastings algorithm. Here, we first examine the accuracy of these transition probabilities themselves. We compare the continued fraction method to empirical transition probabilities obtained via simulation from the true model as ground-truth, and to a new two-type branching approximation to the SIR model introduced below. The branching process approximation is appropriate when transition probabilities need to be computed for short time intervals, and its simple expressions for transition probabilities enable much more efficient computation. However, we show that as transition time intervals increase, the branching approximation becomes less accurate, while the transition probabilities computed under the death/birth-death model remain very accurate.

While branching processes fundamentally rely on independence of each member of the population, we can nonetheless make a fair approximation by mimicking the interaction effect of infection over short time intervals. In the branching model, let \(X_1(t)\) denote the susceptible population and \(X_2(t)\) denote the infected population at time t, with details and derivation included in “Appendix D”. Over any time interval \([t_0, t_1)\), we use the initial population \(X_2(0)\) as a constant scalar for the instantaneous rates. This branching process model has instantaneous infection rate \(\beta X_2(0) X_1(t)\) and recovery rate \(\alpha X_2(t)\) for all \(t \in [t_0, t_1)\), closely resembling the true SIR model rates, with the exception of fixing \(X_2(0)\) in place of \(X_2(t)\) in the rate of infection. This constant initial population fixes a piecewise homogeneous per-particle birth rate to satisfy particle independence while mimicking interactions, but notice that both populations can change over the interval, offering much more flexibility than models such as TSIR that assume constant populations and rates between discrete observations.

This branching model admits closed-form solutions to the transition probabilities that can be evaluated quickly and accurately. The transition probabilities of the two-type branching approximation to the SIR model over any time interval of length t are given by

$$\begin{aligned} \text {Pr} \left\{ \mathbf {X}(t+\tau ) = (k,l) | \mathbf {X}(\tau ) = (m,n) \right\} := P_{kl}^{mn}(t) = \sum _{i=0}^l {l \atopwithdelims ()i} A(l-i) B(i), \end{aligned}$$
(40)

where

$$\begin{aligned} B(i)&= 0 \text { for all } i \ge n, \text { otherwise}, \nonumber \\ B(i)&= \frac{n!}{(n-i)!} (1 - e^{-\alpha t})^{n-i} e^{-i \alpha t} \end{aligned}$$
(41)

and

$$\begin{aligned} A(l-i)&= 0 \text { for all } (l-i) \ge (m-k), \text { otherwise}, \nonumber \\ A(l-i)&= \frac{m!}{(m-k-(l-i))!} e^{-k \beta n t}\nonumber \\&\quad \times \left[ 1 - \frac{\beta n }{\beta n - \alpha } e^{-\alpha t} - \left( 1 - \frac{ \beta n}{\beta n - \alpha } \right) e^{-\beta n t} \right] ^{m-k-(l-i)} \nonumber \\&\quad \times \left[ \frac{ \beta n}{\beta n - \alpha } ( e^{- \alpha t} - e^{-\beta n t} ) \right] ^{l-i}. \end{aligned}$$
(42)

The sum over products of expressions (41) and (42) in Eq. (40) may look unwieldy, but this sum is computed extremely quickly with a vectorized implementation, and with high degrees of numerical stability. In settings when such a model is appropriate and \((X_1(t), X_2(t)) \approx (S(t), I(t) )\), the branching approximation can offer a much more computationally efficient alternative to the continued fraction method.

Fig. 5
figure 5

The plot above displays the values of the nine largest transition probabilities when \(t=0.5\) as we vary t from \(0.1, \ldots , 1.0\). Parameters used to generate data are initialized at \(I_0 = 15, S_0 = 110, \alpha = 3.2, \beta = 0.025\). Empirical Monte Carlo \(95\%\) confidence intervals over 150, 000 simulations from the true model are depicted in orange. Probabilities computed using the continued fraction expansion are depicted by purple triangles, while probabilities computed under the branching approximation are denoted by green squares

3.5 Transition probabilities of the SIR model

Figure 5 provides a comparison between methods of computing transition probabilities. Included are transition probabilities corresponding to the nine pairs of system states \(\left\{ (m,n),(k,l) \right\} _j\), \(j = 1, \ldots , 9\), such that \(P_{kl}^{mn}(0.5)\) is largest. Fixing these indices, we plot the set of probabilities \(\left\{ P_{kl}^{mn}(t)\right\} \) while varying t between 0.1 and 1.0. We see that transition probabilities computed using the continued fraction method under the death/birth-death model very closely match those computed empirically via simulation from the model, taken to be the ground truth. Almost all such probabilities in Fig. 5 fall within the 95% confidence interval, while the branching process transitions follow a similar shape over time, but fall outside of the confidence intervals for many observation intervals. An additional heatmap visualization comparing the support of transition probabilities is included in the Appendix, and shows that the branching approximation is accurate with similar support to the empirical transition probabilities for a shorter time interval of length \(t = 0.5\), but becomes visibly further from the truth when we increase the observation length to \(t=1.0\).

4 The Plague in Eyam revisited

We revisit the outbreak of plague in Eyam, a village in the Derbyshire Dales district, England, over the period from June 18th to October 20th, 1666. This plague outbreak is widely accepted to originate from the Great Plague of London, that killed about \(15\%\) of London’s population at that time. To prevent further spread of the plague after infestation, the Eyam villagers did not escape the village, instead isolating themselves from the outside world. At the end of this horrific event, only 83 people had survived out of an initial population of 350. We summarize data recording the spread of the disease (Raggett 1982) in Table 1. As mentioned in Raggett (1982), this data are obtained by counting the number of deaths from the dead list and estimating the infective population from the list of future deaths assuming a fixed length of illness prior to death. Then, the susceptible population can be computed easily because the the town is isolated.

Table 1 Susceptible and infectious population size in Eyam from June 18th to October 20th, 1666

Raggett (1982) analyzes these data using the stochastic SIR model (39). In this model, \(\alpha \) is the unknown death rate of infective people and \(\beta \) is the unknown infection rate of the plague. The author uses a simple approximation method for the forward differential equation and comes up with a point estimate \((\hat{\alpha }, \hat{\beta }) = (3.39, 0.0212)\). We take a Bayesian approach to re-analyze these data.

With n observations \(\{ (s_k, i_k) \}_{k=1}^n\) at time \(\{ t_k \}_{k=1}^n\), the log of the likelihood function is:

$$\begin{aligned} \log l \left( \alpha , \beta \big | \{ (s_k, i_k) \}_{k=1}^n \right) = \sum _{k=1}^{n-1}{ \log \Pr \left\{ \begin{array}{l | l} S(t_{k+1}) = s_{k+1} &{} S(t_k) = s_k \\ I(t_{k+1}) = i_{k+1} &{} I(t_k) = i_k \end{array} \right\} }. \end{aligned}$$
(43)

Because \(\{S(t),I(t)\}\) is a death/birth-death process, the individual transition probabilities can be computed efficiently using our continued fraction method. Hence, the log of the likelihood (43) can be computed easily. Since \(\alpha \) and \(\beta \) are non-negative, we opt to use \(\log \alpha \) and \(\log \beta \) as our model parameters and assume a priori that \(\log \alpha \sim \mathcal{N}(\mu = 0, \sigma = 100)\) and \(\log \beta \sim \mathcal{N}(\mu = 0, \sigma = 100)\). We explore the posterior distribution of \((\log \alpha , \log \beta )\) using a random-walk Metropolis algorithm implemented in the R function MCMCmetrop1R from package MCMCpack (Martin et al. 2011). We start the chain from Raggett’s estimated value \((\log (3.39), \log (0.0212))\) and run it for 100000 iterations. We discard the first 20000 iterations and summarize the posterior distribution of \((\alpha , \beta )\) using the remaining iterations. We illustrate the density of this posterior distribution in Fig. 6a. The posterior mean of \(\alpha \) is 3.22 and the \(95\%\) Bayesian credible interval for \(\alpha \) lies in (2.69, 3.82). Those corresponding quantities for \(\beta \) are 0.0197 and (0.0164, 0.0234). Notice that our credible intervals include the point estimate \((\hat{\alpha }, \hat{\beta }) = (2.73, 0.0178)\) from Brauer (2008) using the deterministic SIR model and Raggett’s point estimate \((\hat{\alpha }, \hat{\beta }) = (3.39, 0.0212)\).

We also apply the two-type branching approximation to compute the log of the likelihood (43). Using the same random-walk Metropolis algorithm as before, we explore the posterior distribution of \((\alpha , \beta )\) and visualize it in Fig. 6b. The posterior mean of \(\alpha \) is 3.237 and the \(95\%\) Bayesian credible interval for \(\alpha \) is (2.7, 3.84), while those quantities for \(\beta \) are 0.02 and (0.0171, 0.023). Although the posterior means and the \(95\%\) Bayesian credible intervals are similar to ones from the continued fraction method, we see in Fig. 6b that this method fails to fully capture the posterior correlation structure between \(\alpha \) and \(\beta \).

Fig. 6
figure 6

Posterior distributions (log scale) of the death rate \(\alpha \) and the infection rate \(\beta \) during the plague of Eyam in 1666. The “\(+\)” symbol represents the estimate from Brauer (2008) using the deterministic SIR model, and the “\(\times \)” symbol represents the Raggett’s point estimate. a Continued fraction method b branching approximation method

The posterior distribution of the basic reproduction number \(R_0\) from the continued fraction method and from the branching approximation method are similar (Fig. 7). The posterior mean of \(R_0\) from the continued fraction method is 1.61 and from the branching approximation method is 1.62. The estimate for \(R_0\) from Brauer (2008) is 1.7, from Raggett (1982) is 1.63. These estimates are similar, and in particular the branching approximation estimate is very close to that under the continued fraction method, offering a very efficient way to provide reasonable estimates of quantities such as \(R_0\) despite being less accurate than the continued fraction approach.

Fig. 7
figure 7

Posterior distribution of the basic reproduction number \(R_0\) (solid line: continued fraction method, dashed line branching approximation method). The “\(+\)”, and the “\(\times \)” symbols represent the estimate of \(R_0\) from Brauer (2008), and from Raggett (1982) respectively

From the results, we can see that estimates of \(R_0\) from different methods are roughly the same while estimates of \(\alpha \) and \(\beta \) are different. Although the basic reproduction number \(R_0\) is an important quantity in the SIR model, it is not the only parameter driving the dynamic of the epidemic. Correia-Gomes et al. (2014) demonstrated the important of accurately estimating the transmission parameters between compartments of the SIR model for Salmonella Typhimurium in pigs.

5 Discussion

Likelihood-based inference for bivariate continuous-time Markov processes is usually restricted to very small state spaces due to the computational bottleneck of transition probability calculation. In this paper, we provide tools for likelihood-based inference for birth(death)/birth-death processes by developing an efficient method to compute their transition probabilities. We provide a complete implementation of the algorithms to compute these transition probabilities in a new R package called MultiBD. Our functions employ sophisticated tools including continued fractions, the modified Lentz method, the method of Abate and Whitt for approximate inverse Laplace transforms, and the Levin acceleration method. Moreover, these methods are naturally amenable to parallelization, and we exploit multicore processing to speed up the algorithm. We remark that birth(death)/birth-death processes remain a limited subclass of general multivariate birth-death processes. For example, many population biology problems require a full bivariate birth-death process including predator-prey models (Hitchcock 1986; Owen et al. 2015) and the SIR model with vital dynamics (Earn 2008). Unfortunately, efficiently computing the transition probabilities of multivariate birth-death processes remains an open problem. Solving this problem will enable numerically stable statistical inference under birth-death processes and will be worth the “heroic” effort (Renshaw 2011).