Stationary Distributions
The long-run share of time a Markov chain spends in each state. Start it anywhere and the visit fractions settle onto one fixed vector.
Why Does This Exist?
A Markov chain tells you where you go next, but most questions about it are long-run questions. What fraction of customers sit in each subscription tier after a year of monthly switching? What share of page views lands on each article when readers keep clicking related links? The one-step matrix answers neither directly. The stationary distribution does: it is the row vector that the transition matrix leaves unchanged, .
When it exists and the chain forgets its start, every initial distribution flows toward it. That is why MCMC works: Markov chain Monte Carlo designs a chain whose stationary distribution is the posterior you want, then reads samples off the chain instead of computing the posterior in closed form.
The one idea you need first
A transition matrix has rows that sum to 1. Entry is the probability of moving from state to state in one step. A distribution is a row vector of nonnegative numbers summing to 1. Multiplying advances the distribution one step. Stationarity means the advance changes nothing. The full treatment of chains is in Markov chains.
Think of It Like This
Two rooms and a restless crowd
A museum has two rooms, A and B. Every minute, 20 percent of the people in A wander into B, and 30 percent of the people in B wander into A. Nobody enters or leaves the building.
Early on the split swings around, because it depends on where the crowd started. But there is exactly one split that reproduces itself: if 60 percent are in A, then A loses of the crowd and gains back from B. Equal flows, frozen split. Start anywhere and the rooms drift to 60/40 and stay there.
Where the analogy stops: real chains can have structure that blocks settling, like a strict two-step cycle or a trap state you never leave. Settling needs the chain to be able to revisit states flexibly, which is what ergodicity pins down.
How It Actually Works
Stationarity is the global balance condition. For every state :
In words: the long-run share of visits to equals the share arriving from all states, including itself. Plus the normalization . For a finite chain these linear equations plus normalization determine whenever the chain has one closed communicating class.
Worked example
Two states, A and B. From A you stay with probability 0.8 and move to B with 0.2. From B you move to A with 0.3 and stay with 0.7:
Write and impose with . The first balance equation gives , so , meaning . With the sum constraint, and . Check: . It reproduces itself.
Watch it converge. Start everyone in A, . Then , , . The gap to halves each step, because the second eigenvalue here is .
Code
Repeated multiplication is the whole algorithm. This runs power iteration from a cold start and checks the fixed point, which is also the convergence test people use on large chains.
import numpy as np
P = np.array([[0.8, 0.2], [0.3, 0.7]]) # rows sum to 1pi = np.array([1.0, 0.0]) # cold start: everyone in Afor _ in range(20): pi = pi @ P # advance one stepprint(np.round(pi, 4)) # -> [0.6 0.4]print(np.allclose(pi @ P, pi)) # -> TrueTwenty steps is overkill on purpose: the error shrinks by a factor of 0.5 per step, so after 20 steps it sits near . On a chain with thousands of states you stop when pi @ P and pi agree to your tolerance, not after a fixed count.
Watch Out For
Assuming every chain has exactly one
A chain with two disconnected halves has infinitely many stationary distributions, one per weighting of the halves. A chain with an absorbing state plus a transient state has concentrated on the absorber, and the transient share is zero no matter how interesting the transient looks. Before solving, check the chain has a single closed class. If your solver returns something that puts zero mass where you expected traffic, the chain structure is usually the explanation, not the solver.
Reading a finite-horizon histogram as the stationary vector
After 50 steps from a cold start, the visit fractions still carry the start. The gap decays like where is the second-largest eigenvalue magnitude, so a chain with needs thousands of steps, not dozens. Discard a burn-in and compare the first and second halves of the run. If they disagree, you have not converged.
The Quick Version
- A stationary distribution satisfies : advancing one step changes nothing.
- It is the long-run share of visits per state, found from the balance equations plus normalization.
- In the worked chain with flip rates 0.2 and 0.3, it is , and a cold start halves its gap each step.
- MCMC works by building a chain whose stationary distribution is the target posterior.
- Uniqueness needs one closed communicating class; periodic or disconnected chains break it.
- Convergence speed is set by the second eigenvalue, so always discard a burn-in.