This post discusses the technique of collapsing a set of states into an absorbing state to order to make certain Markov chain problems easier. We motivate the technique with the following examples. The method discussed here is to raise the new transition probability matrix (the one with the collapsed absorbing state) to an appropriate th power (ChapmanKolmogorov equations are discussed here). Other applications of Markov chains are discussed here. Markov chains are applied to the occupancy problem in this previous post.
Example 1
On any given day, the weather condition in a city is either sunny, cloudy (but not rainy) or rainy. The weather condition on a given day is identical to that of the previous day with probability 0.5. The weather condition on a given day is equally likely to be one of the other two weather conditions if it is different from the previous day. Suppose that it is sunny today in this city. Find the probability that none of the next five days will be rainy.
Example 2
A fair coin is flipped repeatedly until a run of 4 consecutive heads appear. We want to know how many flips are required to achieve this goal. Specifically we have the following questions.
 Find the probability that it takes at most 9 flips to get a run of 4 consecutive heads.
 Find the probability that it takes at exactly 9 flips to get a run of 4 consecutive heads.
Example 3
A maze is divided into 9 areas as shown below.
A mouse is placed in area 1 initially. Suppose that areas 3, 7 and 9 contain food and that the other areas in the maze do not contain food. Further suppose that the mouse moves through the areas in the maze at random. That is, whenever the mouse is in an area that has exits, the next move is to one of these areas with probability .
 Find the probability that after the 5 moves, the mouse is one area from a food source.
 Find the probability that after the 7 moves, the mouse has not found food and is in area 6 or area 8 after the 7th move.
 Find the probability that it takes at most 8 moves for the mouse to find food.
 Find the probability that it takes exactly 8 moves for the mouse to find food.
Working Example 1
We work Example 1 to illustrate the method. The following is the transition probability matrix for Example 1 where state 0 = sunny weather, state 1 = cloudy weather and state 2 = rainy weather.

$latex
\mathbf{P} =
\bordermatrix{ & 0 & 1 & 2 \cr
0 & 0.50 & 0.25 & 0.25 \cr
1 & 0.25 & 0.50 & 0.25 \cr
2 & 0.25 & 0.25 & 0.50 \cr
} \qquad$
Since it is currently a sunny day, . The probability of not having a rainy day in the next 5 days is the probability . This is the probability that or for the next 5 periods given the current state is 0. Because the range of movement is restricted, using the ChapmanKolmogorov equations, i.e. finding the 5th power of the matrix , does not work. For example, though is the probability that the chain will end up in state 1 at time 5 given that it is in state 0 at time 0, the probability would include the possibilities of a rainy day (state 2) in between time 0 and time 5. The technique is to make the state 2 (the state that is not to be visited in the next 5 days) an absorbing state. Doing so produces a new transition probability matrix.

$latex
\mathbf{Q} =
\bordermatrix{ & 0 & 1 & 2 \cr
0 & 0.50 & 0.25 & 0.25 \cr
1 & 0.25 & 0.50 & 0.25 \cr
2 & 0 & 0 & 1 \cr
} \qquad$
The matrix is obtained by changing state 2 in the matrix an absorbing state (i.e. the entry in the row for state 2 and in the column for state 2 has probability 1). It is a valid transition probability matrix since the sum of each row is 1. So it describes a Markov chain. How does the new Markov chain relate to the original Markov chain? The following is the 5th power of .

