曲线下的区域 - 有没有办法找到特定日期营销活动的完成百分比?

时间:2015-04-08 17:18:11

标签: r time-series curve-fitting forecasting weibull

我正在尝试建立一个模型来预测直邮营销活动。在下面的代码中,我能够使用之前广告系列的响应来创建平滑曲线。现在,我需要找到每天这条曲线下的总面积,这样我才知道广告系列在某一天的完成百分比。我将能够使用每天的完成百分比,以便我可以说"如果我认为我将从广告系列获得x个总回复数,我应该在第1天获得y1%的回复,第2天的回复率为2%,等等。

#vector of direct mail marketing responses over 63 days 
responses <- c(
24.16093706,
41.59607507,
68.20083052,
85.19109064,
100.0704403,
58.6600221,
86.08475816,
88.97439581,
65.58341418,
49.25588053,
53.63602085,
47.03620672,
29.71552264,
32.85862747,
31.29118096,
23.67961069,
19.81261675,
18.69300933,
17.25738435,
12.01161679,
12.36734071,
14.32360673,
11.02390849,
9.108021409,
9.647965622,
8.815576548,
5.67225654,
5.739220185,
6.233999138,
5.527376627,
5.024065761,
5.565266355,
4.626749364,
3.480761716,
4.621902301,
4.518554271,
4.075985188,
3.204946787,
3.174020873,
2.966915873,
2.129178828,
2.673009031,
2.410429043,
2.331287075,
2.509300578,
2.13820695,
2.53433787,
1.603934405,
1.555813592,
1.834605068,
1.842905685,
1.454045577,
2.08684322,
1.318276487,
0.807666643,
1.333167088,
1.004526525,
1.180110123,
1.078079735,
1.151394678,
1.426747942,
0.699119833,
0.583347236)


set.seed(2)
install.packages("MASS")
library("MASS")


shape_and_scale <- fitdistr(responses,'weibull')

#check the shape and scale
shape_and_scale

#plug in the shape and scale
#essentially taking the total number of respondants and for each, doing a random simulation for what day they'll respond- according to a weibull distribution
#rweibull makes it a random generation
#also need to create a variable for the total number of responses
total_responses <- 1121
day_response <- round(rweibull(total_responses,0.70730466,13.79467490)+.5)

day_response

day_response_frequency_table <- as.data.frame(table(round(rweibull(total_responses,0.70730466,13.79467490)+.5)))

day_response_frequency_table
#notice that it extends beyond our 63 day limit for modeling a campaign

#create a factor with levels so that we can limit our distribution to 63 days
day_response_with_levels <- factor(day_response, levels=0:63)
day_response_with_levels
response_frequency <- as.data.frame(table(day_response_with_levels))
response_frequency

#now use dweibull and the curve() function to create a curve
?dweibull 
curve results <- curve(dweibull(x,0.70730466,13.79467490),from=0, to=63)

curve results
#these probabilities don't add to 1 (i.e. area under the curve does not add to 1. Is
#there a way to fix this?  I ultimately just need a way to find the % complete the
#campaign is each day?  

1 个答案:

答案 0 :(得分:0)

integrate函数可以处理密度函数。 (我最初的努力向你展示如何&#34;手工整合&#34;使用diff和梯形规则被接近于零的大概率质量绊倒,其中威布尔密度变为Inf。

?integrate
> integrate( dweibull, 0, 63, 0.70730466,13.79467490)
0.9464916 with absolute error < 2.8e-05

正在使用将参数传递给要集成的函数参数的省略号方法。实际命名它们会更安全:

?dweibull
integrate( dweibull, 0, 63, shape=0.70730466, scale=13.79467490)

只是为了表明integrate表现良好,因为限制增加:

> integrate( dweibull, 0, 500, 0.70730466,13.79467490)
0.9999969 with absolute error < 7.8e-07

> integrate( dweibull, 0, Inf, 0.70730466,13.79467490)
1 with absolute error < 3.8e-05