Absorbing Markov Chain Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

What is an absorbing Markov chain?

An absorbing Markov chain is a stochastic (random) process that moves between a finite set of states from one step to the next. At least one of these states is absorbing, meaning that once the process enters it, it stays there forever. All other states are called transient: starting from a transient state, there is a nonzero probability that the process will eventually be absorbed.

This calculator helps you analyze such chains from their transition matrix. Given a matrix of step-by-step transition probabilities and a list of absorbing states, it computes:

  • The fundamental matrix of the transient states.
  • The expected number of steps until absorption from each transient state.
  • The probability of being absorbed in each absorbing state, starting from any transient state.

The tool is limited to a 5×5 transition matrix, but the underlying method is the standard absorbing Markov chain theory used in probability, statistics, and stochastic modeling.

How the transition matrix is used

Suppose you have n states labeled 0, 1, …, n − 1. The transition matrix P is an n×n matrix where entry P[i,j] is the probability of moving from state i to state j in one step. Each row represents a probability distribution, so each row must sum to 1 (within numerical rounding).

For an absorbing Markov chain, we can conceptually reorder the states so that all transient states come first and all absorbing states come last. In that ordering, the transition matrix can be written in block form as:

P = Q R 0 I

Here:

  • Q is the submatrix of probabilities for transitions from transient states to transient states.
  • R is the submatrix of probabilities for transitions from transient states to absorbing states.
  • I is an identity matrix representing that once you are in an absorbing state you stay there with probability 1.

Fundamental matrix, absorption probabilities, and expected steps

The key object for analysis is the fundamental matrix N, defined by

N = ( I Q ) 1

Interpreting N:

  • Entry N[i,j] is the expected number of visits to transient state j if the chain starts in transient state i, before absorption.
  • The row sums of N give the expected number of steps until absorption from each transient state.

Once N is known, we can compute the matrix of absorption probabilities

B = N R

In B, entry B[i,k] is the probability that, starting from transient state i, the chain will eventually be absorbed in absorbing state k. Each row of B represents a full probability distribution over absorbing states, conditional on the starting transient state.

How to use this calculator

  1. Enter the transition matrix: Fill in the 5×5 grid so that each row represents probabilities from a given state to all states 0–4. Each row should sum to 1 (within rounding).
  2. Specify absorbing states: In the "Absorbing states" field, list the indices of all absorbing states, separated by commas, for example 0,3,4. Each absorbing state should have probability 1 of transitioning to itself and 0 to all other states in its row.
  3. Run the calculation: Submit the form. The calculator identifies transient vs absorbing states based on your list and extracts the Q and R submatrices internally.
  4. Review the results:
    • Fundamental matrix N: shows expected visits to each transient state.
    • Expected steps to absorption: one value per transient state (row sums of N).
    • Absorption probabilities: a matrix where each row corresponds to a starting transient state and each column to an absorbing state.

If you leave the absorbing-states field blank, the tool treats that as resetting your selection. To get meaningful output, you must specify at least one absorbing state and at least one transient state.

Worked example

Consider a simple 3-state system (we embed it in the 5×5 matrix by leaving unused rows/columns in their default form). Suppose:

  • State 0: transient
  • State 1: transient
  • State 2: absorbing
  • States 3 and 4: unused in this example

Use the following nonzero entries in the top-left 3×3 block:

  • P(0 → 0) = 0.2, P(0 → 1) = 0.5, P(0 → 2) = 0.3
  • P(1 → 0) = 0.1, P(1 → 1) = 0.4, P(1 → 2) = 0.5
  • P(2 → 2) = 1.0 (absorbing), with all other transitions from 2 equal to 0

Set the absorbing-states field to 2. The calculator will treat 0 and 1 as transient, and 2 as absorbing. Internally, the Q and R matrices are:

  • Q = [[0.2, 0.5], [0.1, 0.4]] (transient → transient)
  • R = [[0.3], [0.5]] (transient → absorbing)

The calculator inverts I − Q to get N, then computes B = N R. The output will tell you, for example:

  • The expected number of steps until absorption if you start in state 0.
  • The probability that you eventually end in state 2 (the only absorbing state) starting from state 1, which should be 1 in this setup.

By adjusting the matrix, you can model scenarios such as random walks with absorbing boundaries, customer life cycles with "churned" or "retained" absorbing states, or reliability systems where failure is absorbing.

Interpreting the results

Once you have run the calculator, use the outputs as follows:

  • Fundamental matrix N: Larger values along a row indicate states that the process is likely to visit often before being absorbed. If N[i,i] is large, the process tends to spend many steps in state i when starting from that same state.
  • Expected steps to absorption: If a transient state has a very large expected time to absorption, the process is "sticky" and tends to wander for many steps before absorption. Small values indicate rapid absorption.
  • Absorption probabilities: Each row sums to 1 and shows how likely each absorbing outcome is. For example, in a model with absorbing states "success" and "failure", the calculator directly gives the probability of eventually succeeding vs failing from each starting state.

Summary comparison of key quantities

