Will tomorrow be sunny if today is rainy? Will a customer be active next month? A Markov chain answers such questions with a simple rule: the chance of the next state depends only on the present one. This calculator handles the two-state case. From the chance of switching from A to B and from B to A it gives the long-run share of time in each state, the probability after n steps, the speed of convergence and the mean return time.
How the calculation works
With switching probabilities p (A to B) and q (B to A):
- Steady state: share in A = q ÷ (p + q); share in B = p ÷ (p + q)
- After n steps: P(A) = steady share + (start − steady share) × (1 − p − q)ⁿ
- Second eigenvalue = 1 − p − q, the factor by which the gap closes each step
- Mean return time to A = 1 ÷ steady share of A
- Mean time before leaving A = 1 ÷ p
Example
A system starts in state A (100 %) and moves A to B with probability 0.3 and B to A with probability 0.1 at each step. The long-run shares are 25 % in A and 75 % in B. After 5 steps the probability of being in A is 0.25 + 0.75 × 0.6⁵ = 30.83 %. The convergence factor is 0.6, and it takes 9 steps to come within 1 % of the long-run share. It returns to A every 4 steps on average, and stays in A for 3.33 steps before leaving.
Why it matters
Markov chains are the base of weather models, queueing theory, page ranking, customer retention and many simulation methods. The two-state case shows the ideas without matrices: the steady state, the speed at which the start is forgotten and the average time spent in each state. These give quick answers to planning questions such as how many machines will be down on an average day.
Good to know
The chain must be able to move between the two states (both probabilities above zero) for a steady state to exist. If p + q = 1, the chain forgets its start after a single step, and if p + q is close to 2 it flips back and forth. The model has no memory, so a streak of rainy days is not captured. This tool is for education.
In practice
Estimate p and q from data: p is the number of A-to-B moves divided by the number of times the system was in A, and q the same for B. Compare the steady shares with the observed shares to see whether the Markov assumption holds.
Related tools
The queue wait time calculator, the probability calculator and the expected value calculator cover related ideas.