name: mmm-workflow
description: Media-mix workflow with the built-in media-mix regressions — search adstock decays with an lhs sweep, bind the winner as the Hill fit, score contributions and reallocate budget with compose optimize, all in one compose call; or fit the Bayesian model for intervals. The one-call recipe, decay intervals, lift tests as likelihood or prior, what to trust.
kind: design
type: guide
applies_to: compose
requires: [REG_MMM_HILL, WIN_DISTRIBUTED_LAG, WIN_LAG, ATTR_FORMULA, capability:for_each, capability:compose_sweep_sampling, capability:compose_sweep_bind, capability:compose_optimize]
covers: [Bayesian media mix, lift test prior, lift test likelihood, media mix, MMM, adstock decay, Hill curve, marginal ROI, budget reallocation, one-call recipe, sweep_axis, response]
Media-mix workflow
Goal: per-channel decay, response curve and a budget split that equalises marginal ROI. The decay is nonlinear in the adstock, so it is searched; the curves are fitted jointly by REG_MMM_HILL. One compose call does it all: no template, no second call, no label parsing.
The one call
sweep:lhs(compose-sweep-sampling), one axis per channel decay with arange(TV-like[0.3, 0.8], digital[0, 0.4]; keepmaxbelow 1),samplesin the thousands,rank{by: "regressions.mmm.holdout.rmse", order: "asc"}. Each slot: oneWIN_DISTRIBUTED_LAGper channel (kernel: geometric,decay: {"$var": "tv"},normalize: false), then oneREG_MMM_HILLnamedmmmwithparams.channelsand aholdouton the last weeks. Use enough samples for the channel count and check the best slots agree on the decays.MaxComposeSlotscounts the samples plus the explicit slots: raiseOptions.Limits.MaxComposeSlots(CLI--limit max_compose_slots=2001).fits:[{"name": "mmm", "from_sweep": {"regression": "mmm"}}]refits the winning slot’s regression, its holdout kept (compose-sweep-bind).requests: one contribution slot. A window’sdecayis a literal, so rebuild each adstock at the winner’s decay: oneWIN_LAGitem (ordered by week) fanned out withfor_eachover channel × lag1..max_lag, label{{ch}}_l{{lag}}(params: {offset: {"$var": "lag"}, default: 0},item-fan-out), then anATTR_FORMULAper channel labelledtv_ad,tv + d * (tv_l1 + d * (tv_l2 + … + d * tv_l13))withdwritten assweep_axis("mmm", "tv"), thencoef("mmm", "tv_ad") * hill(tv_ad, coef("mmm", "k:tv_ad"), coef("mmm", "s:tv_ad")).optimize: maximise the summed steady-state curves,response("mmm", "tv_ad", tv) + …, undersum(spend) = budget(compose-optimize). Current spend, bounds and the budget are your own figures inparams.
Run order: the sweep slots, the rank, the bound fit, then optimize and the contribution slot. The winning decays are ranking[0].axes, typed numbers. At the optimum every free channel’s marginal equals the budget multiplier.
Steady-state response
response(fit, channel, spend) = beta · hill(m · spend, k, s): beta, k, s the fit’s <ch>, k:<ch>, s:<ch> coefficients (Bayes: posterior means on its own curve; a geo panel’s population, or a 4th geo argument’s own, mmm-bayes-model), m the sum of the channel’s adstock kernel weights over lags 0..max_lag — the level a constant spend of 1 settles to (geometric: (1 - d^(max_lag+1)) / (1 - d); normalised: 1). It reads the fit’s own adstock record, never a default: a Hill channel that is one WIN_DISTRIBUTED_LAG label (sweep winner included) or fitted by params.adstock, every Bayes channel, or an inline model’s declared adstock. Any other channel is PULSE_MODEL_TERM_UNKNOWN adstock_unknown (details.channel; predict too when the fit and channel are literals, except on a from_sweep fit, judged at run). Works in optimize objectives, constraints and bounds and in formulas. hill() is Hill only: read other curves through response().
Contribution by quarter
Add groups (GROUP_DATE on a date field, params.component: "quarter") and one AGG_SUM per channel over its contribution label to the contribution slot. An aggregation reading a post-window label runs the slot windows-first (windows-first): the lags, adstock and contribution are computed per week, then summed per quarter, and the rows are quarters. Weight the aggregations, never the request: a window has no weighted form.
Bayesian route vs LM/sweep route
- LM/sweep (above): fast (seconds per fit), scores holdout, saves and feeds
compose optimize. Decay is a sweep axis (betas, k, s decay-conditional), orparams.adstockfits it, with SE (op-reg-mmm-hill). REG_MMM_BAYES(op-reg-mmm-bayes): one fit adstocks raw spend and returns ROI, mROI and contribution intervals that include decay uncertainty; about 35 s per default fit. Withreturn_drawsit saves, scores and feedsoptimizeover its draws (posterior,mmm-bayes-posterior). Needsorder.fieldas contiguous integers (a date istime_gap).- Pick the sweep to allocate budget, Bayes to say how sure you are. Reading an interval: an always-on channel is the hardest to identify and gets a wide interval, so read its width, not its centre. Check
diagnosticsfirst (Strictfails on a sampler warning).
Lift tests: likelihood or prior
- Likelihood (preferred):
params.lift_tests[{channel, start, end, spend_delta, lift, se}]scores the model’s change in the outcome over the test’s periods (no carry-over pastend) against the measuredlift, in outcome units (mmm-bayes-model): the experiment’s own estimand. - Prior:
priors.<channel>.roilognormal,mu = ln(ROI),sigma ≈ ln(upper/lower)/3.3(90% interval). Estimands must match: the model’s ROI is the whole fitted period against zero spend, a short geo test is not, so widensigma; data can overrule it. - One experiment, one route: a channel with both warns
PULSE_MMM_LIFT_PRIOR_OVERLAP(evidence counted twice).
Intervals and trust
- Decay: a sweep has no SE; report the near-best ranks’ decays (
ranking[i].axes), or fitparams.adstock. For beta intervals,resamplean authored fit at the winning decays: on the sweep regression it would run in every slot. - Curves: an underfunded channel’s k and s are weakly identified; trust its ROI, not its k.
- Check
starts_agreeingon the optimize result. - Known truth (a synthetic cohort): declare it as an
inlinemodelsentry (numbers may beparams.<name>) and run the sameoptimizeobjective over it beside the fit (compose-optimize).
See
op-reg-mmm-hill · op-reg-mmm-bayes · mmm-bayes-model · compose-sweep-sampling · compose-sweep-bind · compose-optimize · item-fan-out · regression-model-options · windows-first