如何设置"长度" weibull分布中的参数。我试图模拟直邮营销活动的响应曲线

时间:2015-03-30 15:39:34

标签: r curve-fitting weibull

我试图拟合曲线来模拟直邮广告系列的响应。使用R,我能够使用fitdistr()函数获得形状和比例因子。然后我在weibull()函数中使用shape和scale作为参数。但是,我们的广告系列通常持续63天(8周)和#34;长度"拟合威布尔曲线的过早切断有没有办法设置"长度"?

...或者是否有更好的方法来模拟Direct Mail营销活动的响应?

谢谢!

set.seed(5)
install.packages("MASS")
library("MASS")
responses <-c(4,5,1,12,24,16,16,15,5,18,7,12,5,13,6,2,9,2,5,1,4,4,5,3,3,4,7,3,9,2,2,4,3,2,5,4,3,2,2,2,2,2,2,2,2,2,1,1,1,1,1,2,3,2,1,1,1,1,1,1,1,1,1)                                                                                        

f <- fitdistr(responses,'weibull')

f #check the shape and scale

#plug in the shape and scale. 284 is the number of total responders that we're trying to fit the curve to. 
weibulldraws <- as.data.frame(table(round(.5 +   rweibull(284,1.0753863,4.6579543))))
weibulldraws

1 个答案:

答案 0 :(得分:0)

使用table()制表向量表时,只会在结果中显示向量中出现的值;如果要包含其他值,则需要创建一个因子,其中包含这些值作为级别。因此,如果您想在结尾处包含所有零,请在制表之前将结果放入具有适当级别的因子中:

set.seed(5)
wshape <- 1.0753863
wscale <- 4.6579543
n <- 284
rvals <- round(rweibull(n,wshape,wscale)+0.5)
frvals <- factor(rvals,levels=0:63)
weibulldraws <- as.data.frame(table(frvals))

如果您想要绘制与Weibull相关联的理论曲线(即密度曲线而不是与分布中随机抽取相对应的表格),则使用curve() dweibull()功能:

curve(n*dweibull(x,wshape,wscale),from=0,to=63)

(使用add=TRUE将曲线添加到现有图中。