PyMC-Marketing MMM: Bayesian Marketing Mix Modeling with Adstock, Saturation and Priors in Python
Before it sees any data, the default priors in a PyMC-Marketing MMM put the median ROAS of an always-on search channel at 29. A two-year simulation with known answers shows what that does to the posterior and to the sampler, and how priors set on the ROAS scale plus two lift tests bring both back.

A PyMC-Marketing MMM gives you Bayesian marketing mix modeling in a few lines of Python: geometric adstock for carryover, a logistic curve for saturation, seasonality, controls and a full posterior for every channel. The few lines hide one decision that carries more weight than anything else in the model, which is the priors. I simulated two years of weekly sales for a brand with three channels and known returns, then fit PyMC-Marketing 1.5.0 to it four ways. Before seeing a single week of data, the default priors put the median return on ad spend of the search channel at 29 dollars of sales per dollar. The true value is 2.94.
The data pulls most of that back, but not all of it. With default priors the 90% interval for search ROAS ran from 0.33 to 16.74, the one for social from 0.15 to 25.32, and the sampler logged 243 divergences. Priors written on the ROAS scale, plus two lift tests of the kind a team runs in a month, narrowed those intervals to 1.07 to 4.85 and 0.79 to 2.98 and cut the divergences to 3. This piece walks through the model, the simulation, the prior check that catches the problem before fitting, and the arithmetic that puts priors on a scale a marketer can argue about.
What a PyMC-Marketing MMM fits
The model is the one Jin, Wang, Sun, Chan and Koehler described at Google in 2017. Weekly sales are a baseline plus the sum of each channel's transformed spend plus noise:
Adstock spreads each week's spend over the following weeks with geometric weights, normalized to sum to one, so a channel's carryover changes the timing of its effect but not its size:
Saturation is a logistic curve on spend divided by the channel's maximum, so it rises steeply at first and flattens toward β:
PyMC-Marketing scales the target too. By default it divides sales by their maximum, so β lives in units of "share of the best week's sales." That choice makes the sampler's job easier, and it is where the trouble starts, because nobody holds beliefs in those units. The Google paper's own simulations found that with small samples the priors "have a big impact on the posteriors" and can bias the estimates. Two years of weekly data is a small sample: 104 rows, three channels, and three parameters per channel.
A brand with known answers
The simulated brand spends about $10.7 million over two years. TV runs in flights of four to six weeks with gaps of three to eight. Search is always on and rises and falls with demand, the way paid search budgets usually do. Social runs steadily between $15,000 and $30,000 a week. Media drives about 20% of sales.
import numpy as np, pandas as pd
TRUE = { # per channel: geometric adstock alpha, logistic saturation lam (on spend / channel max), beta (sales units per week at full saturation)
"tv": {"alpha": 0.60, "lam": 2.0, "beta": 140_000},
"search": {"alpha": 0.10, "lam": 3.0, "beta": 110_000},
"social": {"alpha": 0.30, "lam": 1.5, "beta": 45_000},
}
L_MAX = 8
def geometric_adstock(x, alpha, l_max=L_MAX):
w = alpha ** np.arange(l_max)
w = w / w.sum() # normalized weights, as in PyMC-Marketing's default
out = np.zeros_like(x, dtype=float)
for lag in range(l_max):
out[lag:] += w[lag] * x[: len(x) - lag]
return out
def logistic_saturation(x, lam):
return (1 - np.exp(-lam * x)) / (1 + np.exp(-lam * x))
def simulate(n_weeks=104, seed=7, start="2024-11-04"):
rng = np.random.default_rng(seed)
t = np.arange(n_weeks)
dates = pd.date_range(start, periods=n_weeks, freq="W-MON")
season = np.sin(2 * np.pi * t / 52.18) + 0.5 * np.cos(4 * np.pi * t / 52.18)
# TV runs in flights: on for 4 to 6 weeks, off for 3 to 8
tv = np.zeros(n_weeks); i = 2
while i < n_weeks:
on = rng.integers(4, 7); tv[i:i + on] = rng.uniform(60_000, 120_000); i += on + rng.integers(3, 9)
# Search is always on and follows demand, the usual pattern
search = 30_000 + 8_000 * season + rng.normal(0, 2_500, n_weeks)
social = rng.uniform(15_000, 30_000, n_weeks)
spend = {"tv": tv, "search": search, "social": social}
contrib = {}
for ch, p in TRUE.items():
x = spend[ch] / spend[ch].max()
contrib[ch] = p["beta"] * logistic_saturation(geometric_adstock(x, p["alpha"]), p["lam"])
baseline = 600_000 + 900 * t + 60_000 * season
sales = baseline + sum(contrib.values()) + rng.normal(0, 25_000, n_weeks)
df = pd.DataFrame({"date": dates, **spend, "sales": sales})
return df, contrib
def true_roas(df, contrib):
return {ch: contrib[ch].sum() / df[ch].sum() for ch in TRUE}
Run it and the true returns come out as 1.01 for TV, 2.94 for search and 1.02 for social. Search is the best channel by far, and it is also the hardest to measure: its spend moves with demand, so the model has to separate "search spend went up" from "it was a busy season anyway." The baseline's seasonal swing and search spend are correlated at 0.65.
Fitting the PyMC-Marketing MMM with default priors
The model below uses PyMC-Marketing's components as they ship: GeometricAdstock with an eight-week window, LogisticSaturation, two yearly Fourier modes and a linear trend as a control. Every fit in this piece used four chains, 1,500 tuning steps, 1,000 draws and a target acceptance of 0.95.
from pymc_marketing.mmm import MMM, GeometricAdstock, LogisticSaturation
CHANNELS = ["tv", "search", "social"]
def build(model_config=None):
return MMM(
date_column="date",
channel_columns=CHANNELS,
target_column="sales",
control_columns=["trend"],
yearly_seasonality=2,
adstock=GeometricAdstock(l_max=L_MAX),
saturation=LogisticSaturation(),
model_config=model_config,
)
df, contrib = simulate()
X = df.drop(columns="sales").assign(trend=np.arange(len(df)) / len(df))
y = df["sales"]
mmm = build()
mmm.fit(X, y, chains=4, draws=1000, tune=1500, target_accept=0.95, random_seed=1, progressbar=False)
def posterior_roas(mmm, df):
contrib = mmm.idata.posterior["channel_contribution"] # scaled units
scale = float(np.asarray(mmm.get_scales_as_xarray()["target_scale"]))
roas = contrib.sum("date") * scale / df[CHANNELS].sum().values
out = {}
for i, ch in enumerate(CHANNELS):
v = roas.isel(channel=i).values.ravel()
out[ch] = {"mean": v.mean(), "lo": np.quantile(v, 0.05), "hi": np.quantile(v, 0.95)}
return out
In version 1.5.0 the defaults are a Beta(1, 3) prior on each adstock α, a Gamma(3, 1) on each saturation λ and a HalfNormal with σ = 2 on each β. I read them from MMM(...).model_config rather than from documentation, since defaults change between releases. TV came back well: a posterior mean ROAS of 1.30 with a 90% interval of 1.10 to 1.50. Its flights switch on and off, which is the kind of variation a regression can learn from. Search came back at a mean of 5.03 with an interval from 0.33 to 16.74, and social at 4.46 with an interval from 0.15 to 25.32. Both true values sit inside those intervals. Neither interval would survive a budget meeting.
The sampler said as much. It logged 243 divergences, a maximum r-hat of 1.043 and a minimum bulk effective sample size of 67. The usual bar is an r-hat under 1.01 and several hundred effective draws. A model that fails those checks has not finished describing its own uncertainty, and its intervals should not be read at all.
What the default priors say before seeing data
The faster way to find the problem is to ask the model what it believes before it fits anything. A prior predictive check draws parameters from the priors, pushes them through the model and reports the channel contributions those draws imply. Converting the contributions to ROAS takes one multiplication by the target scale.
import pymc as pm
mmm = build()
mmm.build_model(X, y)
with mmm.model:
pr = pm.sample_prior_predictive(draws=2000, random_seed=3, var_names=["channel_contribution"])
scale = float(np.asarray(mmm.get_scales_as_xarray()["target_scale"]))
roas = pr.prior["channel_contribution"].sum("date") * scale / df[CHANNELS].sum().values
| Channel | Prior median ROAS | Prior 90% range | Share of prior draws above ROAS 5 |
|---|---|---|---|
| TV | 9.57 | 0.83 to 33.66 | 71% |
| Search | 29.05 | 2.45 to 99.29 | 90% |
| Social | 38.15 | 3.74 to 139.40 | 93% |
A HalfNormal(2) on β sounds weak, and on the scaled problem it is. On the ROAS scale it is a strong belief that every channel is a gold mine, and the smaller a channel's spend is next to sales, the stronger that belief gets. Social, the smallest budget, gets the most extreme prior. The data for TV overwhelmed that belief. The data for search and social did not, so their posteriors kept a long right tail that came straight from the prior.
Three common fixes, one of which works
The first fix many teams reach for is to scale each channel's β prior by its share of spend. Here TV has 48.9% of spend, search 28.9% and social 22.2%, and the prior σ becomes the number of channels times the spend share. That run was worse: 618 divergences, an r-hat of 1.234 and a social ROAS mean of 7.28. Spend-share priors assume that every channel returns about the same per dollar, which is the very thing the model is supposed to find out, and they still live on the scaled units.
The second fix is to add experiments. PyMC-Marketing can condition the saturation curve on lift tests through add_lift_test_measurements. I simulated two tests a team could run in a month: cutting search spend by 30% (an observed drop of 16,584 in weekly sales against a true drop of 16,727) and raising social spend by 50% (an observed rise of 10,762 against a true 8,032), each with a 25% standard error. The tests are simulated from the true curves at average weekly spend.
# Pause 30% of search spend for a month, add 50% to social for a month.
rng = np.random.default_rng(11)
def lift_row(ch, frac):
x = float(df[ch].mean()); dx = frac * x; mx = float(df[ch].max()); p = TRUE[ch]
true_dy = p["beta"] * (logistic_saturation((x + dx) / mx, p["lam"]) - logistic_saturation(x / mx, p["lam"]))
sigma = abs(true_dy) * 0.25 # a test with a 25% standard error
return {"channel": ch, "x": x, "delta_x": dx, "delta_y": float(rng.normal(true_dy, sigma)), "sigma": sigma}
lifts = pd.DataFrame([lift_row("search", -0.30), lift_row("social", 0.50)])
mmm = build()
mmm.build_model(X, y)
mmm.add_lift_test_measurements(lifts)
mmm.fit(X, y, chains=4, draws=1000, tune=1500, target_accept=0.95, random_seed=1, progressbar=False)
On top of the default priors, the lift tests made the sampler fail outright: 867 divergences, an r-hat of 1.575 and a minimum effective sample size of 7, with a search ROAS mean of 13.64. A lift test pins the slope of the saturation curve at today's spend. It says little about the curve's height. The likely reason for the failure: with a prior that favors very tall curves, the sampler found tall, nearly flat curves that match the measured slope and put them next to short, steep ones that match it too, and the chains never agreed. The failure is not even stable: with the same tests rounded to whole units, the rerun logged 81 divergences and put search at 6.49 (1.42 to 18.73). A sampler in that state gives a different wrong answer each time the inputs move.
The third fix is to write the prior where people hold beliefs, on ROAS, and translate it into the model's units. Over the fitting period a channel's contribution in sales is β times the target scale T times the sum of its transformed spend, so the β that delivers a believed ROAS is
evaluated at a reference λ and α. I gave every channel the same neutral belief, a median ROAS of 1.4 with a 95th percentile of 4, and put a LogNormal prior on β around the translated value. The prior predictive check then came back with medians of 1.29, 1.26 and 1.25 and 90% ranges from about 0.3 to about 4.1 for all three channels, which is what the belief said. Fit to the data alone, that prior gave 2 divergences and an r-hat of 1.003, with search at 1.62 (0.37 to 3.88) and social at 1.32 (0.35 to 3.02). Both true values sit inside the intervals, which are now about a fifth of the default width for search and a tenth for social.
With the two lift tests added, search moved to 2.55 (1.07 to 4.85) and social to 1.57 (0.79 to 2.98), with 3 divergences and an r-hat of 1.004. The search test pulled the estimate up toward the true 2.94 because the prior now ruled out the tall flat curves and left the slope to decide. TV did not move, at 1.30 (1.10 to 1.50).
| Prior setup | Search ROAS, mean (90%) | Social ROAS, mean (90%) | Divergences | Max r-hat |
|---|---|---|---|---|
| Defaults | 5.03 (0.33 to 16.74) | 4.46 (0.15 to 25.32) | 243 | 1.043 |
| Spend-share β priors | 4.81 (0.39 to 15.64) | 7.28 (0.18 to 27.64) | 618 | 1.234 |
| Defaults + 2 lift tests | 13.64 (1.69 to 34.11) | 1.79 (0.87 to 4.62) | 867 | 1.575 |
| ROAS-scale priors | 1.62 (0.37 to 3.88) | 1.32 (0.35 to 3.02) | 2 | 1.003 |
| ROAS-scale priors + 2 lift tests | 2.55 (1.07 to 4.85) | 1.57 (0.79 to 2.98) | 3 | 1.004 |
True ROAS: search 2.94, social 1.02. Each fit took between about one and five minutes on two CPU cores; the well-posed ones were the fast ones, at 69 and 73 seconds.
Where this breaks
This is one simulated brand with one random seed, and the model that fit it has the same functional form as the process that produced the data. Real data has a baseline that no Fourier series captures, channels that interact, and promotions nobody logged. All of that makes the identification problem worse, not better.
TV's interval, 1.10 to 1.50, misses its true value of 1.01 in every setup. A 90% interval should miss about one time in ten, and part of the gap is the trade between λ and β: a steeper curve with the same ceiling fits TV's flights almost as well. One brand cannot tell those two stories apart. Social's final interval, 0.79 to 2.98, contains the truth but its mean of 1.57 sits above it, partly because the simulated social test happened to come in high (10,762 against a true 8,032). A single lift test is a noisy measurement, and the model treats it as one.
The ROAS-scale translation also rests on reference values of λ and α. The prior predictive check is what keeps that honest: if the implied ROAS does not match the belief you wrote down, the translation is off and you fix it before fitting. None of this is specific to one library. Any Bayesian MMM that scales its target puts priors on units nobody reasons in, and the check works the same way in all of them.
What to do with this
Before fitting a PyMC-Marketing MMM on real data, run the prior predictive check above and read the implied ROAS by channel. If the medians look like nothing your finance team has ever seen, change the priors before you look at a posterior. Write each channel's belief as a ROAS median and an upper bound, with the reason next to it, and translate it into β. Treat divergences and an r-hat above 1.01 as a failed run, not a warning. Spend your experiment budget on the channels whose intervals are still wide after that, which here meant search and social, not TV.
Marketing mix modeling draws 10 to 100 searches a month in the Kansas City metro by Google Keyword Planner's count, and measurement teams here face the same always-on search problem as anyone. More on calibrating models against experiments, and on Papilon, the open-source MMM library built in Kansas City, is in the Marketing Mix Modeling & Measurement research area. To fit a model to your own weekly spend in the browser, try Papilon Studio.
The paid edition on Substack turns this into a production template: a script that reads a prior worksheet, translates each ROAS belief into PyMC-Marketing priors, stops the run when the prior check fails, adds your lift tests, gates the fit on r-hat, effective sample size and divergences, and writes a readout with a sign-off checklist. It also reruns the comparison on 52 and 156 weeks of data to show how much history buys. Subscribe free for new articles by email, or get a Team License for the whole measurement team.
Sources
- Jin, Wang, Sun, Chan and Koehler, Bayesian Methods for Media Mix Modeling with Carryover and Shape Effects, Google, 2017
- pymc-marketing on PyPI, version 1.5.0, released November 18, 2026, Apache 2.0 license, accessed November 23, 2026
- Dean, Orduz, Allen and colleagues, PyMC-Marketing: Bayesian Marketing Mix Models and Customer Analytics in Python, Journal of Open Source Software, 2026
- Simulation, fits and default priors: the code in this article, run November 23, 2026 with pymc-marketing 1.5.0 and PyMC 6.4.0


