Sitemap

An Introduction to Markov Chains

--

What they are, how they work, and why you’ll see them everywhere from Google search to LLMs to modern marketing analytics

Press enter or click to view image in full size
A Markov chain moves from state to state, and where it goes next depends only on where it is now. The idea is over a century old, and it started with a mathematician counting letters in a Russian novel.
A Markov chain moves from state to state, and where it goes next depends only on where it is now. The idea is over a century old, and it started with a mathematician counting letters in a Russian novel.

Introduction

In 1913, a Russian mathematician named Andrei Markov sat down with a copy of Pushkin’s Eugene Onegin and started counting letters. He went through 20,000 characters and marked each one as either a vowel or a consonant. Then he counted how often a vowel followed a vowel, how often a consonant followed a vowel, and so on.

This was not a literary exercise. Markov was in a public argument with another mathematician, Pavel Nekrasov, about the law of large numbers. Nekrasov had argued that the law only applied to independent events, and he had attached some larger philosophical claims to that idea. Markov wanted to show that dependent events could still settle into stable, predictable patterns. Pushkin’s novel gave him a long sequence of dependent data that anyone could check.

He had published the underlying theory back in 1906. The Pushkin analysis was one of the earliest concrete demonstrations of it, and easily the most memorable. Markov chains have been connected to text almost from the beginning, which turned out to matter a great deal later on.

Press enter or click to view image in full size
Figure 1. A brief history of Markov chains, from Andrei Markov’s 1913 analysis of vowels and consonants in Pushkin’s Eugene Onegin to today’s marketing mix models and language models. The same underlying idea has been reapplied for over a century.
Figure 1. A brief history of Markov chains, from Andrei Markov’s 1913 analysis of vowels and consonants in Pushkin’s Eugene Onegin to today’s marketing mix models and language models. The same underlying idea has been reapplied for over a century.

I wrote recently about Monte Carlo simulation, which is a way of answering questions by generating a lot of random draws. Markov chains are the other half of that story, and they answer a different question: “what comes next?”

This article covers what a Markov chain is, how to read one, what happens when you run it forward, and where it fails. The examples include Google’s original search algorithm, a laundry powder study from 1957, and the math behind marketing attribution.

Every Markov chain is built from two pieces: a set of situations the system can be in, and the odds of moving between them. Start there and the rest follows.

States and Transitions

Simply stated, a Markov chain has two parts.

  • A state is a situation the system can be in at any given moment.
  • A transition is a move from one state to another, and each move has a probability attached to it.

Here is a simple marketing version. Suppose I sort everyone in my database into three groups based on how they behaved this month.

  • Unengaged means no meaningful activity.
  • Engaged means they opened, clicked, or visited but did not buy.
  • Active means they bought something.

Those three groups are my states.

Every month, people move between those groups. Some unengaged people start paying attention. Some engaged people buy. Some active customers go quiet. And a lot of people stay right where they are, which counts as a transition too. Someone who was active last month and active again this month has transitioned from Active to Active.

Press enter or click to view image in full size
Figure 2. A three-state Markov chain for customer engagement. Each arrow carries the probability of that move in a given month, including the loops for staying put. The probabilities leaving any one state add up to 1.
Figure 2. A three-state Markov chain for customer engagement. Each arrow carries the probability of that move in a given month, including the loops for staying put. The probabilities leaving any one state add up to 1.

Those self-referencing arrows matter more than they look. In a lot of business situations, the most likely thing to happen next is nothing. Most of your active customers this month will still be active next month. The chain has to be able to represent that.

Notice that these states describe current behavior rather than permanent history. That is deliberate. Someone who buys and then goes quiet moves from Active back to Unengaged, and someone who has been quiet for a year can become Engaged again next week. Every state stays reachable from every other state, and that property turns out to matter for some of the math later.

The arrows leaving any one state add up to 1, or 100 percent. Look at Unengaged: 85 percent stay, 14 percent become Engaged, and 1 percent go straight to Active. That has to be true, because everyone in a state ends up somewhere next month, and staying put counts.

This diagram is the reference example for the first half of the article. I will come back to it several times, and each time we will ask it a different question.

Three Examples of Markov Chains

Before we go further, I want to show that this pattern is not specific to marketing. Here are three examples of Markov chains that have nothing to do with each other: tomorrow’s weather, a children’s board game, and a shopper making up their mind.

Weather. If it is sunny today, there is some probability it will be sunny tomorrow and some probability it will rain. If it is raining today, the probabilities are different. Two states, four transitions, and you have a rough weather model. This is the example most textbooks open with because it takes about ten seconds to understand.

A board game. In Chutes and Ladders, your next square depends on where your token is right now and what the spinner does. It does not depend on how you got to your current square. A player who arrived at square 40 by climbing three ladders faces exactly the same odds as a player who crawled there one turn at a time.

