Robyn: Continuous & Semi-Automated MMM

repository·main·Indexed 23 days ago

https://github.com/facebookexperimental/robyn

An open-source Marketing Mix Modeling (MMM) package developed by Meta Marketing Science. Robyn uses machine learning techniques, including Ridge regression and evolutionary algorithms via the Nevergrad library, to help advertisers analyze media channel efficiency, adstock rates, and saturation curves. It is available as an R package and a Python package (robynpy), featuring tools for budget allocation, Pareto-optimal solution modeling, and response curve calculation.

Tokens
23.5K
Snippets
17
Records
136
Agent score
80%

What's inside Robyn

  1. What is Robyn?

    main

    Robyn is an open-source, AI/ML-powered Marketing Mix Modeling (MMM) package developed by Meta Marketing Science. It is designed for granular datasets with numerous independent variables, making it particularly effective for digital and direct response advertisers with rich data sources.

    Key technical components include:

    • Hyperparameter Optimization: Uses a multi-objective evolutionary algorithm.
    • Trend & Seasonality: Employs time-series decomposition.
    • Model Fitting: Uses Ridge regression.
    • Budget Allocation: Utilizes a gradient-based optimizer.
  2. What is Marketing Mix Modeling (MMM)?

    main

    Marketing Mix Modeling (MMM) is a privacy-friendly, data-driven statistical analysis used to quantify the incremental sales impact and ROI of both marketing and non-marketing activities.

    It is an econometric model that aims to quantify the impact of various factors on a pre-defined KPI (such as sales or website visits). MMM is used to understand how to allocate marketing budgets across different channels, products, and regions, and can be used to forecast the impact of future campaigns.

    Key strengths include:

    • Privacy-friendly: Uses aggregated data (e.g., campaign level) rather than user-level data, making it resilient to signal loss.
    • Holistic: Measures the combined impact of all marketing channels (online and offline) and non-marketing factors (price, promotion, seasonality, distribution) in a single analysis.
    • Flexible: Can be adjusted for different business types and KPIs (revenue, units sold, etc.).
  3. Use organic variables for non-paid marketing activities

    main

    You can use organic_vars to model marketing activities that do not have a direct media spend. These variables are treated similarly to paid media: they are subject to carryover (adstock) and saturation transformations.

    Typical examples include:

    • Reach or impressions on blog posts
    • Impressions on organic/unpaid social media
    • SEO improvements
    • Email campaigns
    • Reach on User Generated Content (UGC)
  4. Understand Saturation (Diminishing Returns)

    main

    Saturation models the hypothesis that each additional unit of advertising investment increases response at a declining rate. Robyn implements the Hill function to transform media variables into S- or L-shaped saturation curves.

    Hill Function Formula: media_saturated_j = 1 / (1 + (gamma_j / media_adstocked_j) ^ alpha_j)

    Key Parameters:

    • alpha: Controls the shape of the curve.
      • Larger alpha $\rightarrow$ S-shape.
      • Smaller alpha $\rightarrow$ C-shape.
      • Recommended bounds: c(0.5, 3).
    • gamma: Controls the inflection point.
      • Larger gamma $\rightarrow$ later inflection point.
      • Recommended bounds: c(0.3, 1).

    Understanding the marginal response (the first derivative of the curve) is critical for budget allocation, as it represents the 'next dollar response'.

  5. Interpret Volume Contribution, ROI, and Spend vs. Effect

    main

    Robyn provides several metrics to evaluate channel performance:

    • Volume Contribution: The incremental sales driven by a specific variable. For example, a 2.2% contribution for Facebook means Facebook drives 2.2% of total sales.
    • Share of Spend: The relative spending of each channel.
    • Share of Effect: Equivalent to volume contribution (how much incremental sales were driven by each channel).
    • ROI (Return on Investment): The efficiency of a channel, calculated as: Incremental Revenue / Spend.

    Decision Making Strategy:

    • High ROI but low contribution/spend: Indicates a potential opportunity to increase spend, as the channel is efficient and likely not saturated.
    • Low ROI but high contribution/spend: Indicates a major driver of performance. Even if it seems underperforming, consider optimizing the channel rather than immediately cutting spend, as it is a significant driver of total volume.
  6. Apply Adstock transformations

    main

    Adstock reflects the carryover and decay effects of advertising over time. Robyn provides two main techniques:

    1. Geometric Adstock

    Simple and fast. It uses a single parameter, theta, representing a fixed decay rate.

    • Example: theta = 0.75 means 75% of impressions from period 1 carry over to period 2.
    • Recommended bounds:
      • TV: c(0.3, 0.8)
      • OOH/Print/Radio: c(0.1, 0.4)
      • Digital: c(0, 0.3)

    2. Weibull Adstock

    More flexible and better for modern media (like Facebook), but slower to run as it optimizes two parameters: shape and scale.

    Weibull CDF (Cumulative Distribution Function)

    • Shape: Controls the decay curve shape. Recommended bound: c(0.0001, 2). (Larger = S-shape, Smaller = L-shape).
    • Scale: Controls the inflection point. Recommended bound: c(0, 0.1).

    Weibull PDF (Probability Density Function)

    Offers lagged effects.

    • Shape: Recommended bounds: c(0.0001, 10). For strong lagged effects, use c(2.0001, 10).
      • shape > 2: Curve peaks after $x=0$ (enables lagged effect).
      • 1 < shape < 2: Curve peaks after $x=0$ with infinite positive slope at $x=0$.
      • shape = 1: Reduces to exponential decay.
      • 0 < shape < 1: Curve peaks at $x=0$ with increasing decay.
    • Scale: Recommended bound: c(0, 0.1).
  7. Apply Saturation transformations using the Hill function

    main

    Robyn uses the Hill function to model the saturation effect (diminishing returns) of media channels. The function uses two parameters:

    • alpha: Controls the shape of the curve.
      • Recommended bound: c(0.5, 3).
      • Larger alpha $\rightarrow$ S-shape.
      • Smaller alpha $\rightarrow$ C-shape.
    • gamma: Controls the inflection point.
      • Recommended bound: c(0.3, 1).
      • Larger gamma $\rightarrow$ later inflection point in the response curve.
  8. How model selection works with evolutionary algorithms

    main

    Robyn uses the Nevergrad library to perform multi-objective hyperparameter optimization via evolutionary algorithms. This process outputs a set of Pareto-optimal solutions.

    Robyn optimizes based on multiple loss functions:

    • NRMSE: The standard loss function for optimization.
    • DECOMP.RSSD: A business logic "decomposition distance" used to steer the model toward more realistic decomposition results.
    • MAPE.LIFT: A third loss function added specifically during the calibration phase.

    The optimization process aims to find the best trade-off between these metrics, often visualized as a Pareto front.

  9. Calibrate average effect size with causal experiments

    main

    Robyn allows you to introduce causality into your Marketing Mix Model (MMM) by calibrating the model using results from Randomized Controlled Trials (RCTs), such as Sales experiments (e.g., Meta/Google Conversion Lift) or Geo experiments.

    Calibration is implemented as a third objective function in Robyn's multi-objective optimization, alongside prediction error and business error. The specific metric used is MAPE.LIFT, which measures the difference between the predicted media contribution and the ground truth provided by the experiment.

    To perform this calibration, you must provide a dataframe containing the experiment results to the robyn_inputs() function.

  10. Use Prophet for time-series decomposition in Robyn

    main

    Robyn integrates Meta's Prophet to automatically decompose time-series data into trend, seasonality, holiday, and weekday impacts. This improves model fit and forecasting without requiring you to manually create dummy variables for every seasonal event.

    Key components handled by Prophet include:

    • Trend: Long-term, slowly evolving movements (e.g., market growth or economic shifts).
    • Seasonality: Repeating short-term cycles, typically yearly (e.g., summer sales peaks).
    • Weekday: Repeating weekly patterns (requires daily data).
    • Holiday/Event: Specific dates with high impact (e.g., national holidays, mega sales days).

    If you do not have custom trend or seasonality data, it is recommended to use Prophet for at least the trend and seasonality components.

  11. Categorize input variables for Robyn MMM

    main

    When preparing data for Robyn, you must categorize your variables into three types. This categorization determines which transformation techniques (adstock and saturation) are applied:

    • paid_media_vars: Media variables with clear marketing spend. These must be continuous data. Robyn applies adstock and saturation transformations to these. It is recommended to use exposure metrics (impressions, clicks, GRPs) instead of spend. If spend is used, Robyn fits a nonlinear model (Michaelis Menten function) to relate exposure to spend.
    • organic_vars: Marketing activities without clear spend (e.g., newsletters, social media posts). These can be categorical or continuous. Robyn applies adstock and saturation transformations to these.
    • context_vars: Non-media variables that explain the dependent variable (e.g., competitor activity, price, macroeconomic factors). These can be categorical or continuous. These variables do not undergo transformation and are expected to have a direct impact.

    Note on Categorical Data: If organic_vars or context_vars are categorical, you must specify them in the factor_vars parameter.

  12. How Robyn performs semi-automated model selection

    main

    Robyn uses Meta's Nevergrad evolutionary optimization platform to automate the search for optimal hyperparameters. Instead of manual trial and error, Robyn performs multi-objective optimization to find a set of Pareto-optimal models by minimizing two primary objectives:

    1. Model fit: Minimizing the prediction error, measured by NRMSE (Normalized Root Mean Square Error).
    2. Business fit: Minimizing the decomposition distance, measured by DECOMP.RSSD (Decomposition Root-Sum-Square Distance). This ensures the relationship between spend share and coefficient decomposition share is realistic (e.g., preventing a channel with tiny spend from showing a massive effect).

    The output is a set of Pareto-optimal models (the 'Pareto front') representing the best trade-offs between these two objectives. The user must then manually select the final model based on business context.