rm(list=ls(all=T))
options(digits=4, scipen=12)
::p_load(ggplot2, manipulate, dplyr, latex2exp)
pacmanload("data/CX.rdata")
因為沒有成本資料,我們先假設營業獲利率為0.3
= 0.5 MRG
以R2
為行銷對象
= subset(CX, status=="R2")
A =A$ProbRetain
P0=A$PredRevenue R0
= 5
cost = 0.75 # fix effect on the probability of retaintion k1
par(mar=c(4,3,3,2), cex=0.8)
= R0*MRG*(k1 - P0) - cost
PI hist(PI, xlim=c(-50, 50), breaks=seq(-500,500,5),main="淨期望報償分布(R2)")
par(mar=c(4,3,3,2), cex=0.8)
= R0*MRG*pmax(0, k1 - P0) - cost
PI hist(PI, xlim=c(-50, 50), breaks=seq(-500,500,5),main="淨期望報償分布(R2)")
\[\Delta P_{ret} = \left\{\begin{matrix} k_2 & P_{retain}<=1-k_2 \\ 1-P_{retain} & else \end{matrix}\right.\]
= 0.15 # max. incremental effect of instrument
k2 = 5
cost par(mar=c(4,3,3,2), cex=0.8)
= MRG * R0 * ifelse(P0<=(1-k2), k2, 1-P0) - cost
PI hist(PI, xlim=c(-50, 50), breaks=seq(-500,500,5),main="淨期望報償分布(R2)")
= CX %>% mutate(
CX PI = MRG*PredRevenue*ifelse(ProbRetain<=(1-k2), k2, 1-ProbRetain) - cost
) %>% group_by(status) %>%
CX summarise(
Group.Sz = n(),
No.Target = sum(PI>0),
AvgROI = mean(PI[PI>0]),
TotalROI = sum(PI[PI>0])) %>%
arrange(No.Target) %>%
data.frame
## status Group.Sz No.Target AvgROI TotalROI
## 1 N1 2772 0 NaN 0
## 2 S2 1718 189 9.130 1726
## 3 S1 2807 508 6.095 3096
## 4 S3 4759 522 9.239 4823
## 5 R1 2140 532 7.242 3853
## 6 R2 2264 770 7.935 6110
## 7 N2 1957 998 11.011 10989
par(mfrow=c(4,2), mar=c(4,3,3,2), cex=0.8)
for(s in c("N1","N2","R1","R2","S1","S2","S3")) {
hist(CX$PI[CX$status==s], xlim=c(-5, 100), breaks=seq(-1000,1000,10),
ylim=c(0, 800), main=s, xlab="exp.profit")
abline(v=0, col='green', lty=2)}
=0.20; a=20; b=15
mpar(cex=0.8,mar=c(4,4,5,1))
curve(m*plogis((10/a)*(x-b)), 0, 30, lwd=2, ylim=c(0, 0.25),
main=TeX('$m \\times Logis(\\frac{10(x - b)}{a})$'), ylab="f(x)")
abline(h=seq(0,0.2,0.05),v=seq(0,30,5),col='lightgrey',lty=2)
\[k_0=f(x)=m \cdot Logis(\frac{10(x - b)}{a})\]
manipulate
套件做模擬manipulate()
不能在Rmd直接執行,需要另外開一個R窗格,把以下程式碼Copy過去跑
manipulate({
curve(m*plogis((10/a)*(x-b)), 0, 30, lwd=2, ylim=c(0, 0.25),
main = TeX('$m \\cdot Logis(10(x - b)/a)$'), ylab="f(x)")
abline(h=seq(0,0.2,0.05),v=seq(0,30,5),col='lightgrey',lty=2)
},m = slider(0.05, 0.25, 0.20, step=0.01),
a = slider( 10, 30, 20, step=1),
b = slider( 4, 20, 15, step=1)
)
=0.20; a=20; b=15
mdo.call(rbind, lapply(seq(5,40,0.5), function(c){
= m*plogis((10/a)*(c-b))
p %>% mutate(
CX PI = ifelse(ProbRetain<=(1-p), p, 1-ProbRetain) * PredRevenue - c
%>%
) group_by(status) %>% summarise(
Cost = c,
Group.Sz = n(),
No.Target = sum(PI>0),
AvgROI = mean(PI[PI>0]),
TotalROI = sum(PI[PI>0])
%>%
) } ) ) ggplot(aes(x=Cost, y=TotalROI, col=status)) +
geom_line(size=1.2) +
ggtitle("Cost Effeciency per Segment ")
manipulate()
不能在Rmd直接執行,需要另外開一個R窗格,把以下程式碼Copy過去跑
manipulate({
do.call(rbind, lapply(seq(5,40,0.5), function(c){
= m*plogis((10/a)*(c-b))
p %>% mutate(
CX PI = ifelse(ProbRetain<=(1-p), p, 1-ProbRetain) * PredRevenue - c
%>%
) group_by(status) %>% summarise(
Cost = c,
Group.Sz = n(),
No.Target = sum(PI>0),
AvgROI = mean(PI[PI>0]),
TotalROI = sum(PI[PI>0])
%>%
) } ) ) ggplot(aes(x=Cost, y=TotalROI, col=status)) +
geom_line(size=1.2) +
ggtitle("Cost Effeciency per Segment ")
},m = slider(0.05, 0.25, 0.20, step=0.01),
a = slider( 10, 30, 20, step=1),
b = slider( 4, 20, 15, step=1)
)