Introduction to Market Mix Modeling using Robyn

As a data scientist working on marketing analytics, one of the most common challenges I hear from clients is accurately measuring the ROI of their media investments. Marketing leaders want to know:

  • How much revenue is each channel generating?
  • What is the optimal budget allocation across channels?
  • How can we improve efficiency and drive more growth?

Answering these questions with rigor requires market mix modeling (MMM) – a technique that uses regression analysis to quantify the impact of various marketing inputs on sales or other business outcomes.

MMM has been around since the 1960s, but adoption has accelerated in recent years with the rise of big data and analytics. In fact, a recent study by McKinsey found that 68% of leading marketers now use advanced marketing mix models.

However, the traditional MMM process has some key challenges:

  1. It‘s resource-intensive, requiring significant time from data scientists and domain experts to wrangle data, build and validate models, and generate insights.

  2. Different analysts make different modeling choices, which can lead to inconsistency and bias in results.

  3. By the time insights are generated, the market has often evolved, making it difficult to act on results.

Robyn is a game-changer. Developed by data scientists and marketing analysts at Meta, Robyn incorporates best practices and automates key parts of the MMM process. This makes MMM more:

  • Efficient: Faster to build and refresh models
  • Consistent: Reduces manual decision-making and bias
  • Actionable: Enables optimization and simulation

Since launching in 2021, Robyn has been used by over 500 brands and agencies to measure and optimize their marketing. Let‘s take a closer look at how it works.

Robyn Technical Overview

At its core, Robyn is a linear regression model to predict sales (or other business outcome) as a function of media inputs and control variables. It uses Ridge regression to avoid overfitting.

What makes Robyn unique is how it handles two key MMM concepts: adstock and saturation.

Adstock and Saturation in Robyn

Adstock is the idea that advertising has a lagged effect on sales beyond the initial exposure. Robyn lets you choose between 3 adstock functions:

  1. Geometric adstock: Simple exponential decay, requiring only 1 parameter (θ)
  2. Weibull CDF: More flexible s-curve shape, with 2 parameters (shape, scale)
  3. Weibull PDF: Captures delayed response with shape > 1

Here is what the different adstock curve types look like:

Robyn uses a Bayesian optimization technique called Nevergrad to find the optimal adstock parameters and adstock function for each media variable.

The second concept Robyn accounts for is saturation – the diminishing marginal return of spending more in a channel. To model this, Robyn uses the Hill function:

$Y = \frac{X^n}{k^n+X^n}$

Where:

  • Y is the transformed media variable
  • X is the adstocked media variable
  • n is the Hill exponent, controlling curve shape
  • k is the half-saturation point

The Hill function looks like this for different values of the exponent n:

By transforming media variables with adstock and saturation functions, Robyn captures real-world media behavior and improves model fit.

Hyperparameter Optimization and Model Validation

Another key feature of Robyn is automated hyperparameter optimization (HPO). Rather than manually tuning model parameters like regularization penalties and time windows, Robyn uses Nevergrad to efficiently search the parameter space.

Nevergrad uses an evolutionary algorithm to find the optimal hyperparameters that minimize the objective function. By default this objective is a combination of 3 error metrics:

  1. NRMSE: Normalized root mean squared error, measuring model fit
  2. Decomp.RSSD: Root-sum-squared distance between spend share and coefficient share, ensuring media coefficient magnitudes are in line with spend levels
  3. MAPE Lift: Mean absolute percentage error on lift analysis, if provided

Robyn also supports cross-validation to prevent overfitting and evaluate out-of-sample model performance. By default, it uses rolling origin time series CV, but also supports k-fold cross-validation.

Robyn Implementation in R

While Robyn is designed to abstract away much of the MMM modeling complexity, data scientists still need to make key decisions on model specification. Here is a full example of using Robyn in R:

# Install and load packages
install.packages(c("Robyn", "reticulate"))
library(Robyn)  
library(reticulate)

# Set up Python environment
use_python("/usr/bin/python3")
py_install("nevergrad", pip=TRUE)

# Load simulated dataset
data("dt_simulated_weekly")

# Specify model
InputCollect <- robyn_inputs(
  dt_input = dt_simulated_weekly,
  dep_var = "revenue",
  paid_media_vars = c("tv_S","ooh_S","print_S","facebook_I","search_clicks_P"),
  paid_media_spends = c("tv_S","ooh_S","print_S","facebook_S","search_S"),
  organic_vars = c("newsletter"),
  context_vars = c("events", "competitor_sales_B"),
  adstock = "weibull_cdf",
  hyperparameters = list(
    facebook_I_alphas = c(0.5, 3),
    facebook_I_gammas = c(0.3, 1),
    facebook_I_thetas = c(0, 0.3),
    tv_S_alphas = c(0.5, 3),
    tv_S_gammas = c(0.3, 1),
    tv_S_thetas = c(0.3, 0.8)
  )
)

# Run initial model
OutputModels <- robyn_run(
  InputCollect = InputCollect, 
  cores = NULL,
  iterations = 2000, 
  trials = 5,
  ts_validation = TRUE
)  

# Analyze model output
print(OutputModels)

OutputCollect <- robyn_outputs(
  InputCollect = InputCollect, 
  OutputModels = OutputModels, 
  select_model = NULL,
  export = "decomp.csv"
)