A customer journey. Someone becomes aware of your product, then considers it, then buys it or drops out. Those stages are states. The rates at which people move between them are transition probabilities. Most marketers have drawn this on a whiteboard without knowing it had a name.

Press enter or click to view image in full size
Figure 3. Three examples of Markov chains. Weather, board games, and customer journeys all share the same structure: a set of situations you can be in, and probabilities that move you between them.
Figure 3. Three examples of Markov chains. Weather, board games, and customer journeys all share the same structure: a set of situations you can be in, and probabilities that move you between them.

These three examples look different, but they share the same underlying shape. There is a set of situations you can be in, and there are probabilities that move you between them. That shape is what a Markov chain describes. The board game is the one to remember, because it demonstrates the single rule that makes all of this work: only the present matters.

The Markov Property: Only the Present Matters

A Markov chain has one defining rule. Where you go next depends only on where you are right now. The path you took to get here does not enter into it.

That is the Markov property. You will also see it called the memoryless property, and the two terms mean the same thing. The chain has no memory of its own history. It only knows its current position.

The board game example makes this feel obvious. Nobody thinks their next spin depends on which squares they visited twenty minutes ago. The token is where it is, the spinner does what it does, and the past is irrelevant to the next move.

Press enter or click to view image in full size
Figure 4. The Markov property in one picture. Two customers took very different routes to the same state, but from here their odds are identical. The chain does not remember the path.
Figure 4. The Markov property in one picture. Two customers took very different routes to the same state, but from here their odds are identical. The chain does not remember the path.

Applied to customers, the same rule is a much stronger claim. It says that two people who are both in the Engaged state right now have the same probability of buying next month, regardless of how they got there. One of them might have found you through a referral last week. The other might have been circling for eight months across a dozen touchpoints. The Markov property says that once they are both Engaged, that history no longer matters.

You already know that is not entirely true. History does affect behavior. Long consideration cycles and referral sources both tell you something real about a customer.

The Markov property is a modeling assumption, not a fact about the world. We adopt it because it makes the math tractable and because it is often close enough to be useful. Whether it is close enough in your situation is a question you have to answer with your own data. I will come back to this in the section on where these models break down.

Reading a Transition Matrix

The state diagram is easy to look at, but it gets messy fast. With three states you have nine possible transitions. With ten states you have a hundred. At some point you need a table instead of a picture.

That table is called a transition matrix.

  • Each row is where you are now.
  • Each column is where you might go next.
  • The number where a row and column meet is the probability of that specific move.
Press enter or click to view image in full size
Figure 5. The same chain shown two ways. Each arrow in the diagram becomes one number in the table, and each row describes everything that can happen from one state. The Active row is highlighted in both. The inset shows what happens to the row count if you condition on two states instead of one. Later I call these rows patterns, since by then the point is about estimating them rather than reading them.
Figure 5. The same chain shown two ways. Each arrow in the diagram becomes one number in the table, and each row describes everything that can happen from one state. The Active row is highlighted in both. The inset shows what happens to the row count if you condition on two states instead of one. Later I call these rows patterns, since by then the point is about estimating them rather than reading them.

Reading it is easier than it looks. Take the Active row, with columns ordered Unengaged, Engaged, Active. If it reads 0.05, 0.15, 0.80, that means someone who was active this month has a 5 percent chance of going fully quiet next month, a 15 percent chance of engaging without buying, and an 80 percent chance of buying again. Read the row left to right and you have the whole story for that state.

Every row adds up to 1, for the reason I mentioned earlier. Something has to happen next. That holds as long as your states cover every outcome a person can have. If someone can leave the system entirely, that departure needs a state of its own.

What I have described is called a first-order chain in which only the current state matters. You can build higher-order chains that condition on the last two states, or the last three, and those sometimes fit real customer journeys better. But the cost is steep. A first-order chain over our three states has 3 patterns to estimate. A second-order chain has 9. A third-order chain has 27.

Each of those patterns needs enough observed data to estimate its probabilities reliably. That is why most practical models stay at first order, and it is a constraint that has been shaping this work since the 1960s. We will see exactly how in a bit.

What Happens Over the Long Run

So far we have looked at one step. The more useful question is what happens after many steps.

Start with your current mix of unengaged, engaged, and active people. Apply the transition matrix and you get next month’s mix. Apply it again and you get the month after that. Keep going and something interesting happens. The numbers settle toward a limit.

That limit is called the stationary distribution. It is the long-run mix the system drifts toward, and under the right conditions it does not depend on where you started. Two companies with completely different customer mixes today would end up at the same place if they had the same transition probabilities.

