Professional Documents
Culture Documents
Fundación Universitaria del Área Andina, VIGILADA MINEDUCACIÓN. Más información en www.areandina.edu.co
Report this ad
By Deepesh Singh
From the previous example we can see that the effectiveness of any ad decays with time. The decay
rate depends totally on business rules. The decay rate will be higher if frequency of ad is lesser and
vice versa. So the decay rate depends on length of the ad, frequency and number of impressions.
Frequency may be very high but customers are not watching that particular channel. So impressions
will be lesser. There might be other factors as well. After discussion we can find the decay rate.
Generally the effect of any ad becomes 0 after 2-3 weeks. So we will consider a window of 2 weeks
only.
Let’s start the code.
From the understanding of the previous example, in my code I will consider effect rate which is vice
versa of decay rate. If decay rate is 0.8 for the 2nd week then the effect rate of previous week’s ad on
2nd week will be 0.2.
Now there is inbuilt function “Filter” in R which can be used. Read more about the filter function
here (http://stackoverflow.com/questions/14372880/simple-examples-of-filter-function-recursive-
option-specifically). In that case, only one week’s effect can be carried forward but we want to
consider 2 weeks. According to our formula;
A(t) = X(t) + AdStock Rate_Week1 * A(t-1) + AdStock Rate_Week2 * A (t-2)
where,
A(t) = Cumulative effect
X(t) = Base effect
A(t-1) = Previous time period effect (last week)
A(t-2) = Last 2nd week’s effect
AdStock Rate_week1 = last 1st week’s effect
AdStock Rate_week2 = last 2nd week’s effect
So we can’t use filter function directly here. We will use our own function. Let’s create a data-set with
number of impression in each week.
1 abc < data.frame(1:6)
2 abc$b < 0
3 colnames(abc) < c ("Weekly impression","Effect")
Now let’s apply our function to calculate ad impression on 2nd,3rd and so on weeks.
1 rate1 = 0.5
2 rate2 = 0.2
3 for (i in 1:nrow(abc)){
4 if (i ==1)
5 abc[i,2] < abc[i,1]
6 else if (i == 2)
7 #Effect = impression + last week effect * decay rate
8 abc[i,2] < abc[i,1] + (abc[i1,2] * rate1)
9 else
10 #Effect = impression + last week effect * decay rate
11 abc[i,2] < abc[i,1] + (abc[i1,2] * rate1) + (abc[i2,2]*rate2)
12 }
1 abc$effect2 < filter(abc$Data1, filter = 0.5, method = "recursive")
As you can see “Filter” is considering only last week’s effect but we need to consider last 2 weeks’
effect as per our business requirement. Our job doesn’t end here. We need to make decay rate (effect
rate) very carefully as different promotion activity would have different decay rate. For example TV
ad will last longer than email ad.
Please comment below your thoughts and let me know if you can improve this article.
Signature
Deepesh Singh (https://plus.google.com/+deepeshsingh?rel=author)
Advertisements
Report this ad
Report this ad
This entry was posted in Advertisement Analysis, Programing & Software and tagged AdStock, Data
analyst, Filter function, Loop in r, Marketing mix modeling, programming, R. Bookmark the
permalink.
1. Gabriel Leão
March 31, 2017 at 8:17 AM
When i applied
> abc$effect2 <- filter(abc$Data1, filter = 0.5, method = "recursive")
i received:
Error in ts(x) : 'ts' object must have one or more observations
Can you say me why?
Reply
Deepesh Singh
March 31, 2017 at 10:02 PM
Hi, Gabriel, the first thought that striking my mind is “filter = 0.5”. Here filter defines like AR
or MA values means how many lag. So it should be an integer. Please try integer value and try
again.
Reply
2. Anonymous
February 23, 2018 at 10:41 PM
Try this
abc$effect2 <- filter(abc$"Weekly impression", filter = 0.5, method = "recursive")
Reply
3. Tomasz Kubicki
April 3, 2018 at 4:45 PM
Actually you can use filter() as it allows you to pass vector of filter coefficients, not only a single
one. You get the same effect as with your ‘for’ loop with “`abc$effect <- filter(abc$`Weekly
impression`, filter = c(0.5, 0.2), method = "recursive")“`.
Reply
4. TK
April 3, 2018 at 4:48 PM
Actually you can use filter() as it allows you to pass a vector of filter coefficients, not only a single
one. You get the same results as your ‘for’ loop with “abc$effect <- filter(abc$`Weekly impression`,
filter = c(0.5, 0.2), method = "recursive")".
Reply
__PRESENT