How to use the markov chain calculator
- Type the transition matrix, one row per line. Row i holds the chances of moving from state i to each state, and each row adds up to 1. Decimals and fractions such as 1/3 work.
- Add state names if you like, in the same order as the rows.
- Set the starting state number and the number of steps to see the distribution after that many steps and the matrix raised to that power.
- Read the long-run distribution and compare it with the step table. The distance row shows how close you already are.
Formula
distribution after n steps = starting distribution x P^n
long-run distribution pi: pi P = pi and the shares add up to 1
distance = half the sum of |p(n) - pi|
The long-run distribution is found by solving the equations directly, not by repeating the multiplication. It is unique when the chain has exactly one closed group of states. If that group cycles, the shares are time averages, and the distribution after n steps keeps rotating instead of settling.
Sunny, cloudy and rainy
The default matrix has rows 0.7, 0.2, 0.1 (sunny), 0.3, 0.5, 0.2 (cloudy) and 0.2, 0.3, 0.5 (rainy). Solving gives long-run shares of 0.4634 sunny, 0.3171 cloudy and 0.2195 rainy, which are 46.341%, 31.707% and 21.951%.
Starting from sunny, after 5 steps the distribution is 0.47367, 0.31307 and 0.21326, only 0.010255 away from the long-run shares in total variation. Raising the matrix to the power 1000 gives rows equal to the long-run shares in every digit shown.
Reading the answers
The long-run share of a state is the fraction of time the chain spends there if it runs for a very long time. In a chain that forgets its past, it is also the chance of being in that state far in the future, whatever the start. The step table shows the chance of each state exactly n steps from the start, and the matrix power shows the same for every possible start.
The page also reports closed groups, absorbing states and the period of the chain. An absorbing state is one that, once entered, is never left. If there are two or more closed groups, where the chain ends depends on where it starts, so no single steady state exists, and the page says so instead of inventing one.
Cycles and transient states
A chain that moves A to B to A forever has period 2. It spends half its time in each state, but the distribution after n steps alternates. States that the chain can leave and never return to are transient and have a long-run share of 0. For general matrix work, the Matrix Calculator handles products and inverses, and the Probability Calculator covers single events.
More probability and statistics tools
To work with other chance models and data, try the Cronbach's Alpha Calculator, Curve Fit Calculator and Odds Ratio and Relative Risk Calculator.
Assumptions and limits
- The next state depends only on the current state, and the probabilities never change.
- Each row of the matrix adds up to 1 within a small rounding tolerance.
- Up to 12 states are supported, and up to 100,000 steps.
- Probabilities are used as typed. Rounded decimals can make a row add up to slightly less or more than 1.
Frequently asked questions
What is a steady state?
It is a distribution that does not change from one step to the next: multiplying it by the transition matrix gives the same distribution back.
Why does the page say the steady state is not unique?
The chain has more than one closed group of states, such as two absorbing states. Each group has its own steady state, and the final answer depends on the starting state.
Why do the step results keep alternating?
The closed group of states cycles with a period above 1, so the chain moves in a repeating pattern instead of mixing. The long-run shares are still correct as time averages.
Can I enter percentages?
Enter probabilities between 0 and 1, or fractions such as 1/4. Convert percentages by dividing by 100 so that each row adds up to 1.