Press enter or click to view image in full size
Figure 6. Two companies with completely different customer mixes, run forward with the same transition probabilities. Within about 30 months they are indistinguishable. The Markov chain forgets where it started.
Figure 6. Two companies with completely different customer mixes, run forward with the same transition probabilities. Within about 30 months they are indistinguishable. The Markov chain forgets where it started.

We should be careful with that claim. Not every Markov chain settles this way. It requires conditions that mathematicians call irreducibility and aperiodicity. In plain terms, every state has to remain reachable from every other state, and the chain cannot get locked into a repeating cycle. Retention and market share models are often built so those conditions roughly hold, which is part of why I defined the reference states by current behavior. Plenty of other business models are deliberately built the other way, and I will get to those next.

Johnson Agbinya, in a textbook chapter on Markov chains and their applications, gives a clean example of why this matters. Two fast food chains compete for market share, and one starts with 60 percent. Run the transition probabilities forward one year and that leader drops to 49 percent. Keep going and it keeps sliding. The current number told you almost nothing about the direction.

This is the part I find most useful in practice. Marketers spend a lot of time on where their numbers are right now. The stationary distribution asks a different question. Given how customers actually move between states, where is this heading if nothing changes? That reframing is often more actionable than the current snapshot, because it points at the transition rates you would need to fix.

The next section covers a different kind of long-run behavior.

Chains That End: Absorbing States

Some states have no exit. Once the chain enters one, it stays there forever. These are called absorbing states, and a chain that has them behaves very differently from the one we just discussed.

Agbinya walks through a bank loan example that makes this concrete. A loan can be in four states: good, risky, paid off, or defaulted. Good loans and risky loans move back and forth as the borrower’s situation changes. But once a loan is fully paid off, it is done. Once it defaults, it is also done. Those two states each loop back to themselves with probability 1.0, and nothing leaves them.

Press enter or click to view image in full size
Figure 7. Two kinds of long-run behavior. On the left, every state stays reachable and the chain settles into a stable mix. On the right, two states have no exit, so the question changes from what the mix will be to where each customer ends up.
Figure 7. Two kinds of long-run behavior. On the left, every state stays reachable and the chain settles into a stable mix. On the right, two states have no exit, so the question changes from what the mix will be to where each customer’s loan ends up.

When a chain has more than one absorbing state, there is no single long-run mix that everyone converges toward. In this example, every loan eventually ends up either paid or defaulted, and which one depends on where it started. The interesting questions change. Instead of asking about the long-run mix, you ask where a given starting point is likely to end up and how long the journey takes.

Where you begin matters here. A loan that starts in the good category has a different probability of ending up paid off than one that starts risky, and it takes a different amount of time to get there.

The marketing version is obvious once you see it. Replace the loan states with prospect, engaged, purchased, and churned, and you have the same structure. Notice how different that is from the customer chain in Figure 2, where everyone can move in any direction forever and nobody is ever finished.

One caution. Purchase is only an absorbing state if you are modeling up to the first conversion. In a full lifecycle model, customers buy repeatedly, so purchase is not an endpoint at all. Churn is only absorbing if you exclude reactivation, and most businesses do reactivate lapsed customers. Whether a state absorbs is a decision you make when you build the model, not a property of the customer. That is exactly why my reference example uses behavioral states with no absorbing endpoints.

These two families, chains that settle and chains that end, cover most of what you will encounter. They are not a complete classification of every possible chain, but between them they cover almost every practical case.

The Math Behind Markov Chains

This section goes a level deeper than the rest of the article. If you want the concepts without the math, skip ahead to the next section. Nothing that follows depends on this. If you want a refresher on vectors and matrices first, I covered the basics in my previous article on linear algebra.

Everything in the last few sections comes down to three operations.

One step forward. Write your current mix as a row of probabilities, which we can call v. Write the transition matrix as P. Next month’s mix is

v₁ = v₀ P

That single multiplication is the whole one-step calculation. Each number in the answer is a weighted sum of the row you started with, where the weights come from a column of the matrix.

Many steps forward. Two steps is v times P times P. Ten steps is v times P raised to the tenth power. This is where the settling behavior shows up in the numbers. For a chain that satisfies the conditions I described earlier, raising P to higher and higher powers makes every row converge toward the same set of values.

Press enter or click to view image in full size
Figure 8. The same transition matrix multiplied by itself. After one month the rows are very different, because where you end up depends heavily on where you started. After 48 months every row is identical, which is another way of saying the starting point no longer matters.
Figure 8. The same transition matrix multiplied by itself. After one month the rows are very different, because where you end up depends heavily on where you started. After 48 months every row is identical, which is another way of saying the starting point no longer matters.

Susmita Bandyopadhyay, in a chapter on Markov chains in a decision support systems textbook, shows this clearly with a four-state example. By the eighth power, all four rows of the matrix match to four decimal places. That shared row is the stationary distribution, and the fact that every row converges to it is exactly why the starting point stops mattering. How fast this happens depends on the matrix. Our customer example takes closer to 48 steps to settle that completely, because customers move between states slowly.

