07
Programming a DTMC SIS model
The SIS model describes an infection that does not give lasting immunity. Recovery returns an infectious person to the susceptible compartment, so the same person may later become infected again.
The new biological idea: reinfection
Unlike the SIR model, SIS has no removed compartment. Recovery does not create permanent immunity. SIS models can be useful for infections for which immunity is absent, short-lived or ignored at the chosen modelling scale.
Closed population and a one-dimensional state
Assume a closed population of constant size \(N\):
Knowing \(I_n\) automatically determines the susceptible count:
Therefore the DTMC can use the single integer state \(X_n=I_n\) with state space:
This reduction is not an approximation. It follows exactly from population conservation.
Possible movements from state (i)
Suppose \(I_n=i\). Under the one-event-per-step assumption, the next infectious count can be only:
Infection: upward movement
One susceptible person becomes infectious.
Recovery: downward movement
One infectious person becomes susceptible again.
No change: stay
No infection or recovery occurs in the step.
A chain with only upward, downward and stay movements between neighbouring integer states is commonly called a birth–death DTMC. Here “birth” means an increase in the infectious count, not a biological birth.
Derive the SIS transition probabilities
At state \(i\), the susceptible count is \(N-i\). The infection and recovery event rates are:
For sufficiently short fixed step \(\Delta t\), the DTMC probabilities are:
| Symbol | Meaning | State change |
|---|---|---|
| \(p_i\) | Infection probability at state \(i\) | \(+1\) |
| \(q_i\) | Recovery probability at state \(i\) | \(-1\) |
| \(r_i\) | No-change probability at state \(i\) | \(0\) |
Why the probabilities change with the state
This DTMC is time-homogeneous when \(\beta\), \(\gamma\) and \(\Delta t\) remain fixed. However, its transition probabilities still depend on the current infectious count \(i\).
- When \(i\) is small, there are many susceptible people but few infectious people.
- At intermediate values, both groups are present, so infection probability can be larger.
- When \(i\) is near \(N\), few susceptible people remain, so infection probability falls.
- Recovery probability increases linearly with \(i\).
Boundary states
Extinction: (i=0)
With no infectious people, neither infection nor recovery can occur. State 0 is absorbing.
Everyone infectious: (i=N)
There is nobody susceptible to infect, but recovery can move the process down to \(N-1\). State \(N\) is not absorbing when \(\gamma>0\).
Check one fixed time step over the whole state space
A simulation may visit many values of \(i\). Therefore it is not enough to check the probabilities only at the initial state. For every possible state:
The code calculates this sum for every integer state and rejects \(\Delta t\) if any no-change probability is negative.
Satisfying the inequality makes the probabilities valid. It does not by itself prove that the one-event approximation is accurate. A smaller time step makes multiple unrepresented events within one step less likely.
Interactive Python laboratory
The program verifies all states, simulates one SIS trajectory, records event counts and creates two graphs: the realised epidemic path and the transition probabilities across the state space.
Output
Run the code to see the result.
Read the two graphs differently
| Graph | Question answered | What it represents |
|---|---|---|
| Trajectory graph | What happened in this simulation? | One randomly realised path through time. |
| Probability-by-state graph | How does the model behave from each possible state? | The model's transition rule, not one realised path. |
Do not interpret the probability curves as compartment trajectories. Their horizontal axis is the current state \(i\), not time.
What does \(\beta/\gamma\) tell us?
For this simple SIS model, the ratio:
compares transmission with recovery near the disease-free state. If it exceeds 1, infection has an initial tendency to grow in the corresponding deterministic model.
\(\mathcal R_0>1\) does not guarantee growth in every stochastic realisation. With only a few infectious people, early recoveries can still send the DTMC to the absorbing state \(I=0\).
Why event counts are not counts of different people
In an SIS trajectory, one person can be infected, recover and later become infected again. Therefore the total number of infection events may exceed the population size.
This differs from a closed SIR model, where a person enters the removed compartment after recovery and cannot be infected again. SIS has no conventional “final epidemic size” measured by a permanently removed compartment.
Understand the model-specific code
| Code | Meaning |
|---|---|
susceptible = N - i | Reconstructs \(S\) from the one-dimensional infectious state. |
return i + 1 | An infection moves the birth–death chain one state upward. |
return i - 1 | A recovery returns one person to susceptibility and moves the chain downward. |
np.arange(N + 1) | Creates every infectious-count state from 0 through \(N\), including both boundaries. |
.argmax() | Returns the position where the total event probability is largest. |
N - np.array(I_values) | Calculates the complete susceptible trajectory from the stored infectious counts. |
Try these experiments
- Change
seed = 7. Compare early extinction with longer persistence. - Set
initial_I = 1. Explain why early chance events become especially influential. - Use
beta = 0.15andgamma = 0.20, so \(\beta/\gamma<1\). Compare the trajectory. - Increase
dtgradually. Find when the whole-state-space validity check rejects it. - Set
initial_I = N. Confirm from the probability graph that infection probability is zero at the right boundary.
Biological interpretation
The SIS model permits repeated circulation because recovery replenishes the susceptible group. Nevertheless, a finite closed stochastic population eventually can reach \(I=0\), after which the infection cannot return without importation.
A trajectory that remains infectious at 300 days demonstrates persistence during the observation window. It does not prove permanent persistence. Similarly, an early extinction path does not prove that every introduction will fail.
What this lesson has added
- SIS recovery returns people to susceptibility.
- Population conservation reduces the state to the single count \(I_n\).
- The process moves between neighbouring states \(i-1,i,i+1\).
- State 0 is absorbing, while state \(N\) allows recovery.
- A fixed time step must be valid across the whole state space.
- One person may contribute multiple infection events through reinfection.
Lesson 8 turns to the SIR model, where recovery is irreversible and the removed compartment makes final epidemic size meaningful.