$latex
\displaystyle \mathbf{Q}^5 =
\bordermatrix{ & 0 & 1 & 2 \cr
0 & \frac{122}{1024} &\frac{121}{1024} & \frac{781}{1024} \cr
\text{ } & \text{ } & \text{ } & \text{ } \cr
1 & \frac{121}{1024} & \frac{122}{1024} & \frac{781}{1024} \cr
\text{ } & \text{ } & \text{ } & \text{ } \cr
2 & 0 & 0 & 1 \cr } \qquad
=
\bordermatrix{ & 0 & 1 & 2 \cr
0 & 0.11914 & 0.11816 & 0.76270 \cr
\text{ } & \text{ } & \text{ } & \text{ } \cr
1 & 0.11816 & 0.11914 & 0.76270 \cr
\text{ } & \text{ } & \text{ } & \text{ } \cr
2 & 0 & 0 & 1 \cr
} \qquad$
The transition probability is the probability of transitioning in the new process from state 0 at time 0 to state 2 at time 5 (the 5th day). Starting at state 0, there is a 76.27% chance that the new process will reach state 2 at time 5. This means that the original process will have reached state 2 at time 5 or prior to time 5. The complement of this probability is . So there is a 23.73% chance the original process will never reach state 2 at any time in the first 5 periods. If the weather is indeed governed the chain described in , it is likely (76.27% chance) that there will be a rainy day at some point within the next 5 periods (given that today is sunny). In fact, even if today is cloudy, there is also a 76.27% chance that there will be a rainy day within the next 5 days.
Discussion
Before working Example 2, let’s discuss the idea of collapsing states into an absorbing state. Consider a Markov chain with transition probability matrix . Let be the state space of this chain. Let be a set of states. Suppose that the states in are either desirable to enter in or states that are negative situations to be avoided. In case of being desirable or attractive, we wish to find the probability of entering into a state in after a number of transitions. In the case of being negative situations, we wish to find the probability of not in entering into any state in after a number of transitions.
The key to finding these probabilities is to collapse the states in into a state called that is an integer that is different from all states not in . For convenience, we let be the smallest integer that is greater than all states not in . For example, if , and , then .
Now define a new Markov chain by letting all states not in remain the same and by collapsing all states in into the new state . The new state is made an absorbing state. The state space of the new Markov chain is the original states not in along with the new state . Let be the transition probability matrix of the new Markov chain. The transition probabilities in are defined as follows:

$latex \displaystyle Q_{ij} = \left\{ \begin{array}{ll}
\displaystyle P_{ij} &\ \ \ \ \ \ i \notin \mathcal{M}, j \notin \mathcal{M} \\
\text{ } & \text{ } \\
\displaystyle \sum \limits_{k \in \mathcal{M}} P_{ik} &\ \ \ \ \ \ i \notin \mathcal{M}, j=M \\
\text{ } & \text{ } \\
\displaystyle 1 &\ \ \ \ \ \ i=M, j=M \\
\end{array} \right.$
The transition probability matrix is derived from and is closely related to the matrix . For states not in , the transition probabilities are the same in both matrices (the first condition). The second condition says that is the sum of all where . Thus is the probability of the original process entering one of the states in when starting from a state . Since is an absorbing state, .
To calculate the two probabilities concerning the process for indicated earlier, compute powers of the matrix . In the new Markov process for the matrix , there are two kinds of states, the states and the collapsed state . Whenever the process is in state , the process is not yet absorbed (into the state ). When the process starts at a state not in (i.e. not yet absorbed), the process will eventually be absorbed (after some number of transitions).
Consider where . This is the probability that the process starts in state (not yet absorbed) and is absorbed at time . This is the connection between the two processes: being absorbed into state in the new process at time means that the original process enters a state in in some period prior to time or at time . We have the following summary.
Consider a Markov process with the transition probability matrix . Collapse , a set of states, into an absorbing state called in the manner described above. Let be the resulting transition probability matrix of the new Markov chain. For , is the probability of absorption given that the process starts out not being absorbed, i.e. the probability that the original process enters a state in at time or prior to time given that initially the process is in state . Equivalently .
The above observation gives a way to interpret the complement . It would be the probability of the original process never entering any state in during the time periods (given that the process starts at ). This is the answer to Example 1. We have the following summary.
The complement of is . It is the probability that the original process never enters any of the states in during the time periods (given that the process starts at ). Equivalently, can be stated as . Note that the probability is also the sum . Specifically, for , can be stated as .
The probability is the probability of absorption on or prior to time . Another probability of interest is the probability of absorption exactly at time .
As described above, let be the resulting transition probability matrix of the new Markov chain after collapsing some states into an absorbing state. For , is the probability of absorption at time given that the process starts out not being absorbed, i.e. the probability that the original process enters a state in at time given that initially the process is in state . Equivalently .
In a nutshell, the idea of collapsing states into an absorbing state is to inform on two probabilities concerning the original process. To illustrate this process, consider the following example.
Example 0
Consider a Markov chain with the following transition probability matrix.

$latex
\mathbf{P} =
\bordermatrix{ & 0 & 1 & 2 & 3 & 4 & 5 \cr
0 & 0.6 & 0.08 & 0.08 & 0.08 & 0.08 & 0.08 \cr
1 & 0.5 & 0.10 & 0.10 & 0.10 & 0.10 & 0.10 \cr
2 & 0.4 & 0.12 & 0.12 & 0.12 & 0.12 & 0.12 \cr
3 & 0.3 & 0.14 & 0.14 & 0.14 & 0.14 & 0.14 \cr
4 & 0.2 & 0.16 & 0.16 & 0.16 & 0.16 & 0.16 \cr
5 & 0.1 & 0.18 & 0.18 & 0.18 & 0.18 & 0.18 \cr
} \qquad$
Now collapse state 4 and state 5 into a new state called 4. The following is the resulting matrix .
$latex
\mathbf{Q} =
\bordermatrix{ & 0 & 1 & 2 & 3 & 4 \cr
0 & 0.6 & 0.08 & 0.08 & 0.08 & 0.16 \cr
1 & 0.5 & 0.10 & 0.10 & 0.10 & 0.20 \cr
2 & 0.4 & 0.12 & 0.12 & 0.12 & 0.24 \cr
3 & 0.3 & 0.14 & 0.14 & 0.14 & 0.28 \cr
4 & 0 & 0 & 0 & 0 & 1 \cr
} \qquad$
The following is the 6th power of .
$latex
\mathbf{Q}^6 =
\bordermatrix{ & 0 & 1 & 2 & 3 & 4 \cr
0 & 0.195466 & 0.034574 & 0.034574 & 0.034574 & 0.700812 \cr
1 & 0.184167 & 0.032578 & 0.032578 & 0.032578 & 0.718099 \cr
2 & 0.172869 & 0.030582 & 0.030582 & 0.030582 & 0.735386 \cr
3 & 0.161570 & 0.028586 & 0.028586 & 0.028586 & 0.752673 \cr
4 & 0 & 0 & 0 & 0 & 1 \cr
} \qquad$
As a result, is the probability that the new process will be in state 4 at time 4 (given the process starts at state 0). This means that it is the probability that the original process will reach state 4 or state 5 by time 6 (at or before time 6) given the original process starts in state 0. Note that regardless of the initial state, the probability of being absorbed into state 4 or state 5 by time 6 is roughly the same (70% to 75%).
On the other hand, . Thus . Thus there is a 6.9% chance that absorption will take place exactly at time 6.
More Examples
We now work Example 2 and Example 3.
Example 2 (Statement of the example given above)
Define a Markov chain with states 0, 1, 2, 3 and 4 with meaning that there is currently a run of consecutive heads (the last flips are heads) and with state 4 meaning that a run of 4 consecutive heads has already occurred (the last 4 or more flips are heads). Thus state 4 is an absorbing state. The following is the transition probability matrix.
$latex
\mathbf{P} =
\bordermatrix{ & 0 & 1 & 2 & 3 & 4 \cr
0 & 0.5 & 0.5 & 0 & 0 & 0 \cr
1 & 0.5 & 0 & 0.5 & 0 & 0 \cr
2 & 0.5 & 0 & 0 & 0.5 & 0 \cr
3 & 0.5 & 0 & 0 & 0 & 0.5 \cr
4 & 0 & 0 & 0 & 0 & 1 \cr
} \qquad$
Here’s how is derived. For example, if there is currently a run of 2 heads (the third row), the next state is either 0 (the next flip is a tail) or 3 (the next flip is a head) with equal probability. To find the two probabilities in question, raise to the 8th and 9th powers.
$latex
\mathbf{P}^9 =
\bordermatrix{ & 0 & 1 & 2 & 3 & 4 \cr
0 & 0.406250 & 0.210938 & 0.109375 & 0.056641 & 0.216797 \cr
1 & 0.376953 & 0.195313 & 0.101563 & 0.052734 & 0.273438 \cr
2 & 0.320313 & 0.166016 & 0.085938 & 0.044922 & 0.382813 \cr
3 & 0.210938 & 0.109375 & 0.056641 & 0.029297 & 0.593750 \cr
4 & 0 & 0 & 0 & 0 & 1 \cr
} \qquad$
$latex
\mathbf{P}^8 =
\bordermatrix{ & 0 & 1 & 2 & 3 & 4 \cr
0 & 0.421875 & 0.218750 & 0.113281 & 0.058594 & 0.187500 \cr
1 & 0.390625 & 0.203125 & 0.105469 & 0.054688 & 0.246094 \cr
2 & 0.332031 & 0.171875 & 0.089844 & 0.046875 & 0.359375 \cr
3 & 0.218750 & 0.113281 & 0.058594 & 0.031250 & 0.578125 \cr
4 & 0 & 0 & 0 & 0 & 1 \cr
} \qquad$
The starting state is 0 since the coin flips are counted from the very first one. With , we know that the probability of taking 9 flips or less to get 4 consecutive heads is 0.216797.
With , there is a roughly 3% chance that the run of 4 consecutive heads is achieved at the 9th flip.
Example 3 (Statement of the example given above)
Let be the area the mouse is in after making moves. Then is a Markov chain. The following is the transition probability matrix. To help see the matrix, the diagram of the maze is repeated.

$latex
\mathbf{P} =
\bordermatrix{ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 \cr
1 & 0 & 1/2 & 0 & 0 & 0 & 1/2 & 0 & 0 & 0 \cr
2 & 1/3 & 0 & 1/3 & 0 & 1/3 & 0 & 0 & 0 & 0 \cr
3 & 0 & 1/2 & 0 & 1/2 & 0 & 0 & 0 & 0 & 0 \cr
4 & 0 & 0 & 1/3 & 0 & 1/3 & 0 & 0 & 0 & 1/3 \cr
5 & 0 & 1/4 & 0 & 1/4 & 0 & 1/4 & 0 & 1/4 & 0 \cr
6 & 1/3 & 0 & 0 & 0 & 1/3 & 0 & 1/3 & 0 & 0 \cr
7 & 0 & 0 & 0 & 0 & 0 & 1/2 & 0 & 1/2 & 0 \cr
8 & 0 & 0 & 0 & 0 & 1/3 & 0 & 1/3 & 0 & 1/3 \cr
9 & 0 & 0 & 0 & 1/2 & 0 & 0 & 0 & 1/2 & 0 \cr
} \qquad$
States 3, 7 and 9 are desirable states since these are the areas with food. Let . We then collapse into a new state called 9. The state 9 in the new process is an absorbing state, which means that the original process has reached a state with food (states 3, 7 and 9). The following is the transition probability matrix for the new (collapsed) process.

$latex
\mathbf{Q} =
\bordermatrix{ & 1 & 2 & 4 & 5 & 6 & 8 & 9 \cr
1 & 0 & 1/2 & 0 & 0 & 1/2 & 0 & 0 \cr
2 & 1/3 & 0 & 0 & 1/3 & 0 & 0 & 1/3 \cr
4 & 0 & 0 & 0 & 1/3 & 0 & 0 & 2/3 \cr
5 & 0 & 1/4 & 1/4 & 0 & 1/4 & 1/4 & 0 \cr
6 & 1/3 & 0 & 0 & 1/3 & 0 & 0 & 1/3 \cr
8 & 0 & 0 & 0 & 1/3 & 0 & 0 & 2/3 \cr
9 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \cr
} \qquad$
The state 9 in the matrix refers to the situation in the original process reaching states 3, 7 or 9. Then all the questions in the example can be answered by raising to an appropriate power. In particular, raising to the 5th, 7th and 8th power.

$latex
\mathbf{Q}^5 =
\bordermatrix{ & 1 & 2 & 4 & 5 & 6 & 8 & 9 \cr
1 & 0 & 5/36 & 1/18 & 0 & 5/36 & 1/18 & 11/18 \cr
2 & 5/54 & 0 & 0 & 7/54 & 0 & 0 & 7/9 \cr
4 & 1/27 & 0 & 0 & 1/18 & 0 & 0 & 49/54 \cr
5 & 0 & 7/72 & 1/24 & 0 & 7/72 & 1/24 & 13/18 \cr
6 & 5/54 & 0 & 0 & 7/54 & 0 & 0 & 7/9 \cr
8 & 1/27 & 0 & 0 & 1/18 & 0 & 0 & 49/54 \cr
9 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \cr
} \qquad$
$latex
\mathbf{Q}^7 =
\bordermatrix{ & 1 & 2 & 4 & 5 & 6 & 8 & 9 \cr
1 & 0 & 17/216 & 7/216 & 0 & 17/216 & 7/216 & 7/9 \cr
2 & 17/324 & 0 & 0 & 2/27 & 0 & 0 & 283/324 \cr
4 & 7/324 & 0 & 0 & 5/162 & 0 & 0 & 307/324 \cr
5 & 0 & 1/18 & 5/216 & 0 & 1/18 & 5/216 & 91/108 \cr
6 & 17/324 & 0 & 0 & 2/27 & 0 & 0 & 283/324 \cr
8 & 7/324 & 0 & 0 & 5/162 & 0 & 0 & 307/324 \cr
9 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \cr
} \qquad$
$latex
\mathbf{Q}^8 =
\bordermatrix{ & 1 & 2 & 4 & 5 & 6 & 8 & 9 \cr
1 & 17/324 & 0 & 0 & 2/27 & 0 & 0 & 283/324 \cr
2 & 0 & 29/648 & 1/54 & 0 & 29/648 & 1/54 & 283/324 \cr
4 & 0 & 1/54 & 5/648 & 0 & 1/54 & 5/648 & 307/324 \cr
5 & 1/27 & 0 & 0 & 17/324 & 0 & 0 & 295/324 \cr
6 & 0 & 29/648 & 1/54 & 0 & 29/648 & 1/54 & 283/324 \cr
8 & 0 & 1/54 & 5/648 & 0 & 1/54 & 5/648 & 307/324 \cr
9 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \cr
} \qquad$
The statements for the probabilities to be sought are repeated here.
 Find the probability that after the 5 moves, the mouse is one area from a food source.
 Find the probability that after the 7 moves, the mouse has not found food and is in area 6 or area 8 after the 7th move.
 Find the probability that it takes at most 8 moves for the mouse to find food.
 Find the probability that it takes exactly 8 moves for the mouse to find food.
To obtain the answers, it is a matter of picking the entries from the matrices.
One area from a food source means being in areas 2, 4, 6 and 8. Thus the first probability is . The probability of being in areas 6 or 8 after 7 moves is . The probability that it will take 8 moves or less to reach food is . The probability of reaching food in exactly 8 moves is .
With the matrices , and , we can also find out the probability of reaching food. Just from the diagram, it is clear that the likelihood of reaching food is greater if the initial position is area 8 or area 6. Between these two areas, it is easier to reach food if the mouse is in area 8 initially since area 8 is adjacent to two food sources. This is also confirmed by the calculation. For example, and . So it is over 90% certain that the mouse will find food if it is placed in area 8 initially.
2017 – Dan Ma
Pingback: Probability problems using Markov chains  A Blog on Probability and Statistics
Pingback: Making use of Markov chains – Climbing Math Everest
Pingback: Making use of Markov chains – Climbing Math Everest
Pingback: Celebrate the year of the dog  All Math Considered