Solving directly. You do not have to iterate. The stationary distribution is the vector v that satisfies

v P = v

Multiplying it by the transition matrix leaves it unchanged, which is what stationary means. Rearrange that and add the requirement that the shares total 1:

v (P − I) = 0, with v₁ + v₂ + v₃ = 1

Then solve the resulting system of equations.

Press enter or click to view image in full size
Figure 9. Two ways to find the stationary distribution. On the left, keep multiplying and wait for the numbers to stop moving. On the right, ask directly which vector the matrix leaves unchanged, and solve for it. Same answer, much less arithmetic.
Figure 9. Two ways to find the stationary distribution. On the left, keep multiplying and wait for the numbers to stop moving. On the right, ask directly which vector the matrix leaves unchanged, and solve for it. Same answer, much less arithmetic.

For readers with linear algebra background, that vector is the left eigenvector of P associated with eigenvalue 1. It is unique when the conditions I mentioned earlier hold.

Absorbing chains use a different calculation. You separate the states that can be left from the states that cannot, and the resulting block of numbers lets you compute the probability of ending in each absorbing state and the expected number of steps to get there. The key object has a name, the fundamental matrix, if you want to look it up.

One last note. Everything here assumes discrete time steps, meaning the system updates at fixed intervals like weeks or months. Continuous-time Markov chains exist and get used in queueing and reliability work, but they are outside what we need here.

Where Markov Chains Are Used

Markov chains turn up in a lot of fields. Here are three that show the range.

PageRank. Google’s original ranking algorithm modeled a random web surfer. The surfer sits on a page, clicks a link at random, lands on a new page, and repeats. The pages are states and the links are transitions. Run that chain long enough and it settles into a stationary distribution, and the pages with the highest long-run probability are the ones the surfer visits most. That distribution was the ranking.

There is a detail in PageRank that connects directly to the convergence conditions I described earlier. Every so often, instead of clicking a link, the surfer jumps to a random page. That jump is called teleportation, and it exists to make sure every page stays reachable so the chain has a unique, well-behaved stationary distribution. The algorithm that built the modern search industry was a Markov chain with a deliberate fix for reducibility and periodic behavior.

Get Marketing Data Science with Joe Domaleski’s stories in your inbox

Join Medium for free to get updates from this writer.

Queueing systems. A checkout line, a call center, or a server handling requests can all be modeled as states representing the number of people waiting. Customers arrive and move the system up a state. Service completions move it down. This is where a lot of operations research people first encounter this math, and it is how organizations decide how many registers or agents to staff.

Press enter or click to view image in full size
Figure 10. Three very different problems, all modeled as Markov chains. PageRank treats web pages as states and links as transitions, with the dashed arrows showing the random jumps that keep every page reachable. A queue’s states are how many people are waiting. A disease model moves people from susceptible to infected to recovered. Different domains, same structure.
Figure 10. Three very different problems, all modeled as Markov chains. PageRank treats web pages as states and links as transitions, with the dashed arrows showing the random jumps that keep every page reachable. A queue’s states are how many people are waiting. A disease model moves people from susceptible to infected to recovered. Different domains, same structure.

Disease spread. Stochastic compartment models track people moving between susceptible, infected, and recovered states. The transition rates or probabilities encode how contagious something is and how fast people recover. A lot of the modeling you saw during the pandemic was built on this structure.

Wai-Ki Ching’s book on Markov chain models and algorithms covers all three of these plus inventory systems, remanufacturing, and bioinformatics, so it is a good single place to look if you want more range than I can fit here.

There is also a variant called a hidden Markov model, where the states are not directly observable and you have to infer them from what you can see. That is a large topic on its own and I am not going to cover it, but it is worth knowing the term exists.

Markov Chains and Language Models

Now back to where we started, with Markov counting letters in Pushkin.

In 1948, Claude Shannon used the same approach in his foundational paper on information theory. He built text generators that picked each new letter or word based on the ones immediately before it. The output was not meaningful, but it looked like English. It had the right letter frequencies and the right rhythm. Shannon had shown that a surprising amount of what makes text look like text is captured by simple transition probabilities.

Early phone keyboards predicted your next word this way. Modern keyboards often use neural models instead, but the original versions were straightforward Markov chains over words.

Press enter or click to view image in full size
Figure 11. One prediction problem, three definitions of the current state. Give the model one word and almost anything could follow. Give it three and the options narrow. Give it the entire conversation and one answer dominates, though several remain possible.
Figure 11. One prediction problem, three definitions of the current state. Give the model one word and almost anything could follow. Give it three and the options narrow. Give it the entire conversation and one answer dominates, though several remain possible.

