Solution (source code)

= Solution

Use the compartment counts $Z_n=(S_n,I_n,R_n)$ as the state of the <SIRS Markov chain>. Its state space is $\{(S,I,R)\in\mathbb Z_{\ge0}^3:S+I+R=n\}$. The <transition rates> are
$$
\begin{array}{c|c}
\text{new state}&\text{rate from }(S,I,R)\\\hline
(S-1,I+1,R)&\lambda SI/n\\
(S,I-1,R+1)&\gamma I\\
(S+1,I,R-1)&\nu R.
\end{array}
$$
Each susceptible has infection hazard $\lambda I/n$, so summing over the $S$ susceptibles gives the first rate. The <memorylessness of the exponential distribution> makes each of the $I$ current infectives have recovery hazard $\gamma$, irrespective of its infection time. Each removed individual has immunity-loss hazard $\nu$. These are all the possible off-diagonal transitions. The diagonal entry of the <transition intensity matrix> is minus their sum, and a transition with no eligible individual has rate zero. Thus \b[the three total event rates are $\lambda SI/n$, $\gamma I$ and $\nu R$], and every event conserves population size.