How to Calculate Probabilities in a Markov Chain
At a glance
- 1. Define the states
List every possible state and decide what one time step represents.
- 2. Build the transition matrix
Place each probability of moving from a current state to a next state in the appropriate matrix entry.
- 3. Choose the initial distribution
Represent the starting state or uncertainty about the starting state as a probability vector.
- 4. Advance the chain
Multiply by the transition matrix once per time step, or use a matrix power.
- 5. Extract the desired probability
Read the relevant component or sum the components for the target states.
A Markov chain models a process that moves between states in discrete time. Its defining property is that the distribution of the next state depends on the current state, not on the full history:
The phrase “calculate the probability” can mean several things: the probability of a state after a fixed number of steps, the probability of one particular path, the probability of ever reaching a state, or the long-run proportion of time spent in each state. The transition matrix gives the first two directly; the other questions require related equations.
Transition matrices
Suppose the chain has states . Using the common row-vector convention, define the transition matrix by
Thus, row describes where the chain can go when it is currently in state . Every entry must satisfy , and every row must sum to :
If the current-state distribution is the row vector
then the next distribution is
After steps,
If the chain starts in state with certainty, has a in position and zeros elsewhere. The probability of being in state after steps is the th component of .
Worked example: state after three steps
Consider a two-state weather chain with states Sunny () and Rainy (). Suppose
- after a sunny day, the next day is sunny with probability and rainy with probability ;
- after a rainy day, the next day is sunny with probability and rainy with probability .
With the state order ,
Assume today is sunny, so
The required probability that it rains three days from today is the second component of .
First calculate the powers of :
and
Therefore,
The probability of rain three days from today is therefore , or 31.2%.
The entry has a useful direct interpretation: it is the probability of being in state after steps, given that the chain started in state .
Probability of one particular path
If you want the probability of a specified sequence of states, multiply the transition probabilities along the path. For example, in the weather chain, the path
has probability
So this particular three-transition path has probability .
Do not confuse this with the probability of being sunny after three steps. Many different paths end in , and their probabilities must be added. Matrix multiplication performs that summation automatically.
If the starting state is uncertain
Suppose the weather is sunny with probability and rainy with probability . Then
The distribution after three days is
Thus the probability of rain after three steps is . An uncertain initial state is handled by averaging over the possible starting states through the initial distribution vector.
Hitting or reaching probabilities
“Will the chain ever reach state ?” is different from “where is it after steps?” For a finite chain with absorbing or target states, define
Then set . If another state cannot reach , set . For every other state, use first-step analysis:
These simultaneous linear equations produce the eventual hitting probabilities. A matrix power answers a fixed-time question; it does not by itself answer an “ever” question.
Long-run probabilities
A stationary distribution is a probability vector satisfying
When a finite chain is irreducible and aperiodic, the distribution often converges to this stationary distribution regardless of the initial state. This describes long-run behavior, not necessarily the probability at a particular finite time.
For the weather example, write . Solving gives
so . The stationary distribution is therefore : in the long run, about two-thirds of days are sunny and one-third rainy.
Common mistakes
- Reversing the matrix convention. With row vectors, use . With column vectors, the formula becomes , but the matrix entries must be arranged consistently.
- Using a single transition probability for multiple steps. The probability of rain tomorrow is not generally the probability of rain two days from now. Use or sum over the possible intermediate states.
- Multiplying all possible paths when asking for a final state. Multiply along each path, then add the probabilities of all paths ending in the target state.
- Confusing stationary and finite-time probabilities. A stationary distribution describes equilibrium behavior; it is not automatically the distribution after one or two steps.
- Ignoring the initial distribution. The same transition matrix can give different answers depending on where the chain starts.
References
- Markov Chains, J. R. Norris
- Introduction to Probability Models, Sheldon M. Ross
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.