Here is the connection that makes this click for anyone who has worked with text data. What natural language processing calls an n-gram model is exactly a Markov chain. A model that uses three words of context to predict the fourth is a third-order Markov chain, and it is also called a four-gram model. Those are two names for the same thing.

So what about large language models (LLMs)?

An LLM is not a conventional Markov chain. It does not maintain a table of states and transition probabilities. It uses attention across the entire context to weigh every previous token when producing the next one, and the mechanism is nothing like a transition matrix.

That said, there is a mathematical reframing worth knowing. If you define the state as the entire context window rather than the last word or two, then the model does satisfy the Markov property. The next token depends only on the current state, where the state happens to be thousands of tokens long. That is a technically correct observation and a useful way to think about it, not a description of how the thing actually works.

Markov Chains in Marketing

Marketers have been using this math for a long time. The first paper I know of is from 1964, in the first issue of the Journal of Marketing Research.

George Styan and Harry Smith studied 100 households in Leeds, England. From January to June of 1957, those households kept weekly diaries of what laundry products they bought. Styan and Smith sorted every household-week into one of four states: bought detergent only, bought soap powder only, bought both, or bought neither. Then they built a transition matrix from the switching patterns.

Press enter or click to view image in full size
Figure 12. The first published Markov chain in marketing. Styan and Smith estimated week-to-week switching among 100 households in Leeds, then computed where that switching pattern was heading. The long-run mix lands almost exactly on the observed average. Worth noting that both come from the same 26 weeks of diaries, so this is internal consistency rather than out-of-sample validation.
Figure 12. The first published Markov chain in marketing. Styan and Smith estimated week-to-week switching among 100 households in Leeds, then computed where that switching pattern was heading. The long-run mix lands almost exactly on the observed average. Worth noting that both come from the same 26 weeks of diaries, so this is internal consistency rather than out-of-sample validation.

They calculated a stationary distribution of roughly 21, 41, 6, and 32 percent across the four states. The observed average across the 26 weeks was 21.04, 41.23, 6.42, and 31.31 percent. Those numbers line up closely.

I want to be careful about what that agreement means. The transition matrix was estimated from the same diary data that produced the observed average, so this is not out-of-sample validation. Part of the match is structural. To their credit, Styan and Smith said so themselves, noting that on this data their stationary prediction was equivalent to just assuming next week looks like this week. The original authors were more careful about their own result than a lot of people who have cited it since.

Worth noting who wrote it. Harry Smith ran the math and statistics department at Procter & Gamble. This was applied industry work from the start, not academic theory that marketers picked up later.

The modern applications follow the same structure. Journey and funnel modeling treats stages as states. Customer lifetime value and churn models use absorbing states for conversion and churn. Next best action models pick the transition most likely to move someone forward. And there is work using hidden Markov models to represent unobserved states like high intent versus low intent, where you infer the state from behavior rather than observing it directly.

The most common application, though, is attribution, which is how marketers divide credit for a sale across channels.

Attribution and the Removal Effect

Markov chain attribution answers a specific question. Given all the journeys you observed, how much credit does each marketing channel (social, search, email, etc.) deserve?

The setup is a chain where the states are your channels as shown in the figure below. Every journey starts at a node called Start. From there it moves through channels like paid social, paid search, and email, in whatever order the data shows. Every journey ends at one of two places:

  • Conversion. The person bought something.
  • Null. The person left without buying. Figure 13 labels this one No Sale, since the plain-language version is easier to read on a diagram.

That Null state is not optional. If Conversion is the only place a journey can end, then given enough steps every journey eventually converts, and the model reports a conversion probability of 1. Null is what makes the numbers mean anything.

Press enter or click to view image in full size
Figure 13. How Markov chain attribution works. Take the whole journey graph, calculate the chance a journey reaches a conversion, then delete one channel and calculate again. The drop, divided by the original, is that channel’s raw removal effect, which you then normalize against the other channels. Note the No Sale state: without somewhere for failed journeys to end, every journey would eventually convert and the calculation would be meaningless.
Figure 13. How Markov chain attribution works. Take the whole journey graph, calculate the chance a journey reaches a conversion, then delete one channel and calculate again. The drop, divided by the original, is that channel’s raw removal effect, which you then normalize against the other channels. Note the No Sale state: without somewhere for failed journeys to end, every journey would eventually convert and the calculation would be meaningless.

With the chain built, you calculate the probability that a journey starting at Start reaches Conversion. Call that the baseline.

Then you remove one channel and calculate the same probability again. It usually drops, because some journeys that used to reach Conversion no longer can. The size of that drop, divided by the baseline, is called the removal effect for that channel. Repeat this for every channel, then normalize the removal effects and use those proportions to allocate your observed conversions.

