Two-State Markov Chain Calculator (Stationary Distribution, n-Step Probability & λ₂)

Solve πP = π for steady-state probabilities (π₁, π₂) and n-step transition probabilities.

Stationary Probability of State 1 (π₁) 70 %
Stationary Probability of State 2 (π₂) 30 %
n-Step Probability P(X_5=1 | X_0=1) 70.938 %
Second Eigenvalue Convergence Rate (λ₂) 0.5 λ₂
Inputs
Try:
p(1→2)
Transition probability α from State 1 to State 2 per step (0.01 to 0.99).
p(2→1)
Transition probability β from State 2 to State 1 per step (0.01 to 0.99).
steps
Number of steps n to project P^n.
Results & Graph
Stationary Probability of State 1 (π₁)
70 %
Stationary Probability of State 2 (π₂)
30 %
n-Step Probability P(X_5=1 | X_0=1)
70.938 %
Second Eigenvalue Convergence Rate (λ₂)
0.5 λ₂

Stationary Probability of State 1 (π₁)

Graph 1 • How the inputs feed Markov Stationary Distribution
2-State Markov Chain Stationary Distribution (π₁, π₂) & Mixing Time Calculator • Custom Domain Schematic (Game Theory, Ratings & Stochastic Processes) transititransitiMarkov Stationary Dist Transition Prob1 To2 Alpha: 0.150 p(1→2) • Transition Prob2 To1 Beta: 0.350 p(2→1) STATIONARY PROBABILITY OF 70 % • Stationary Probability: 30 % • n-Step Probability P(X: 70.938 % Eq: π₁ = p_{2→1} / (p_{1→2} + p_{2→1
Graph 2 • Stationary Probability of State 1 (π₁) as Transition Prob1 To2 Alpha changes (40% to 160% of current)
0 % 46.95 % 93.90 % 85.37 0.0600 79.55 0.0900 74.47 0.120 70 0.150 66.04 0.180 62.50 0.210 59.32 0.240
Graph 3 • Transition Prob1 To2 Alpha and Transition Prob2 To1 Beta together Compares Stationary Probability of State 1 (π₁) when Transition Prob2 To1 Beta is shifted +25% (solid) vs. −25% (dashed).
0 % 44.35 % 88.71 % --- Transition Prob2 To1 Beta @ 75% 80.64 -30% 77.43 -15% 74.47 +0% 71.72 +15% 69.17 +30%
Summary: Long-run stationary distribution is π₁ = 70% and π₂ = 30% (mean return times 1.43 and 3.33 steps; P₁₁(5) = 70.94%).
Summary: Long-run stationary distribution is π₁ = 70% and π₂ = 30% (mean return times 1.43 and 3.33 steps; P₁₁(5) = 70.94%).
Interactive chart & math engine powered by CalculatorGraph

Formula: Markov Stationary Distribution Formula

π₁ = p2→1 / (p1→2 + p2→1)
π₂ = p1→2 / (p1→2 + p2→1)
λ₂ = 1 − p1→2 − p2→1
π₁ = p_{2→1} / (p_{1→2} + p_{2→1}); π₂ = p_{1→2} / (p_{1→2} + p_{2→1}); λ₂ = 1 − p_{1→2} − p_{2→1}
  • transitionProb1To2Alpha: Transition Prob1 To2 Alpha (p(1→2))
  • transitionProb2To1Beta: Transition Prob2 To1 Beta (p(2→1))
  • stepsToProjectN: Steps To Project N (steps)

Frequently Asked Questions

How does the 2-State Markov Chain Stationary Distribution (π₁, π₂) & Mixing Time Calculator compute the solution?

It evaluates π₁ = p_{2→1} / (p_{1→2} + p_{2→1}); π₂ = p_{1→2} / (p_{1→2} + p_{2→1}); λ₂ = 1 − p_{1→2} − p_{2→1} directly in your browser and updates three custom SVG visualizations in real time.

Which formula gives π₁, and why is beta on top?

π₁ = beta / (alpha + beta), where alpha is the chance of leaving state 1 and beta the chance of returning to it. Beta is on top because returning more often raises the share of time in state 1. With the defaults, 0.35 / (0.15 + 0.35) = 0.7, which is the 70% headline.

Does the starting state affect the long-run answer?

No. For any chain with both probabilities above 0 and alpha + beta below 2, the stationary distribution is the same whatever state you start in. The start only affects the early steps. The n-step line shows this from state 1: P₁₁(5) is 70.938%, already within one point of the 70% limit.

What is the difference between return time and visit length?

Return time, 1 / π, is the average number of steps from one visit to the next, shown as 1.43 and 3.33 steps for the defaults. Visit length is how long you stay once you arrive, 1 / alpha for state 1 and 1 / beta for state 2, about 6.67 and 2.86 steps. The page shows only the first.

How many steps until the chain has settled?

The gap from the stationary value shrinks by a factor of |λ₂| every step. With the default λ₂ of 0.5, five steps cut the gap to about 3% of its starting size. With λ₂ = 0.95 it takes around 72 steps to get within a percentage point. There is no single mixing time; it depends on how close you need to be.

Why is λ₂ equal to 1 − alpha − beta?

A transition matrix always has one eigenvalue equal to 1, belonging to the stationary distribution. For a two-state matrix the eigenvalues add up to the trace, (1 − alpha) + (1 − beta). Subtracting 1 leaves 1 − alpha − beta. With the defaults that is 1 − 0.15 − 0.35 = 0.5.

Can I use this for a chain with three states?

No. The formulas here only work for two states. With three or more you need to solve πP = π with the full matrix, usually by linear algebra or by raising the matrix to a high power. You can sometimes group states into two, but only if switching behaviour is the same within each group.

What happens if I set alpha to zero?

State 1 becomes absorbing: once the chain arrives it never leaves. The page shows π₁ = 100% and P₁₁(5) = 100%, which is correct. Ignore the mean return time of 0 steps it prints for state 2; a state the chain leaves for good has no finite return time. Setting both alpha and beta to 0 is rejected.

Why did the five-step figure come out below the long-run share?

That happens when alpha + beta exceeds one, which makes λ₂ negative. The chain overshoots and oscillates around the stationary value. With alpha = 0.9 and beta = 0.8, λ₂ is −0.7 and P₁₁(5) is 38.161% against a long-run 47.059%. Try an even number of steps and it lands above.

How do the comparison scenarios relate to each other?

They keep beta at 0.35 and change alpha. At 0.09 the chain leaves state 1 less often, so π₁ rises to 79.546% and λ₂ to 0.56. At 0.22 it leaves more often, π₁ falls to 61.404% and λ₂ drops to 0.43, so that chain also settles a little faster than the default.

Does the step length matter?

The long-run percentages do not depend on what a step represents, but the probabilities do. A chance of 0.15 per day is very different from 0.15 per hour. Make sure alpha, beta and the steps-to-project box all refer to the same time unit, or the n-step projection will be wrong.

What does a long-run probability of 70% mean in practice?

It means that over a long run of steps, the chain spends about 70% of them in state 1, and that if you look at it at a random moment far from the start, there is a 70% chance it is in state 1. It does not mean the chain will be in state 1 on any particular step, which still depends on where it was just before.

Two numbers describe the whole chain

A two-state Markov chain needs only two inputs. Alpha is the probability of moving from state 1 to state 2 on any one step. Beta is the probability of moving from state 2 back to state 1. Staying put is whatever is left: 1 − alpha in state 1, 1 − beta in state 2. The defaults are alpha = 0.15 and beta = 0.35.

Those two numbers fill the transition matrix. Row one is (0.85, 0.15) and row two is (0.35, 0.65). Each row must add up to one, which is why the calculator asks for only the switching probabilities and works out the staying probabilities itself.

Think of state 1 as a machine running and state 2 as it being down, or a customer being active and lapsed, or a dry day and a wet day. What matters is that the probability of the next move depends only on where you are now, not on how you got there. If yesterday's history changes today's odds, the chain is not Markov, and the long-run figures here will not describe your system.

The steps box only changes one line of the result, the n-step probability. The long-run percentages, return times and λ₂ do not depend on it at all. Set it to 1 and the n-step line simply shows 1 − alpha, which is 85% with the defaults; set it to 20 and it shows 70%, the stationary value, because the starting point has been forgotten.

Checking 70% and 30% by hand

The headline result is π₁ = 70%, with π₂ = 30% on the next line. These are the long-run shares of time spent in each state.

The reasoning takes one line. In the long run the flow out of state 1 must equal the flow into it. Flow out is π₁ × alpha and flow in is π₂ × beta. So π₁ × 0.15 = π₂ × 0.35, and with π₁ + π₂ = 1 that gives π₁ = beta / (alpha + beta) = 0.35 / 0.5 = 0.7.

A handy way to remember which probability goes on top: π₁ is large when beta is large, because a high beta pulls the chain back into state 1 quickly. It is also large when alpha is small, because the chain rarely leaves. The ratio π₁ / π₂ is simply beta / alpha, here 0.35 / 0.15, or about 2.33.

You can check the answer against the matrix directly. Multiply the row vector (0.7, 0.3) by the transition matrix. The first entry is 0.7 × 0.85 + 0.3 × 0.35 = 0.7, and the second is 0.7 × 0.15 + 0.3 × 0.65 = 0.3. The distribution does not change from one step to the next, which is what stationary means.

Return times and how long each visit lasts

The interpretation line gives mean return times of 1.43 steps for state 1 and 3.33 steps for state 2. These are 1 / π₁ and 1 / π₂: the average number of steps between successive visits to a state, counting from one visit to the next.

A different and often more practical figure is how long a visit lasts once it starts. Each step in state 1 has a 0.15 chance of ending the visit, so the average stay is 1 / 0.15, about 6.67 steps. A stay in state 2 averages 1 / 0.35, about 2.86 steps. The page does not print these, but they follow directly from the inputs.

The two views agree. A visit to state 1 lasts about 2.33 times as long as a visit to state 2, and the chain alternates between them, so it spends 2.33 times as much time in state 1. That is the same 70 to 30 split.

If your steps are days, the default chain describes a system that stays in state 1 for about a week at a time, drops into state 2 for about three days, and then comes back.

What λ₂ = 0.5 says about speed

The second eigenvalue of a two-state chain is λ₂ = 1 − alpha − beta. With the defaults that is 0.5. It controls how fast the chain forgets where it started.

The exact n-step formula for staying in state 1 is P₁₁(n) = π₁ + π₂ × λ₂ⁿ. The page uses it for the n-step line. With five steps, 0.5⁵ = 0.03125, so P₁₁(5) = 0.7 + 0.3 × 0.03125 = 70.938%. The gap from the long-run 70% has shrunk to less than one percentage point.

Starting from state 2 instead, the probability of being in state 1 after n steps is π₁ − π₁ × λ₂ⁿ. After five steps that is 0.7 − 0.7 × 0.03125, about 67.8%. The page only reports the state 1 start, but the formula for the other one is just as short.

Each step multiplies the remaining gap by λ₂. With λ₂ = 0.5 the gap halves every step. That is fast. Change the inputs to alpha = 0.02 and beta = 0.03 and the long-run split is 60% and 40%, but λ₂ = 0.95, and after ten steps P₁₁ is still 83.95%. Getting within one percentage point of 60% takes about 72 steps. Small switching probabilities mean a slow chain, even when the long-run answer looks ordinary.

When λ₂ turns negative

If alpha + beta is greater than one, λ₂ is negative and the chain overshoots. With alpha = 0.9 and beta = 0.8, λ₂ = −0.7. The long-run split is 47.059% in state 1 and 52.941% in state 2, but the path to it zigzags.

Starting in state 1, the chain almost certainly jumps to state 2 on the next step, then almost certainly jumps back. The n-step probability swings above and below the stationary value. After five steps the page shows 38.161%, below the long-run 47.059%, and after six it would be above it.

The size of λ₂ still sets the speed of convergence; only the sign changes the pattern. A chain like this describes a system that tends to alternate, such as a two-shift rota or a market that reverses after each move.

So when you read the n-step figure, check the sign of λ₂ first. A positive λ₂ means steady approach from one side. A negative one means the projection for one particular n may be misleading because the next step would land on the other side.

Absorbing and flip-flop chains at the edges

Both probabilities can be anywhere from 0 to 1, as long as they are not both 0. A chain where neither state can be left never mixes at all, so the page rejects that input. The steps box needs a whole number of 1 or more.

Enter alpha = 0 to model a state 1 that is never left, an absorbing state. The page reports π₁ = 100% and P₁₁(5) = 100%, which is right: once in state 1 the chain stays there. The interpretation line then gives a mean return time of 0 steps for state 2, which should be read as undefined. A state the chain eventually leaves for good has no finite return time.

Enter alpha = 1 and beta = 1 for a chain that flips every step. λ₂ is −1, and P₁₁(5) is exactly 0, because after an odd number of steps you are always in state 2. The 50% and 50% long-run split is still the share of time spent in each state, but the chain never settles, so there is no limit for the n-step figure to approach.

So use the edge values knowingly. They are valid inputs, but the stationary distribution means something slightly different for an absorbing or periodic chain than for an ordinary one.

Estimating alpha and beta from real data

Most people arrive with a sequence of observations rather than probabilities. Count how many steps you observed in state 1 and how many of those were followed by a move to state 2. Alpha is the second count divided by the first. Do the same for state 2 to get beta.

Keep the step length consistent. If you estimate daily switching probabilities, the n-step line is in days. Mixing weekly and daily observations in the same count will give a meaningless alpha.

Small samples give rough estimates, and the stationary distribution is sensitive to them when alpha and beta are small. The page's own comparison runs show this. Moving alpha from 0.15 to 0.09 lifts π₁ from 70% to 79.546%, and moving it up to 0.22 drops π₁ to 61.404%. A difference of a few switches in your data can move the long-run share by ten points.

Finally, check that the probabilities stay roughly constant over the period you observed. A chain whose switching rates change with the season, or with how long it has been in a state, needs a richer model than two fixed numbers.

A quick check on your estimates is to compare the stationary share with what you actually observed. If your records show the system in state 1 about seven tenths of the time and the page gives π₁ = 70%, the two agree. A large mismatch usually means the record is too short, the chain was not near steady state when you started observing, or the probabilities are not constant.