R的AdStock转型

时间:2018-05-04 19:45:41

标签: r for-loop statistics exp data-transform

我在这里引用这个文件: https://mpra.ub.uni-muenchen.de/7683/4/Adstock

在第6页上有一个AdStock Transformation的公式如下: enter image description here

我找到了一个R代码,可以在下面重现这个adstock转换: https://analyticsartist.wordpress.com/2013/11/02/calculating-adstock-effect/

enter image description here

R-Code:

adstock_rate = 0.50
advertising = c(117.913, 120.112, 125.828, 115.354, 177.090, 141.647, 137.892,   0.000,   0.000,   0.000,   0.000, 
            0.000,   0.000,   0.000,   0.000,   0.000,   0.000, 158.511, 109.385,  91.084,  79.253, 102.706, 
            78.494, 135.114, 114.549,  87.337, 107.829, 125.020,  82.956,  60.813,  83.149,   0.000,   0.000, 
            0.000,   0.000,   0.000,   0.000, 129.515, 105.486, 111.494, 107.099,   0.000,   0.000,   0.000, 
            0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000,   0.000)

adstocked_advertising = numeric(length(advertising))
adstocked_advertising[1] = advertising[1]
for(i in 2:length(advertising)){
  adstocked_advertising[i] = advertising[i] + adstock_rate * 
adstocked_advertising[i-1]
}

情节:

enter image description here

当我尝试使用第6页的公式时,我的输出看起来有所不同,看起来并不准确。有谁知道如何重现第一个公式而不是最后一个?

这是我的尝试:

adstocked_advertising = numeric(length(advertising))
adstocked_advertising[1] = advertising[1]
for(i in 2:length(advertising)){
 adstocked_advertising[i] = 1/(1+exp(-v*advertising[i])) + 
adstock_rate*adstocked_advertising[i-1]}

输出图: enter image description here

0 个答案:

没有答案