One oddity worth knowing. A channel that appears mostly in paths that failed to convert can produce a negative removal effect, meaning the modeled conversion probability goes up when you take it out. That is usually a signal to look at how you defined that channel or how thin the data is for it rather than a finding about the channel itself.

Removing a channel is not as simple as deleting a node, because deleting transitions leaves rows that no longer add up to 1. Whatever probability was flowing into that channel has to go somewhere for the matrix to remain valid. Some implementations redirect it to Null. Others redistribute it across the remaining paths, or rebuild the matrix from modified journey data. Those choices produce different numbers. If you build or buy one of these models, find out which convention it uses.

The result describes how conversion credit distributes across the journeys you recorded. That is useful for understanding your funnel. It is not the same as knowing what happens to sales if you cut the paid social budget by 30 percent. That difference matters, and I come back to it in the last section.

Where Markov Chains Break Down

Every model has limits, and these are worth knowing before you build anything.

The memoryless assumption is often wrong. Real customer journeys have history. Someone who has seen your ad nine times responds differently than someone seeing it for the first time, and a first-order chain cannot represent that difference.

You can fix this by going to higher orders, but there is a cost. An attribution model with 5 channels plus Start, Conversion, and Null has 8 states, so a first-order chain has up to 8 possible patterns to estimate. Second-order has up to 64. Third-order has up to 512, and fourth-order has up to 4,096. Each of those patterns needs enough observed transitions to produce a stable estimate, and your data does not grow just because your model did.

Press enter or click to view image in full size
Figure 14. Why higher-order Markov chains are harder than they look. Each square holds the same amount of data. All that changes is how many patterns it has to be divided among. By the fourth order, each estimate rests on about a dozen observations.
Figure 14. Why higher-order Markov chains are harder than they look. Each square holds the same amount of data. All that changes is how many patterns it has to be divided among. By the fourth order, each estimate rests on about a dozen observations.

This constraint is not new. Styan and Smith tested whether their 1957 data supported a first-order chain over a zero-order one, and it did. They also wanted to test higher orders and could not, because they did not have enough observed transitions. Lukáš Kakalejčík and his co-authors ran the same kind of test on modern e-commerce journeys and found fourth-order fit best.

What practitioners actually do about it is unglamorous. Prune paths that appear too few times to estimate. Aggregate similar channels together. Move to higher orders only when the data genuinely supports it.

The transition probabilities may not stay put. Everything in the long-run section assumes the same matrix keeps applying month after month. In marketing, that is a strong assumption. A price change, a new campaign, a competitor entering, or an ordinary seasonal shift can all change the transition probabilities themselves. When that happens, your stationary distribution describes where a world would have ended up, not the one you are operating in.

The chain records that a channel appeared, not how much of it appeared. One paid social impression and twenty impressions can both become the same transition. Frequency, spend level, and creative all collapse into the same state.

State definition is a choice you have to defend. Nobody hands you the states. You decide whether paid social is one channel or four, whether email opens and clicks are separate states, and where a journey starts. Different choices give different answers, and there is no objectively correct version.

And the biggest one. A Markov chain built from observed journeys describes those journeys. It does not establish what causes what. If paid search shows up in most converting paths, that might mean paid search drives conversions. It might also mean people who already decided to buy use search to find you. The chain cannot tell those apart, because both produce the same transition data.

I have written before about the difference between prediction and causation. This is a textbook case. The model can describe your journey structure accurately while telling you nothing about what happens if you change spend.

From Markov Chains to Markov Chain Monte Carlo (MCMC)

Everything so far treated the chain as a model of something real. States were customers or web pages or loan accounts, and transitions described how those things actually move. The chain was a representation of a process.

Now flip it. Suppose you do not care about representing anything. Suppose instead you have a probability distribution you want to study, and you cannot study it directly. What if you built a chain on purpose, designed so that its stationary distribution is exactly the distribution you are after?

That is the idea behind Markov Chain Monte Carlo. You construct a chain whose long-run behavior matches your target, let it run, and record where it goes. The record of visited states becomes a sample from the distribution you wanted.

Press enter or click to view image in full size
Figure 15. Markov Chain Monte Carlo in three snapshots. The chain starts somewhere arbitrary and moves step by step, accepting some proposed positions and rejecting others. Early on the path looks aimless. After enough steps, the places it has visited take the shape of the distribution you were after.
Figure 15. Markov Chain Monte Carlo in three snapshots. The chain starts somewhere arbitrary and moves step by step, accepting some proposed positions and rejecting others. Early on the path looks aimless. After enough steps, the places it has visited take the shape of the distribution you were after.

Monte Carlo means generating random samples to answer a question. Markov chain means each new sample depends on the current one. Put them together as MCMC and you can draw approximate samples from a distribution that you can describe mathematically but cannot sample from directly.

