Adstock in Marketing Mix Models R code

by gatekeeper on 14.06.2020

The effect of marketing effort is mostly spread over time. The contribution of advertising expenditures to sales is not only a function of the current period, but also depending on the levels of previous periods.

Let us take a look at some of the key drivers of media reach — TV. The total amount gross rating points (Adstock of present and past efforts) can be generally summarized as follows:

Adstock = T + a.At‑1,where T represents the current GRP level and a — the retention rate/constant fraction of the GRP amount in the previous period.

In case you want to compute some of the variables, especially the retention rate, by R code, you can follow the example I have created:

Data = read.csv(file.choose(), header = TRUE)
summary (Data)


plot(Data$TV, Data$Sales, main = "TV Salas Chart ",
     xlab = "TV ", ylab = "Sales",
     pch = 19, frame = FALSE)

plot(Data$Price, Data$Sales, main = "Price Salas Chart",
     xlab = "Price ", ylab = "Sales",
     pch = 22, frame = FALSE)

adstock <- function(x, rate=0){
  return(as.numeric(stats::filter(x=x, filter=rate, method="recursive")))
mod <- nls(Sales ~ b1+ b2*adstock(TV, rate)+b3*Price, data ​= Data, 
start = list(b1 = 1,b2 = 1, rate = 0.0, b3 = 0))


The code would provide you:

-basic information about variables in your dateset

-scatter plot of data is generated with TV/Price as the independent variable and Sales as the dependent variable

-view the results of the model

Leave a Reply

Your email address will not be published. Required fields are marked *