mixdyn¶
Media-mix modelling that plans the budget, reads your lift and geo tests, and is scored in the open against Meridian, PyMC-Marketing and Orbit.
mixdyn is a media-mix modelling (MMM) engine in Python and JAX, built on causal-hybrid-control:
- Models: regressions, discount dynamic linear models, Bayesian models with lift and geo tests in the likelihood, and hierarchies over geos.
- Experiments: readers for lift and geo tests, and a test priced by what it adds to the plan before it runs.
- Plans: next quarter's budget split over channels, inside each channel's bounds, from a posterior or from each channel's margin.
- Checks: diagnostics, holdout scores, refreshes as weeks arrive, and each channel's sensitivity to an unmeasured confounder.
Its runtime is NumPy, SciPy, JAX and causal-hybrid-control, with what those bring in: no probabilistic-programming language, no other MMM package, no UI. It does not do multi-touch attribution (MTA): it reads no user-level path.
How it measures up¶
On the causaldyn bench's simulated worlds, whose optimal budget split is known, mixdyn's plans are within δ = 0.05 of regret per euro of budget of those of Meridian 2.1.0, PyMC-Marketing 1.3.0 and Orbit 1.1.5.1, and of the status quo and the equal split, on 37 of 38 pre-registered family-rungs. Three scored runs read them, M3, M4 and M5, each pre-registration frozen before any confirmatory world was fitted. The one family-rung not within δ is family 4, S-curves, with no lift test: there mixdyn's plan loses to Orbit's by +0.136 and to PyMC-Marketing's by +0.135 a euro, because the data do not identify television's curve beyond the range its spend was logged in.
| Of 38 family-rungs, mixdyn | Meridian | PyMC-Marketing | Orbit | Status quo | Equal split |
|---|---|---|---|---|---|
| beats the rival | 34 | 19 | 35 | 36 | 38 |
| ties | 1 | 11 | 1 | 2 | 0 |
| loses to it, within δ | 1 | 7 | 1 | 0 | 0 |
| loses to it, past δ | 0 | 1 | 1 | 0 | 0 |
| is not compared: the rival failed | 2 | 0 | 0 | 0 | 0 |
Each count is of family-rungs, each read by Hall's reader at one-sided 0.025 over the worlds both tools planned. This is a non-inferiority result on simulated worlds: it does not say that mixdyn is the best MMM, and no real data has scored it yet. One maintainer built both the engine and the bench that scores it. Every comparison, every loss, the pre-registrations, the versions and the compute are on the benchmark page.
Install¶
pip install mixdyn # Python 3.12 or later
A first plan¶
import numpy as np
from mixdyn import Cadence, Revenue, read_panel
from mixdyn.decisions import Range, plan_margins
from mixdyn.models import fit_margins
# Two years of weekly history: sales lifted by each channel's spend through a geometric adstock.
rng, weeks, names = np.random.default_rng(0), 104, ("tv", "search", "social")
spend = rng.uniform([60.0, 20.0, 15.0], [180.0, 80.0, 55.0], size=(weeks, 3))
kernel = 0.5 ** np.arange(8) / (0.5 ** np.arange(8)).sum()
carried = np.column_stack([np.convolve(s, kernel)[:weeks] for s in spend.T])
truth = np.array([1.5, 3.0, 0.5]) # each channel's margin, which the fit does not see
sales = 5000.0 + carried @ truth + rng.normal(0.0, 25.0, weeks)
dates = np.datetime64("2024-01-01") + np.timedelta64(7, "D") * np.arange(weeks)
data = {"week": dates, "sales": sales} | {c: spend[:, i] for i, c in enumerate(names)}
panel = read_panel(
data,
date="week",
kpi="sales",
spend={c: c for c in names},
cadence=Cadence.WEEK,
kpi_unit=Revenue(),
currency="EUR",
)
fit = fit_margins(sales, spend, None, None, kernel=8) # each margin, as the regression reads it
# Next quarter's weekly plan at the status quo's budget, within half to twice each status quo.
status_quo = spend[-52:].mean(axis=0)
limits = {c: Range(0.5 * q, 2.0 * q) for c, q in zip(panel.channels, status_quo, strict=True)}
plan = plan_margins(panel, None, 13, limits, kernel=8)
print("status quo", plan.current.round(1), "plan", plan.spend.round(1), fit.mean.round(2))
plan_margins is margin held, the rule the runs scored with no lift test
(scorecard/arms/margin.py), in one call: it reads each margin off a regression with saturating
curves, shrinks the margins together and fills the budget along the curves. SKILL.md walks one
panel through the Bayesian engine, gated at each step: read, fit, diagnostics, tests, plan, report.
Where it sits¶
Marketers' measurement is turning to MMM checked by experiments, more than to
multi-touch attribution (MTA), which follows each user's path to a sale. In a survey of 196 US
marketers that EMARKETER fielded for TransUnion in July 2025, 47 % planned to raise their spend on
MMM in the next year and 35 % their spend on MTA
(TransUnion, October 2025).
Forrester's 2025 and 2026 global marketing surveys found that "adoption of marketing mix
modeling and incrementality testing increased substantially year over year"
(Forrester, July 2026).
CIMM's 2026 roadmap for MMM asks the industry to "establish an experimentation and validation
playbook for geo tests, lift tests"
(CIMM, July 2026).
mixdyn is built for that pairing: its Bayesian models read lift and geo tests in the likelihood,
and mixdyn.experiments prices a test by what it adds to the plan before it runs (ADRs 0030 to
0032). It does not do MTA: it reads no user-level path.
Using it¶
Each channel's return can be read against an unmeasured confounder: mixdyn.inference.sensitivity
gives Cinelli and Hazlett's robustness values for the ridge engine and the marginal sensitivity
model's Gamma* for the Bayesian ones, mixdyn.api.sensitivity_line states them, and
mixdyn.api.factsheet writes each Bayesian channel's line among its limitations (ADR 0061). The
bound is wide wherever the spend moved little beside the KPI's unexplained variation, confounded
or not.
A static fit can be checked on the periods after its window and carried forward as weeks arrive
(ADR 0079). holdout_bayes scores the posterior predictive on the window's last periods, held out
of the fit: periods drawn from the whole window would share their autocorrelated noise with their
fitted neighbours and flatter the score. refresh_bayes refits the whole panel with each
channel's return prior tempered by the previous posterior, and reports how far each return moved
and whether it left the previous 80 % interval. The scorecard's refresh cell
(python -m scorecard.refresh) refits every arm on a world's history four weeks at a time, six
times, and reads how far each return and each plan's regret swing between refits, and, from a
rolling origin on the short-history family, each origin's forecast score. Measurement services
sell a refresh loop whose results stay stable; the cell measures that stability on worlds whose
truth is known, for this engine's arms and the rivals'.
Where to go next¶
- Benchmark: what three pre-registered runs measured against Meridian, PyMC-Marketing, Orbit, the status quo and the equal split, where the engine loses, and how each run can be reproduced.
- Walkthrough: one panel through read, fit, diagnostics, tests, plan and report, each step gated by the engine's own checks.
- Scope: what the engine does not model, reach and frequency among it.
- API reference: every public name, the versioning rules, and one page per public module rendered from its docstrings.
- On GitHub: the decision records the code relies on, the evidence their measurements come from, the scorecard harness, the changelog and how to contribute.