It is not that the distribution is unknown. In Bayesian work you can usually write it down up to a constant. The problem is that you cannot normalize it or draw from it with a standard method, and MCMC works around that.

The states here still mean something. Each one is a specific set of parameter values, a candidate answer to the question you are asking. What has no real-world meaning is the transition from one candidate to the next. Nothing is moving through time. The path is a computational device built to explore the distribution, and how well it explores is what determines whether your results are any good. That is why people who run these models spend real time on diagnostics.

The method dates to 1953, when Metropolis and his colleagues developed it for physics simulations at Los Alamos. It took decades and a lot of cheap computing before it reached the rest of us.

MCMC and Marketing Mix Modeling

Which brings us to marketing mix modeling (MMM).

A Bayesian MMM has a lot of moving parts. There are adstock parameters describing how long advertising effects persist, saturation parameters describing diminishing returns, coefficients for every channel, seasonality terms, and baseline components. That can easily run to dozens of parameters.

What you want from the model is a posterior distribution, meaning the range of plausible values for each parameter given your data and your priors. You can write that posterior down mathematically. What you cannot do is compute it directly, because doing so would require an integral that has no practical solution.

So you build a chain instead. Google Meridian uses the No-U-Turn Sampler (NUTS, that’s not a joke but is how it’s abbreviated), an adaptive extension of Hamiltonian Monte Carlo. It is a good deal smarter about how it moves through parameter space than the original Metropolis approach, which matters when you have dozens of dimensions to explore. Not every Bayesian tool uses MCMC, and some use variational inference to approximate the posterior instead, but MCMC remains the standard.

Press enter or click to view image in full size
Figure 16. What comes out of a Bayesian marketing mix model. Four chains explored the same channel coefficient from different starting points, and the histogram pools their retained draws. The answer is a range rather than a single number. R-hat compares the chains against each other, and the effective sample size accounts for the fact that consecutive draws are related rather than independent.
Figure 16. What comes out of a Bayesian marketing mix model. Four chains explored the same channel coefficient from different starting points, and the histogram pools their retained draws. The answer is a range rather than a single number. R-hat compares the chains against each other, and the effective sample size accounts for the fact that consecutive draws are related rather than independent.

There is a limit to what those numbers can tell you.

Markov chain attribution describes the journeys you observed and allocates credit across them. That is accounting. A marketing mix model attempts something harder. It asks a counterfactual question: what happens to sales if I change spend on this channel?

Whether it answers that question well depends heavily on your data. If a channel runs at a constant level all year, the model has little to work with, because there is no variation to separate that channel’s effect from everything else moving at the same time. I saw this directly on a recent modeling project, where the true channel effects were known in advance. An always-on search channel was consistently overattributed, because its steady spend pattern confounded with seasonal demand. Channels that ran in flights, with clear on and off periods, were estimated much more accurately.

Variation in your media schedule helps, but it does not settle the question by itself. Model specification, priors, and whatever confounders you failed to include all still matter. This is where diagnostics come in. R-hat compares the variation within chains against the variation between them, to check whether they appear to be sampling the same distribution. Trace plots let you see whether a chain explored properly or got stuck. Effective sample size tells you how much independent information your samples actually contain. Those are the topics of future articles.

Conclusion

If you remember one thing from this article, consider the distinction between the two jobs a Markov chain can do.

Sometimes the chain is the model. The states represent something real, the transitions describe how that real thing moves, and the output tells you something about the world. That is what is happening in attribution, in funnel modeling, in PageRank, and in the 1957 laundry study.

Press enter or click to view image in full size
Figure 17. Two jobs, one definition. A Markov chain used as a model has states that stand for real things, and its output describes the world. The same chain used as an engine has states that are candidate answers, with the path between them serving as a computational device. Knowing which one you are looking at is the difference between using these methods well and misreading them.
Figure 17. Two jobs, one definition. A Markov chain used as a model has states that stand for real things, and its output describes the world. The same chain used as an engine has states that are candidate answers, with the path between them serving as a computational device. Knowing which one you are looking at is the difference between using these methods well and misreading them.

Other times the chain is a computational engine. Its states are candidate parameter values, which do mean something, but its transitions do not describe anything moving in the real world. The path exists only to explore the posterior (the range of plausible parameter values given your data and priors). Once you have checked that it explored properly, you keep the parameter draws and set the ordering aside. That is MCMC, and it is what runs inside your MMM.

Both are Markov chains. Same definition, same math, two different jobs. Confusing them is how people end up making claims their models do not support, usually by treating an attribution result as if it were a causal one.

Try it on your own business. Sketch the states your customers move through and put rough numbers on how often they move between them. You will not have the real probabilities handy, but guessing at them tells you exactly which ones you should be measuring. You will have built a Markov chain without doing any math at all.

Resources

