# Sojourn times in different compartments

How long does an individual spend in an infected state or compartment? This duration, also known as the _sojourn_ time, isn’t a fixed value, so it’s important to know the distribution of these sojourn times. In Markov-Chain-Monte-Carlo simulations like ours, the sojourn times are exponentially distributed. First we will explain why the distribution is exponential, which can allow us to change our algorithm for non-exponential cases.

We discretise time into small intervals or time-steps of \(\Delta t\), so that the total time \(T = N \Delta t\), where \(N\) is the total number of time-steps. In every small step \(\Delta t\) an individual in our disease model has a small probability, \(p\), of exiting the compartment. The value of \(p\) depends on factors such as the number of individuals in that compartment at that time, and so on.

To simulate \(p\), we draw a random number \(r\) from a uniform distribution. If \(r < p\), the individual exits the compartment. This is equivalent to saying:

This is the only role of the uniform distribution here.

Now, we ask ourself the following question: *what is the probability that an individual will leave a compartment at some time \(t\)?* In our scheme, this is equivalent to asking what the probability is of the event occurring between time \(t\) and \(t + \Delta t\). We will call this probability \(P(t)\Delta t\). We’ve also discretized time into units of \(\Delta t\), so we can define \(t = n\Delta t\), where \(n\) is the number of steps of \(\Delta t\).

This allows us to reframe the problem as this: *what is the probability that the individual will leave the compartment after exactly \(n\) steps?* This is given by:

Using the fact that \(p = \lambda \Delta t\), and that \(\Delta t = T/N\), we can show that:

To find the true probability density, we need to take the limit \(N\to\infty\), i.e. \(N/T \to \infty\), and so

so that the probability distribution is:

Exercise

Show that the probability that an individual exits the compartment $I$ exactly after some time $t = n \Delta t$ is given by: $$\mathcal{P}(t)\,\Delta t = p_\text{IR} (1-p_\text{IR})^n.$$

Using the fact that $p=\lambda_I\,\Delta t$, and $\Delta t = T/N_\text{steps}$ (Where $T$ is the total simulation time and $N_\text{steps}$ the total number of steps): $$\mathcal{P}(t)\,\Delta t = \left(1 - \frac{\lambda_I T}{N_\text{steps}}\right)^{t N_\text{steps}/T}\, \lambda_I \, \Delta t.$$

Next, take the limit $N_\text{steps}\to\infty$, and $\Delta t\to 0$, keeping $N_\text{steps}\,\Delta t = T$, and argue that $$\mathcal{P}(t) = \lambda_I \, e^{-\lambda_I t}.$$ The sojourn times in the infected compartment are exponentially distributed, with mean $\tau_I = 1/\lambda_I$! In other words, this is a succession of Poisson processes – characteristic of Markov Chain Monte Carlo processes: happens every time the probability of a transition is independent of the history.

Can the same argument be used to say that the sojourn time in the susceptible compartment is $\tau_S = 1/\lambda_S$? Explain.