How Wrong Is Your MMM?
Measure how reliable your MMM is, and phase your budget to make it more reliable.
Marketing budgets are planned together and follow demand, so a marketing mix model (MMM) struggles to tell channels apart. This package simulates your own spend to measure the damage on three fronts (variance, bias, and whether saturation and adstock can be recovered at all), then recommends a weekly spend schedule that fixes it without changing any channel's annual budget.
Everything is measured by simulation against marginal returns you supply, not against ground truth in your data.
Read the overview for the full walkthrough on a worked example.
- Overview: the problem, the fix and what it costs.
- Example report: the HTML report the package produces, on simulated data.
- API reference: every class and function.
Quick start
pip install how-wrong-is-your-mmm
Or from source:
git clone https://github.com/raz1470/how_wrong_is_your_mmm
cd how_wrong_is_your_mmm
uv venv --python 3.12 && uv sync
Your inputs
Every step takes the same inputs: your spend, and plausible values from your MMM. The baseline inputs are used by the report only.
# history: your multi-year weekly spend, one column per channel (DatetimeIndex)
# plan: the upcoming year's weekly spend plan (DatetimeIndex, same channels)
marginal_returns = {"tv": 1.8, "paid_social": 2.4, "search": 4.1} # revenue from the next £1
saturation = {"tv": 0.6, "paid_social": 0.75, "search": 0.9} # curve exponent, 1.0 is linear
adstock = {"tv": 0.5, "paid_social": 0.3, "search": 0.1} # share of the effect carried into next week
noise_std = 50_000 # weekly sales noise sd in GBP
baseline_share = 0.7 # share of sales you would get with no marketing
baseline_cv = 0.05 # how much that baseline moves week to week (sd / mean)
1. Diagnose
How much do your marginal-return estimates swing, given your own spend history?
from how_wrong_is_your_mmm import CollinearityDiagnostic
diag = CollinearityDiagnostic(
spend_df=history,
true_marginal_returns=marginal_returns,
saturation=saturation,
adstock=adstock,
revenue_noise_std=noise_std,
)
diag.fit()
diag.summary()
2. Phase
Get a weekly schedule that breaks the correlation between channels:
from how_wrong_is_your_mmm import BudgetPhaser
phaser = BudgetPhaser(
history_df=history,
plan_df=plan,
true_marginal_returns=marginal_returns,
saturation=saturation,
adstock=adstock,
revenue_noise_std=noise_std,
)
phaser.fit()
phaser.recommended_schedule_ # 52-week DataFrame, monthly totals guaranteed to match
phaser.recommended_cost_ # spend saved and revenue given up, per channel
To go dark for four weeks a year and keep the saving, rather than move it to another month, pass max_weekly_deviation_pct=Redistribute(reallocate=False). The plan then spends less, and recommended_cost_ shows how much revenue that gives up.
3. Report
Compare the phasing strategies and package the result as one HTML report, with the winning schedule as a CSV:
from how_wrong_is_your_mmm import DiscoveryReport
report = DiscoveryReport(
history_df=history,
plan_df=plan,
true_marginal_returns=marginal_returns,
saturation=saturation,
adstock=adstock,
revenue_noise_std=noise_std,
baseline_share=baseline_share,
baseline_cv=baseline_cv,
client_name="Example Brand",
# optional: pin a strategy instead of sweeping for one, with per-channel overrides
# strategy_pct=60.0,
# channel_constraints={"paid_social": 20.0},
)
report.fit()
report.to_html("reports/example_brand.html") # self-contained HTML, open it in a browser
report.schedule_csv("reports/example_brand_schedule.csv") # the recommended weekly schedule
true_marginal_returns and the noise level are the two inputs that matter most. Supply your own for both.
Notebooks
| Notebook | What it shows |
|---|---|
01_scenario_walkthrough |
The full pipeline on the example report's four-channel scenario |
02_channel_scaling |
Whether the fix holds from 3 to 20 channels and across spend correlations |
03_time_to_benefit |
How many weeks of phasing it takes to cut the uncertainty |
04_adstock_threat |
Whether the bias reduction survives carryover |
05_strategy_comparison |
The six default strategies compared on variance, bias, identifiability and cost |
Development
uv run ruff format . && uv run ruff check . && uv run pytest
Python 3.12+. MIT licence.
The API reference is rebuilt and deployed with the rest of docs/ on every push to main. To preview it locally:
uv run mkdocs serve
Metadata
Release files for how-wrong-is-your-mmm 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| how_wrong_is_your_mmm-0.1.0.tar.gz | 170.9 kB | Without provenance | Details for how_wrong_is_your_mmm-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| how_wrong_is_your_mmm-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for how_wrong_is_your_mmm-0.1.0-py3-none-any.whl |
Total release size: 283.3 kB
Release files / how_wrong_is_your_mmm-0.1.0.tar.gz
| Download URL | how_wrong_is_your_mmm-0.1.0.tar.gz |
|---|---|
| Size | 170.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39e0b3b57ea667ffda5b2a0bb88fe8859dff85113ef91ff606cb807ea825f7d9
|
|
BLAKE2b-256 checksum How to use checksums |
feb5974c97edec1e5a861958e9c51f2fd40bbacdd25b7dd150638311fe4f6371
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / how_wrong_is_your_mmm-0.1.0-py3-none-any.whl
| Download URL | how_wrong_is_your_mmm-0.1.0-py3-none-any.whl |
|---|---|
| Size | 112.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d63a4599d772a04741a1c596e208df7a3f550b94e9cdb919fd5cba736197d061
|
|
BLAKE2b-256 checksum How to use checksums |
60de7b103b3cf551ba061995f5aea6c02429b3613fd0c7e6c7e57a193a070108
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for how-wrong-is-your-mmm 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.