Agbinya, Johnson I. “Markov Chain and Its Applications.” Applied Data Analytics: Principles and Applications, River Publishers, 2020, pp. 1–15.

Bandyopadhyay, Susmita. “Markov Chain.” Decision Support System, CRC Press, 2023, pp. 109–124, https://doi.org/10.1201/9781003307655-8.

“Chain-Based Attribution: A B2B Marketing Deep Dive.” CaliberMind, 18 Jan. 2026, https://calibermind.com/articles/chain-based-attribution-a-b2b-marketing-deep-dive/.

Chen, Guanyu. “Introduction to Basic Properties of Markov Chain and Its Application in Simple Random Walk.” REU Papers, University of Chicago, 2022, https://math.uchicago.edu/~may/REU2022/REUPapers/Chen,Guanyu.pdf.

Ching, Wai-Ki, et al. Markov Chains: Models, Algorithms and Applications. 2nd ed., Springer, 2013. International Series in Operations Research & Management Science 189, https://doi.org/10.1007/978-1-4614-6312-2.

Domaleski, Joe. “Bayesian Statistics Explained for Marketers.” Marketing Data Science, 5 July 2026, https://blog.marketingdatascience.ai/bayesian-statistics-explained-for-marketers-be1c46ea159a.

Domaleski, Joe. “An Introduction to Linear Algebra: The Math I Slept Through in College That Now Powers AI.” Marketing Data Science, 12 April 2026, https://blog.marketingdatascience.ai/an-introduction-to-linear-algebra-the-math-i-slept-through-in-college-that-now-powers-ai-c4831f688496.

Domaleski, Joe. “An Introduction to Marketing Mix Modeling (MMM): How It Works and Why It’s Making a Comeback.” Marketing Data Science, 8 March 2026, https://blog.marketingdatascience.ai/an-introduction-to-marketing-mix-modeling-mmm-how-it-works-and-why-its-making-a-comeback-3791c1ccb914.

Domaleski, Joe. “Marketing Mix Modeling with Meridian: How to Build Your First Bayesian MMM Step-by-Step.” Marketing Data Science, 22 March 2026, https://blog.marketingdatascience.ai/marketing-mix-modeling-with-meridian-how-to-build-your-first-bayesian-mmm-step-by-step-e00d736596e7.

Domaleski, Joe. “Introduction to Monte Carlo Simulation for Marketers,” Marketing Data Science, 2 August 2026, https://blog.marketingdatascience.ai/introduction-to-monte-carlo-simulation-for-marketers-8cb0077f1566.

Domaleski, Joe. “The Role of Attribution, Correlation, and Causation in Everyday Life.” The Citizen, 16 Sept. 2024, https://thecitizen.com/2024/09/16/the-role-of-attribution-correlation-and-causation-in-everyday-life/.

Kakalejčík, Lukáš, et al. “Multichannel Marketing Attribution Using Markov Chains.” Journal of Applied Management and Investments, vol. 7, no. 1, 2018, pp. 49–60, https://growthpro.sk/wp-content/themes/growthpro/pdf/multichannel_marketing_attribution_using_markov_chains.pdf.

Mahfuz, Fariha. Markov Chains and Their Applications. Master’s thesis, University of Texas at Tyler, 2021, https://scholarworks.uttyler.edu/math_grad/10/.

“Markov Chain Attribution Modeling [Complete Guide].” Adequate, 25 Dec. 2023, https://adequate.digital/en/markov-chain-attribution-modeling-complete-guide/.

Seabrook, Eddie, and Laurenz Wiskott. “A Tutorial on the Spectral Theory of Markov Chains.” Neural Computation, vol. 35, no. 11, 2023, pp. 1713–1796, https://doi.org/10.1162/neco_a_01611. Open-access preprint: https://arxiv.org/abs/2207.02296.

Shannon, Claude E. “A Mathematical Theory of Communication.” Bell System Technical Journal, vol. 27, no. 3, July 1948, pp. 379–423, https://doi.org/10.1002/j.1538-7305.1948.tb01338.x.

Styan, George P. H., and Harry Smith, Jr. “Markov Chains Applied to Marketing.” Journal of Marketing Research, vol. 1, no. 1, Feb. 1964, pp. 50–55, https://doi.org/10.1177/002224376400100109.

Umbalacheri Ramasamy, Venkatraman. “Multi-Touch Attribution Models.” DZone, 10 Apr. 2024, https://dzone.com/articles/multi-touch-attribution-models.

--

--

Marketing Data Science with Joe Domaleski
Marketing Data Science with Joe Domaleski

Written by Marketing Data Science with Joe Domaleski

I use data science 📊 & machine learning 👨🏻‍💻 for BETTER MARKETING. Owner of Country Fried Creative, an award-winning marketing firm. Army Vet. GT 🐝, GSU 🐾