我正在尝试建立一个模型来预测直邮营销活动。在下面的代码中,我能够使用以前活动的响应来创建平滑曲线。现在,我需要找出这条曲线下每一天的总面积,这样我就知道某天广告系列的完成百分比。我将能够使用每天的完成百分比,这样我就可以说“如果我认为我会从一个活动中获得 x 个总回复,我应该在第 1 天获得 y1% 的回复,y2% 的回复在第 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?