How to implement marketing mix modelling (using Facebook’s Robyn)

If you’re a marketing manager trying to figure out which channels actually drive sales, you’re not alone. I’ve been there – staring at spreadsheets, wondering if that Facebook campaign really worked or if sales just went up because it was Black Friday.

That’s where Marketing Mix Modelling (MMM) comes in, and today I’ll show you how to implement it using Meta’s Robyn.

Let me be honest upfront – this is fairly hard to implement. MMM isn’t the low hanging fruit of marketing analytics. There are many easier analyses you can run first (like simple attribution reports, or channel-specific ROAS calculations). If you’re looking for quick wins, start there. Also, you need minimum spend thresholds to get meaningful results – typically at least $10,000 per month per channel, though this varies by business.

What is marketing mix modelling?

Marketing Mix Modelling is a statistical analysis technique that helps you understand how different marketing activities contribute to sales. Think of it as a way to untangle the mess of marketing data and see what’s really working.

Here’s what MMM does for you:

  • Shows which channels drive the most sales
  • Reveals when you’re spending too much (diminishing returns)
  • Accounts for external factors like seasonality
  • Helps predict future performance

Unlike attribution models that track individual customer journeys, MMM looks at the bigger picture. It analyses aggregated data over time to spot patterns and relationships.

Why Robyn?

Meta developed Robyn as an open-source MMM solution. It’s free, relatively user-friendly, and backed by one of the biggest names in digital advertising. The tool uses advanced statistical methods (Bayesian inference and Ridge regression) but packages them in a way that doesn’t require a PhD in statistics.

Models you’ll encounter in MMM

Before we jump into implementation, let’s clarify the different modelling approaches you’ll see:

Adstock transformation: This captures how advertising effects decay over time. Your TV ad doesn’t stop working the moment it airs – people remember it for days or weeks. Robyn uses two main approaches:

  • Geometric adstock: Simple exponential decay
  • Weibull adstock: More flexible, can model delayed effects

Saturation curves: These show diminishing returns. Your first £10,000 in Google Ads might generate great returns, but the next £10,000 probably won’t perform as well. Robyn typically uses Hill transformation for this.

Base vs incremental: MMM separates your baseline sales (what you’d get without any marketing) from incremental sales driven by marketing activities.

Tools you’ll need

Here’s your toolkit for running MMM with Robyn:

Essential:

  • R and RStudio (free statistical software)
  • Robyn package (install directly in R)
  • Your historical data (2-3 years ideally)
  • Basic spreadsheet software (Excel or Google Sheets)

Helpful extras:

  • Python (for data preparation)
  • SQL knowledge (for pulling data)
  • Visualisation tools (Tableau, Power BI)
  • Version control (Git)

Step-by-step implementation guide

Step 1: Prepare your data

This is where most projects stumble. You need weekly or daily data for:

  • Sales or conversions (your dependent variable)
  • Marketing spend by channel
  • Impressions or other volume metrics
  • External factors (holidays, competitor activity, weather)
  • Pricing changes
  • Any other business drivers

Your data should be in a simple CSV format with one row per time period. Here’s what it might look like:

date, sales, facebook_spend, google_spend, tv_spend, price_index, is_holiday
2023-01-01, 45000, 5000, 8000, 12000, 1.0, 0
2023-01-08, 52000, 5500, 8500, 12000, 0.95, 0

Data quality matters. Check for:

  • Missing values
  • Outliers that need explanation
  • Consistent currency and metrics
  • Matching time periods across all channels

Step 2: Install and set up Robyn

First, install R and RStudio from their respective websites. Then, in RStudio, run:

install.packages("remotes")
remotes::install_github("facebookexperimental/Robyn")

Create a new project folder with this structure:

my_mmm_project/
├── data/
├── results/
└── scripts/

Step 3: Configure your model

Create a new R script and start with the basic setup:

library(Robyn)

# Set up input variables
InputCollect <- robyn_inputs(
  dt_input = your_data,
  dt_holidays = holidays_data,
  date_var = "date",
  dep_var = "sales",
  dep_var_type = "revenue",
  prophet_vars = c("trend", "season", "holiday"),
  prophet_country = "GB"
)

