Recast Model Technical Documentation
Introduction
Under the hood, Recast fits a statistical model to your data. The model is a Bayesian hierarchical time series model and the fitting happens via a Hamiltonian Monte Carlo (HMC) algorithm in Stan.
The documentation below covers the core parts of the statistical model as they are specified mathematically. Since there’s a lot of very dense information here, we’ll start by laying out the model's assumptions in prose before getting into the formal specification.
To start, let’s lay out a diagram of how we believe marketing performance actually works. This causal diagram is designed to help us think from first principles about 1) what are the true causal relationships we are trying to understand and 2) how we can build a statistical model that estimates the relationships of interest.
The causal diagram looks like this:
It’s complicated! Marketing is a complicated domain and there are lots of factors that impact each other in non-obvious and non-measurable ways. Our job as modelers is to build a statistical model that can estimate the most important relationships in this causal diagram in a way that’s robust and unbiased.
The Recast statistical model is a fully Bayesian generative model that attempts to capture all of these relationships in code. The core model includes thousands of lines of Stan code which we won’t walk through, and instead, we’ll outline the core components and how the pieces fit together.
Core assumptions:
The dependent variable is impacted by
Paid media performance.
Baseline non-media sales or the “intercept”.
“Spikes”: exogenous shocks, usually from holidays, promotions, or new product launches.
“Contextual variables” which have their impacts through the intercept and paid media variables.
Paid media performance has the following characteristics
Marketing performance can change over time, but the changes must be smooth according to a Gaussian process
The effect of marketing is shifted in time according to a negative binomial distribution
There are diminishing marginal returns to increased investment in Paid media. I.e., marketing channels “get saturated”
Marketing performance may be impacted by seasonal trends (i.e., channels might get more performance in the summer vs. the winter).
The intercept has the following characteristics
The intercept changes over time, but the changes must be smooth according to a Gaussian process
The intercept may be impacted by seasonal trends (i.e., it may be higher in the summer vs. the winter).
Spikes have the following characteristics
Spikes may have pull-forward and pull-backward effects (i.e., they distort sales that were going to happen before or after the spike date)
Spikes may interact with marketing performance (you can spend more money in certain marketing channels when a promotion is happening)
Now, let’s get into the math!
Preliminaries
Time-varying coefficients
Several things change over time in Recast’s model:
The intercept
The ROIs of media channels
Crucially, as we’ll explain below, this contains two time-varying components for each channel. One is the performance of the “first dollar” of spend in the channel (and — if not indexed by spend, the equivalent “first activity”), and the other is a shared “saturation multiplier” — this will make more sense below.
The saturation multiplier
All of the parameters that change over time are assumed to follow a locally-periodic Gaussian Process. You can read more about locally periodic kernels here, but the gist is that the kernel makes three assumptions:
Today is like yesterday
Today is like one year ago
Today is more like one year ago than like two years ago
For details on our implementation of locally-periodic Gaussian processes, see our doc Mean-Zero Gaussian Processes: An Overview.
The Intercept
The functional form of the intercept is the following:
Where:
lb and ub represent the upper and lower bounds for the intercept
mean and trend represent the latent linear trend in the intercept
GP is a locally-periodic Gaussian Process
ROIs — direct and indirect
Direct effects
The effect — before time-shifting (see below for how we estimate the time-shifting) — of marketing activity in a channel c at time t is given by the following formula:
We have a section on the Hill Function below — this is how we model the “saturation” effect. The kappa term in there can be thought of as the amount that one can spend into that channel before the channel gets saturated. The beta term can be thought of as the efficiency of this saturated spend.
In turn, the kappa term is itself the product of two components:
We model a saturation term for each channel, and a multiplier term for each time step. This multiplier term is the same mentioned above – it evolves according to a locally periodic Gaussian Process, which allows for the overall saturation level across a model to go up and down with the seasons and over time.
The beta term is itself indexed by channel and time step — we model it with a locally periodic GP for each channel.
The time-varying multiplier
The specification for the time-varying multiplier is as follows:
where:
lb and ub represent the upper and lower bounds for the multiplier
mean and trend represent the latent linear trend in the multiplier
GP is a locally-periodic Gaussian Process
are saturation spikes, which have a parameterization detailed below and represent rapid changes in the efficacy of a channel around a promotion or holiday
Indirect effects and the difference between “demand generation” and “demand capture” channels
Recast has two different types of channels — those whose spend levels can be directly manipulated by the advertiser, and those – like branded search or affiliate — whose spend levels are essentially “taken” by the advertiser. We call these “demand generation” and “demand capture” channels, respectively.
In order to capture this dependence in induced spend in demand capture channels that is driven by activity in demand capture channels, we include the following in our model:
That is, the amount of spend in the lth demand capture channel at the tth time step is a function of:
Some baseline level of spend (the intercept term) — that evolves according to a GP
The shifted effects of each demand generation channel multiplied by an alpha coefficient for each pair of demand generation and demand capture channels
Therefore the total effect of a demand generation channel will be:
The direct effect of spend into the channel
Plus the effect of the induced spend into the demand generation channels that it influenced
Which will depend both on how strongly the demand generation channel influences that capture channel, and
How effective the capture channel is