Media Mix Models: A Bayesian Approach with PyMC

Artificial Intelligence Association of Lithuania - AI Lithuania MeetUp

Dr. Juan Orduz

Outline

  1. Introduction MMM

  2. Example: Simulated Use Case

    2.1 Data Generating Process

    2.2 Model Specification

    2.3 Results

  3. References

Media Optimization is Hard

Media Mix Models

  • Media Mix Models (MMM) are used by advertisers to measure the effectiveness of their advertising and provide insights for making future budget allocation decisions.

  • Media mix models are also used to find the optimal media mix that maximizes the revenue under a budget constraint in the selected time period.

Marketing Measurement

%%{init: {"theme": "dark", "themeVariables": {"fontSize": "32px"}, "flowchart":{"htmlLabels":false}}}%%
flowchart LR
  Experimentation("Experimentation") --> MMM("Media Mix Model")
  MMM --> Attribution("Attribution")
  Attribution --> Experimentation

Offline Media Experimentation

Funnel Effects: Causality

“When an ad channel also impacts the level of another ad channel, using a model like in the baseline above, which simultaneously estimates the impact of all ad channels in one equation, will lead to biased estimates.”

We need to draw the DAG!

We need to do a causal analysis to define the causal connections (DAG) and fit the model accordingly so that we do not induce biased estimates.

Funnel effects: Causality

MMM in Practice

MMM to Create Business Value

  • A MMM will not provide business value by itself.
  • It was to be complemented with a strategy and education.
  • Learn and iterate.

MMM Modern Approaches: Bayesian Modeling

  • Conceptually transparent interpretation of probability.
  • Uncertainty quantification.
  • Allows to explicitly include prior knowledge in the model.
  • Flexible and suited for many applications in academia and industry.

%%{init: {"theme": "dark", "themeVariables": {"fontSize": "28px"}, "flowchart":{"htmlLabels":false}}}%%
flowchart LR
  Prior("Prior") --> Data("Data")
  Data --> Posterior("Posterior")

Simulated Data: Two Media Input

Simulated Data: Media Transformations

Simulated Data: Media Contributions

Simulated Data: Trend and Seasonality Components

Seasonal and trend components.

Target variable: linear combination of media contribution, trend, seasonality and Gaussian noise.

Model Specification

\[ y_{t} = \text{intercept} + \sum_{m=1}^{M}\beta_{m}f_{\theta}(x_{m, t}) + \sum_{c=1}^{C}\gamma_{c}z_{c, t} + \varepsilon_{t}, \]

  • \(x_{m, t}\): media input data (e.g. impressions or total costs)
  • \(f_{\theta}\): media transformation function (e.g. adstock and saturation) which depends on a parameter \(\theta\)
  • \(z_{c, t}\): control variables (e.g. trend and seasonality)
  • \(\varepsilon_{t}\): Gaussian noise

PyMC Model

with pm.Model(coords=coords) as self.model:
    # --- Priors ---
    intercept = pm.Normal(name="intercept", mu=0, sigma=2)
    beta_channel = pm.HalfNormal(
        name="beta_channel", sigma=2, dims="channel"
    )
    alpha = pm.Beta(name="alpha", alpha=1, beta=3, dims="channel")
    lam = pm.Gamma(name="lam", alpha=3, beta=1, dims="channel")
    sigma = pm.HalfNormal(name="sigma", sigma=2)
    # --- Parametrization ---
    channel_adstock = pm.Deterministic(
        name="channel_adstock",
        var=geometric_adstock_vectorized(
            x=channel_data,
            alpha=alpha,
        ),
        dims=("date", "channel"),
    )
    channel_adstock_saturated = pm.Deterministic(
        name="channel_adstock_saturated",
        var=logistic_saturation(x=channel_adstock, lam=lam),
        dims=("date", "channel"),
    )
    channel_contributions = pm.Deterministic(
        name="channel_contributions",
        var=channel_adstock_saturated * beta_channel,
        dims=("date", "channel"),
    )
    mu = intercept + channel_contributions.sum(axis=-1)
    # --- Likelihood ---
    pm.Normal(
      name="likelihood", mu=mu, sigma=sigma, observed=target, dims="date",
    )

PyMC Model

PyMC Model: Components

PyMC Model: Parameter Recovery

We recover the parameters from the data generation process!

PyMC Model: Media Contribution

PyMC Model: ROAS Estimation

PyMC-Marketing

PyMC Models and Custom Transformations

References

Bayesian Media Mix Models

Marketing + Bayes + Causal Inference

Thank you!

juanitorduz.github.io