Quantity Matrix symbol What it represents
Transition matrix P Full step-by-step transition probabilities between all states in the chain.
Transient-to-transient block Q Probabilities of moving among transient states before absorption.
Transient-to-absorbing block R Probabilities of jumping from transient states directly into absorbing states.
Fundamental matrix N = (I − Q)−1 Expected number of visits to each transient state, starting from each transient state.
Absorption probabilities B = N R Probability of ending in each absorbing state, given the starting transient state.
Expected steps to absorption Row sums of N Expected number of transitions until some absorbing state is reached.

Assumptions and limitations of this calculator

  • Matrix size: The interface supports a 5×5 transition matrix. Larger chains must be approximated or analyzed elsewhere.
  • Stochastic rows: Each row of the transition matrix should sum to 1 within numerical tolerance. Rows that do not sum to 1 break the Markov property and can lead to misleading results.
  • At least one absorbing state: You must specify at least one absorbing state. Without absorbing states, the fundamental matrix is not defined.
  • At least one transient state: There must be at least one transient state. If all states are absorbing, the chain is already absorbed and the expected time to absorption is zero everywhere.
  • Reordering of states: Internally, results are based on separating transient and absorbing states. Pay attention to how the calculator labels rows and columns in the output so you interpret them with the correct state ordering.
  • Numerical stability: When I − Q is nearly singular (for example, if the chain almost never leaves certain regions), numerical inversion may be unstable. Very large entries in N or extremely large expected times may reflect this sensitivity.
  • Modeling assumptions: The Markov assumption means that only the current state matters for the next step, not the full history. If your real system has memory or time-varying transition probabilities, this model is an approximation.

Within these constraints, the calculator provides a quick way to explore absorbing Markov chains, understand expected times to certain outcomes, and compare different configurations of transition probabilities.

Transition probabilities

Enter a 5×5 transition matrix where each row sums to 1:

Transition probabilities from each state to every other state
From → / To ↓ 0 1 2 3 4
0
1
2
3
4
Absorbing state selection
Enter a transition matrix and mark absorbing states to view results.

Understanding Absorbing Markov Chains

A Markov chain is a stochastic process that hops between states with probabilities that depend only on the current state. Among the many varieties of Markov chains, absorbing chains occupy a special place. An absorbing chain contains at least one state that, once entered, cannot be left. These states are called absorbing states. Formally, a state i is absorbing if P ii = 1 , where P denotes the transition matrix. All other states are called transient because the chain will eventually leave them.

To analyze an absorbing chain, we reorder the states so that all absorbing states come last. The transition matrix then takes a canonical block form:

Q R 0 I

Here, Q is a square matrix describing transitions among transient states, R gives probabilities of moving from transient to absorbing states, and I is an identity matrix corresponding to staying in an absorbing state once reached. The zero block indicates that absorbing states have no transitions back to transient states.

The fundamental matrix of an absorbing chain is defined as N = I - Q 1 . Each entry n ij of N gives the expected number of times the chain visits transient state j starting from transient state i . Summing a row of N yields the expected number of steps before absorption when starting from that transient state. Multiplying N by R yields a matrix B = N R whose entries b ij give the probability of absorption in absorbing state j given that the chain starts in transient state i .

The calculations this calculator performs mirror standard textbook treatments. After you input the transition matrix and specify which states are absorbing, the script rearranges the matrix into the Q R form, inverts I - Q , and computes expected step counts and absorption probabilities. All computations occur client‑side using plain JavaScript, making the tool self‑contained and suitable for offline use.

Example Calculation

Consider a simple board game in which a token moves along four squares and then reaches an absorbing finish. At each step the token either advances or stays put, depending on a die roll. We can model this with the following transition matrix:

0.5 0.5 0 0 0 0 0.5 0.5 0 0 0 0 0.5 0.5 0 0 0 0 0.5 0.5 0 0 0 0 1

State 4 is absorbing. The corresponding Q matrix consists of the top‑left 4×4 block, while R is a 4×1 column vector giving the probabilities of transitioning to state 4. Calculating N and B yields insight into how long the game lasts and the likelihood of finishing, though in this simple example absorption is certain.

Transient State Expected Steps to Absorption
0 8
1 6
2 4
3 2

The table illustrates a pattern: the further the starting state is from the absorbing state, the more steps the process expects to take. These numbers correspond to the row sums of the fundamental matrix. In general, if the transition probabilities vary, the expected times can exhibit non‑linear behavior, emphasizing the importance of computational tools.

Derivation of the Fundamental Matrix

The derivation of N begins with the series expansion of I - Q :

N = I + Q + Q 2 + Q 3 +

Each term Q k gives the probabilities of transitioning between transient states in exactly k steps without absorption. Summing this infinite geometric series yields N = I - Q 1 , provided the spectral radius of Q is less than one—a condition guaranteed for absorbing chains. This representation connects probabilistic intuition with linear algebra.

