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
- Data collection: Daily sales, spend by channel, contextual variables
- Feature engineering: Creating seasonality variables, special events
- Training: Calibrating adstock and saturation parameters
- Model selection: Pareto analysis (NRMSE vs DECOMP.RSSD)
- 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
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:
- Marketing modeling: Understanding adstock and saturation effects
- Multi-objective optimization: Finding the right balance between accuracy and interpretability
- Results communication: Translating complex models into actionable recommendations