Marketing Mix Modeling with Robyn

Marketing Analytics
Optimization
R
Multi-channel marketing budget optimization with Meta’s Robyn framework

Context & Problem

Business question: How should a CMO reallocate marketing budget to maximize sales?

In a context where marketing budgets are scrutinized and attribution becomes increasingly complex (end of third-party cookies, multiplication of channels), Marketing Mix Modeling (MMM) is experiencing renewed interest.

MMM allows you to:

  • Measure the incremental impact of each marketing channel on sales
  • Account for saturation effects (diminishing returns)
  • Model carryover effects (adstock) - the impact of a campaign that persists over time
  • Optimize budget allocation across channels

Approach & Methodology

Robyn Framework

I used Robyn, the open-source framework developed by Meta (Facebook), which combines several advanced techniques:

# Robyn model architecture
# 1. Time decomposition with Prophet
#    - Trend
#    - Seasonality (weekly, annual)
#    - Holiday effects

# 2. Marketing variable transformations
#    - Geometric adstock: effect(t) = spend(t) + ΞΈ Γ— effect(t-1)
#    - Logistic saturation: response = Ξ± / (1 + exp(-Ξ² Γ— spend))

# 3. Ridge regression to avoid overfitting

# 4. Multi-objective optimization with Nevergrad
#    - Minimize NRMSE (prediction error)
#    - Minimize DECOMP.RSSD (decomposition consistency)

Channels Analyzed

  • Google Ads: Search and Display
  • Facebook Ads: Social and remarketing
  • LinkedIn: B2B
  • Email: Newsletters and promotions
  • Organic: SEO and direct traffic

Complete Workflow

Raw data β†’ Feature Engineering β†’ Robyn Training β†’ Model Selection β†’ Budget Optimization
  1. Data collection: Daily sales, spend by channel, contextual variables
  2. Feature engineering: Creating seasonality variables, special events
  3. Training: Calibrating adstock and saturation parameters
  4. Model selection: Pareto analysis (NRMSE vs DECOMP.RSSD)
  5. Optimization: Budget allocation scenario simulation

Key Results

Sales Decomposition

The model decomposes sales into:

  • Baseline: β€œNatural” sales without marketing (~60%)
  • Channel contribution: Incremental impact of each investment
  • Seasonality: Calendar-related variations

Response Curves

Each channel has a different response curve, showing diminishing returns:

  • Google Ads: High initial ROI, rapid saturation
  • Facebook: More linear curve, less saturation
  • Email: Excellent ROI but limited capacity

Optimization Recommendations

The dashboard allows simulating different scenarios:

  • Current scenario: Historical allocation
  • Optimized scenario: Rebalancing toward under-invested channels
  • Constrained scenario: Optimization with fixed budget

Demo

View Shiny Dashboard

The interactive dashboard allows you to:

  • Visualize sales decomposition
  • Explore response curves by channel
  • Simulate allocation scenarios
  • Compare marginal ROIs

Technologies

Component Technology
Language R
MMM Framework Robyn (Meta)
Time Decomposition Prophet
Optimization Nevergrad
Dashboard Shiny
Environment Management renv

Source Code

The project is organized into several components:

mmm-robyn-project/
β”œβ”€β”€ R/
β”‚   β”œβ”€β”€ 01_data_preparation.R    # Data preparation
β”‚   β”œβ”€β”€ 02_robyn_training.R      # Model training
β”‚   β”œβ”€β”€ 03_model_selection.R     # Pareto selection
β”‚   └── 04_optimization.R        # Budget optimization
β”œβ”€β”€ app/
β”‚   └── app.R                    # Shiny dashboard
β”œβ”€β”€ data/
β”‚   └── marketing_data.csv       # Input data
└── outputs/
    β”œβ”€β”€ exploration/             # EDA visualizations
    β”œβ”€β”€ robyn/                   # Model results
    └── optimization/            # Optimized scenarios

Learnings

This project allowed me to deepen:

  1. Marketing modeling: Understanding adstock and saturation effects
  2. Multi-objective optimization: Finding the right balance between accuracy and interpretability
  3. Results communication: Translating complex models into actionable recommendations

← Back to Portfolio Analysis | View Dashboard