Once N is known, other quantities follow. The expected number of steps before absorption starting from transient state i is t i = j n ij . Writing this in vector form with \mathbf{1} as a column of ones gives t = N \mathbf{1} . The matrix of absorption probabilities is B = N R , as noted earlier. These formulas make computation straightforward once we have routines for matrix multiplication and inversion.

Working with the Calculator

To use this tool, fill in the 5×5 transition matrix with probabilities. Each row should sum to one, reflecting total probability. Then list the indices of absorbing states separated by commas. When you click the button, the script extracts the sets of transient and absorbing states, forms matrices Q and R , and computes N , the expected steps vector, and the absorption probability matrix. Results are displayed in tables: one for expected steps and another for absorption probabilities.

The calculator handles up to five states for readability, but the underlying mathematics extends to larger systems. For large matrices, numerical issues such as rounding errors can arise during inversion. Our implementation uses a Gauss–Jordan elimination routine with a tolerance for tiny pivots, sufficient for educational use. In professional settings, numerical libraries with enhanced stability are recommended.

Applications and Interpretation

Absorbing Markov chains model a wide range of phenomena. In ecology, they describe the progression of an organism through life stages culminating in death. In finance, certain credit rating models allow default as an absorbing state. In board games like Monopoly, landing in jail can be treated as an absorbing state for some analyses. By computing expected times and absorption probabilities, analysts can quantify how long processes persist and which terminal states are most likely.

For example, consider a customer churn model where customers transition among loyalty levels before eventually leaving. States representing active customers are transient, while a “churned” state is absorbing. The fundamental matrix then reveals the expected lifetime of a customer and the probability of eventual churn from each starting level. Such insights inform marketing strategies and resource allocation.

Another application appears in reliability engineering. Components may pass through stages of wear before failure; failure is absorbing. By modeling transitions based on observed data, engineers estimate expected lifetimes and the distribution of failure modes. Similarly, in health care, disease progression can be modeled as an absorbing chain where recovery or death are absorbing states. The expected time in each health state and the probabilities of each outcome aid treatment planning.

While absorbing chains eventually terminate, the path to absorption can be complex. Some chains exhibit almost‑absorbing behavior where the expected number of steps is large despite certain absorption. The fundamental matrix captures this by summing over all possible visits to transient states. If the spectral radius of Q is close to one, the entries of N grow large, indicating prolonged wandering before absorption.

Interpreting the absorption probability matrix B requires attention. Rows correspond to starting transient states and columns to absorbing states. Each row sums to one, reflecting the certainty of eventual absorption somewhere. Disparities among columns reveal which absorbing states dominate given a starting point. If certain absorbing states are undesirable—say, system failure versus successful completion—these probabilities guide interventions aimed at steering the process.

Behind the Scenes

The JavaScript code constructs matrices as arrays of arrays. To invert I - Q , it augments the matrix with the identity and performs Gauss–Jordan elimination. Matrix multiplication routines carry out the necessary products for N , t , and B . All calculations are performed in double‑precision floating point, which suffices for most educational examples.

To ensure robustness, the code includes basic checks: if no absorbing states are provided or if all states are absorbing, the script reports that analysis cannot proceed. Similarly, if the transition matrix is ill‑formed—for example, rows not summing to one—the results may not represent a valid Markov chain. While the script does not enforce row sums exactly, users are encouraged to input proper stochastic matrices.

Experimenting with different matrices reveals interesting behavior. Chains with multiple absorbing states can show strong sensitivity to initial conditions. By observing how absorption probabilities vary with starting state, one gains intuition about the dynamics. The expected steps table highlights which states serve as bottlenecks or traps, where the process lingers.

Ultimately, absorbing Markov chains blend linear algebra with probability, yielding insights applicable across disciplines. This calculator aims to demystify the computations by automating matrix operations and presenting results clearly. The extensive explanation above, complete with MathML formulas and tables, serves as a reference for students and practitioners alike. By engaging with the tool, you can explore how transitions accumulate, how long processes persist, and where they end up. Such understanding is invaluable in fields ranging from economics to epidemiology, demonstrating the broad utility of absorbing Markov chain analysis.

Archiving Matrix Results

Save the computed tables of expected steps and absorption probabilities in your notes or research log. Keeping these matrix snapshots lets you revisit assumptions and compare how changes in transition probabilities alter long-term behavior.

Example absorption outcomes for a chain with two safe and one failure states
Starting state Absorb in state 3 Absorb in state 4 Absorb in state 0
1 (transient) 0.62 0.33 0.05
2 (transient) 0.20 0.70 0.10
3 (absorbing) Already absorbed

Tables like this help you rank starting states by risk. If the "failure" column dominates, consider changing transitions or adding a control policy that nudges the process toward safer absorbing states. Pair the absorption view with the expected steps summary to identify whether riskier states also keep the system occupied longer.

Continue exploring stochastic modeling with the Markov chain steady state tool for long-run behavior, matrix inverse calculator for manual verification of I - Q inversions, and the matrix multiplication helper to practice composing transition powers.

Embed this calculator

Copy and paste the HTML below to add the Absorbing Markov Chain Calculator to your website.