# Get budget recommendation  
AllocatorCollect <- robyn_allocator(
  InputCollect = InputCollect, 
  OutputCollect = OutputCollect,
  scenario = "max_historical_response",
  channel_constr_low = c(0.5, 0.5, 0.5, 0.8, 0.7), 
  channel_constr_up = c(2, 1.2, 1.5, 1.5, 1.2),
  export = "budget_reco.csv"
)

print(AllocatorCollect)

Let‘s break this down:

  1. Install and load the required R packages. Robyn uses Python under the hood for some functions, so you also need to set up a Python environment using reticulate.

  2. Load your data into a data.frame or data.table. Here we use the built-in dt_simulated_weekly for this example.

  3. Use robyn_inputs() to specify the model configuration:

    • Dependent variable to predict (dep_var)
    • Media spend variables (paid_media_vars, paid_media_spends)
    • Other predictors like organic and contextual variables
    • Hyperparameter ranges for media adstock/saturation
  4. Run the initial model using robyn_run(). Set the number of trials and iterations to control the HPO search. Enable time series validation with ts_validation.

  5. View model output with print(OutputModels). This shows error metrics for each trial.

  6. Generate additional charts and analyses with robyn_outputs(). This produces things like media decomposition, response curves, and model fit.

  7. Finally, get recommended budget allocations by channel with robyn_allocator(). Specify channel_constr_low and channel_constr_up to set bounds on the minimum/maximum spend levels.

After the initial model build, you can save your selected model and update it with robyn_refresh() as new data becomes available.

Robyn Case Study

To illustrate the impact Robyn can have for marketers, consider this disguised client case study.

A mid-sized e-commerce company came to us spending about $50M per year on a mix of online and offline media:

  • Linear TV: $20M
  • Paid Search: $15M
  • Facebook: $5M
  • YouTube: $5M
  • Affiliate: $5M

They had been running MMMs using spreadsheet analysis but wanted a more sophisticated and granular approach. After importing 3 years of weekly data into Robyn, we generated the following decomposition of media-driven sales:

Channel Spend Revenue ROAS
TV $20M $50M 2.5
Paid Search $15M $75M 5.0
Facebook $5M $20M 4.0
YouTube $5M $15M 3.0
Affiliate $5M $10M 2.0

Overall the marketing portfolio was driving $170M in incremental revenue, a 3.4x return on ad spend (ROAS). However, there was wide variation in efficiency by channel.

Paid Search was performing well, while Linear TV and Affiliate were less efficient. We then ran robyn_allocator to optimize the budget mix going forward, setting a constraint of +/- 20% on each channel.

The result:

By shifting dollars from TV into Paid Search and Facebook, Robyn estimated we could drive an additional $15M in revenue (+ 9%) while staying within +/- 20% of prior spend by channel.

We tested this reallocation with a geo-matched market test, and the results validated the 9% lift predicted by Robyn. The client has since rolled out the new budget allocation, improving ROAS by 11% year-over-year.

Limitations and Future of Robyn

While Robyn is a powerful tool for MMM, it‘s important to also understand its limitations:

  1. As a linear regression model, it doesn‘t capture more complex, non-linear relationships that techniques like gradient boosting or neural networks can. Meta is actively working on Robyn alternatives with more sophisticated ML.

  2. MMM in general is backwards-looking and doesn‘t account for changes in market conditions, creative quality, competitor activity, etc. It should be combined with experimental design (e.g. geo tests) to validate findings.

  3. Robyn is open-source but requires non-trivial setup and data prep to implement. It‘s not a fully automated, out-of-the-box solution.

  4. Robyn provides an interface for R users today. Support for Python is on the roadmap to make it accessible to a wider audience.

Despite these limitations, Robyn adoption has grown quickly. Meta itself used Robyn to model $250B in ad spend across 150 countries. Companies like Unilever, Dentsu, and Colgate have also deployed Robyn at scale.

Looking ahead, I expect continued growth in MMM – and Robyn usage – as the $600B+ global advertising industry becomes increasingly ROI-focused. Newer applications of MMM, like multi-touch attribution, will also expand its use cases in digital channels.

With the rise of privacy regulations and the death of the 3rd party cookie, MMM provides a privacy-safe way for marketers to measure and optimize their investments. A recent Gartner study found that 54% of CMOs expect to increase MMM spend over the next 1-2 years.

As MMM grows in adoption, I predict that Robyn and other open-source tools will coexist with commercial offerings to serve different business needs. Regardless of the specific software, the key trends of automation, interpretability, and actionability will define the future of MMM.

Conclusion

Marketing Mix Modeling has a long history, but open-source tools like Robyn are helping modernize and democratize this powerful technique. By codifying MMM best practices and streamlining the modeling process, Robyn makes it easier for marketers to assess performance and optimize their media mix.

While not a complete replacement for human expertise, Robyn and similar tools will play an important role in optimizing the trillions in marketing spend deployed worldwide. I expect to see continued investment and innovation in this space as marketing analytics becomes an even more essential lever for growth.

If you‘re a data scientist or marketing analyst looking to uplevel your marketing measurement capabilities, I highly recommend giving Robyn a try. The combination of sophisticated ML and practical business application makes it an invaluable tool to have in your marketing data science toolkit.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Similar Posts