Now define your media variables:

InputCollect <- robyn_inputs(InputCollect = InputCollect,
  paid_media_spends = c("facebook_spend", "google_spend", "tv_spend"),
  paid_media_vars = c("facebook_imp", "google_imp", "tv_grp"),
  organic_vars = c("newsletter", "pr_mentions")
)

Step 4: Set hyperparameters

This is where you tell Robyn how to model your media effects. Don’t worry about getting these perfect – Robyn will test different combinations:

hyperparameters <- list(
  facebook_spend_alphas = c(0.5, 3),
  facebook_spend_gammas = c(0.3, 1),
  facebook_spend_thetas = c(0, 0.3)
)

These ranges let Robyn explore different saturation curves and adstock effects. See the hyperparameter guide for detailed explanations.

Step 5: Run the initial models

Now for the computational heavy lifting:

OutputModels <- robyn_run(
  InputCollect = InputCollect,
  hyperparameters = hyperparameters,
  iterations = 2000,
  trials = 5,
  outputs = TRUE
)

This will take 30 minutes to several hours depending on your data complexity. Robyn will generate thousands of models and identify the best ones.

Step 6: Select your model

Robyn will show you a selection of Pareto-optimal models. These balance different objectives like:

  • Prediction accuracy (how well it fits historical data)
  • Business sense (do the results seem reasonable?)
  • Decomposition distance (how different from other good models)

Review the one-pager outputs for each model. Look for:

  • Reasonable effect sizes for each channel
  • Sensible seasonality patterns
  • Good fit to historical data
  • Logical saturation curves

Step 7: Calibrate with experiments (optional but recommended)

If you’ve run any lift tests or geo experiments, use them to calibrate your model:

calibration_input <- data.frame(
  channel = "facebook_spend",
  liftStartDate = "2023-06-01",
  liftEndDate = "2023-06-14",
  liftAbs = 50000,
  liftPct = 0.15
)

OutputCollect <- robyn_calibrate(
  InputCollect = InputCollect,
  OutputModels = OutputModels,
  calibration_input = calibration_input
)

Learn more about calibration in Robyn.

Step 8: Generate final outputs

Once you’ve selected your model, extract the key insights:

# Get decomposition
decomp <- OutputCollect$decompCollect

# Calculate ROAS by channel
roas <- OutputCollect$xDecompAgg %>%
  mutate(ROAS = effect / spend)

# Generate diagnostic plots
robyn_plots(OutputCollect, plot_folder = "results/")

Step 9: Budget optimisation

Here’s where MMM becomes actionable. Robyn can suggest optimal budget allocation:

AllocatorCollect <- robyn_allocator(
  OutputCollect = OutputCollect,
  channel_constr_low = 0.5,  # Don't cut any channel by more than 50%
  channel_constr_up = 2,     # Don't increase any channel by more than 2x
  scenario = "max_response"
)

This tells you how to reallocate your budget for maximum impact. Check the budget allocator documentation for more options.

Step 10: Refresh and maintain

Markets change, so your model needs updating. Set up a quarterly refresh cycle:

  1. Add new data
  2. Re-run the model
  3. Compare results to previous versions
  4. Document any major shifts
  5. Adjust strategy based on findings

Common pitfalls and how to avoid them

Too little data: You need at least 2 years of weekly data. Daily data needs even longer periods.

Missing variables: Forgetting major business drivers (like big sales or product launches) will bias your results.

Over-trusting the model: MMM shows correlations, not perfect causation. Use it as one input among many.

Ignoring business context: If the model says TV drives no sales but you know your TV ads coincided with a website outage, trust your knowledge.

Setting and forgetting: Markets evolve. Refresh your model quarterly.

Making MMM work in your organisation

Start small. Pick a subset of channels or one product line for your first model. Get comfortable with the process before expanding.

Document everything. Future you (or your successor) will thank you for clear notes on data sources, assumptions, and decisions.

Share results widely. MMM insights help finance, product, and sales teams too. Create simple visualisations that non-technical stakeholders can understand.

Combine with other measurement. MMM works best alongside attribution data, brand studies, and conversion lift tests. Each method has strengths – use them together.

For more resources, check out:


Posted

in

by

Tags: