I am working with the pareto/NBD model in the BTYD package, and I am having trouble with a very high P-alive value (0,99+).
I have read another thread about the subject, but it didn't help (Extremely high probability of being alive BTYD R)
I know the problem is due to a very low s and parameter estimate, but I don't why I get the low estimate.
My parems estimates are:
r alpha s beta LL
2.549445e+00 1.260866e+01 1.169191e-05 6.187665e+01
# Model params are :
# r gamma parameter for NBD transaction
# alpha gamma parameter for NBD transaction
# s gamma parameter for Pareto (exponential gamma) dropout process
# beta gammma parameter for Pareto (exponential gamma) dropout process
This is the code I have used:
elog <- read.csv("elog.csv")
elog$date <- ymd(elog$date)
#merge transaction on same day
elog <- dc.MergeTransactionsOnSameDate(elog);
head(elog, 3)
#set cal period
end.of.cal.period <- as.Date("2017-08-30")
elog.cal <- elog[which(elog$date <= end.of.cal.period), ]
split.data <- dc.SplitUpElogForRepeatTrans(elog.cal);
clean.elog <- split.data$repeat.trans.elog;
#reach and frequency matrix.
freq.cbt <- dc.CreateFreqCBT(clean.elog); ###CBT = customer by time matrix
freq.cbt[1:8,1:10]
#spend matrix
spend.cbt <- dc.CreateSpendCBT(clean.elog, is.avg.spend= FALSE);
spend.cbt[1:8,1:10]
tot.cbt <- dc.CreateFreqCBT(elog)
cal.cbt <- dc.MergeCustomers(tot.cbt, freq.cbt)
## CBS = customer-bysufficient-statistic matrix
birth.periods <- split.data$cust.data$birth.per
last.dates <- split.data$cust.data$last.date
cal.cbs.dates <- data.frame(birth.periods, last.dates,
end.of.cal.period)
cal.cbs <- dc.BuildCBSFromCBTAndDates(cal.cbt, cal.cbs.dates,
per="week")
cal.cbs
#### Customer-by-sufficient-statistic matrix (CBS), with three columns: frequency("x"), recency("t.x") and total time observed("T.cal").
##################################################
# Parameter Estimation
##################################################
params <- pnbd.EstimateParameters(cal.cbs);
params
LL <- pnbd.cbs.LL(params, cal.cbs);
LL
## parameter optimization ##
p.matrix <- c(params, LL);
for (i in 1:10){
params <- pnbd.EstimateParameters(cal.cbs, params);
LL <- pnbd.cbs.LL(params, cal.cbs);
p.matrix.row <- c(params, LL);
p.matrix <- rbind(p.matrix, p.matrix.row);
}
colnames(p.matrix) <- c("r", "alpha", "s", "beta", "LL");
p.matrix;
pnbd.PlotTransactionRateHeterogeneity(params)
pnbd.PlotDropoutRateHeterogeneity(params)
I cannot get the dropoutrate plot because of the low s value.
The dataset is a sample of a larger dataset, but both the sample and larger dataset produces the same problem.
The data I have used (dput output):
elog <- structure(list(cust = c("1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "3", "3", "3", "3", "3", "3", "3", "3", "3", "4", "4",
"4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4",
"4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4",
"4", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5",
"5", "5", "5", "5", "5", "5", "6", "6", "6", "6", "6", "6", "6",
"6", "6", "6", "6", "6", "7", "7", "7", "7", "7", "7", "7", "7",
"7", "7", "7", "7", "8", "8", "8", "8", "8", "8", "8", "8", "8",
"8", "8", "8", "9", "9", "10", "10", "10", "10", "10", "10",
"10", "10", "10", "11", "11", "11", "11", "11", "11", "11", "11",
"11", "11", "11", "12", "12", "12", "12", "13", "13", "13", "13",
"13", "13", "13", "13", "13", "14", "14", "14", "14", "14", "14",
"14", "14", "14", "14", "14", "14", "14", "14", "14", "14", "15",
"15", "15", "15", "15", "15", "15", "15", "15", "15", "15", "15",
"15", "15", "16", "16", "16", "16", "16", "16", "16", "16", "16",
"16", "16", "16", "16", "16", "16", "16", "16", "16", "16", "16",
"16", "16", "16", "16", "17", "17", "18", "18", "18", "19", "19",
"19", "19", "19", "19", "19", "19", "19", "19", "19", "19", "19",
"20", "20", "20", "20", "20", "20", "20", "20", "20", "20", "20",
"20", "20", "21", "21", "21", "21", "21", "21", "22", "22", "22",
"22", "22", "22", "22", "22", "22", "22", "22", "22", "22", "23",
"23", "24", "24", "24", "24", "24", "24", "24", "25", "25", "25",
"26", "26", "26", "26", "26", "26", "27", "27", "27", "27", "27",
"27", "27", "27", "27", "27", "28", "29", "29", "29", "29", "29",
"29", "29", "29", "29", "30", "30", "30", "30", "30", "30", "30",
"30", "30", "30", "30", "30", "30", "30", "30", "30", "30", "30",
"31", "31", "31", "31", "31", "31", "31", "31", "31", "31", "31",
"31", "31", "31", "32", "32", "32", "32", "33", "33", "33", "33",
"33", "33", "33", "33", "33", "33", "33", "33", "33", "33", "33",
"33", "33", "33", "33", "33", "34", "34", "34", "34", "35", "35",
"35", "35", "35", "35", "35", "36", "36", "36", "36", "36", "37",
"37", "37", "37", "37", "37", "37", "37", "37", "38", "38", "38",
"38", "38", "38", "39", "39", "39", "39", "39", "39", "39", "39",
"39", "39", "39", "39", "39", "39", "39", "39", "39", "39", "39",
"39", "39", "39", "39", "39", "39", "40", "40", "41", "41", "41",
"41", "41", "41", "41", "41", "41", "41", "41", "41", "41", "41",
"41", "41", "41", "41", "41", "41", "41", "41", "41", "41", "41",
"41", "41", "41", "41", "41", "41", "42", "42", "42", "42", "42",
"42", "42", "42", "42", "42", "42", "42", "42", "42", "43", "43",
"44", "44", "44", "44", "44", "44", "44", "44", "44", "45", "45",
"45", "45", "45", "45", "45", "45", "45", "46", "46", "46", "46",
"46", "46", "46", "46", "46", "46", "46", "46", "46", "46", "46",
"46", "46", "46", "46", "46", "46", "46", "46", "46", "46", "46",
"46", "46", "47"), date = structure(c(17428, 17181, 17371, 17450,
17423, 17260, 17412, 17375, 17438, 17193, 17283, 17329, 17267,
17295, 17240, 17257, 17452, 17172, 17490, 17235, 17177, 17222,
17219, 17222, 17214, 17271, 17390, 17354, 17360, 17343, 17246,
17502, 17453, 17292, 17218, 17497, 17280, 17259, 17530, 17287,
17469, 17371, 17427, 17385, 17343, 17462, 17257, 17187, 17245,
17324, 17413, 17502, 17504, 17511, 17490, 17238, 17406, 17189,
17434, 17203, 17357, 17278, 17348, 17340, 17371, 17213, 17341,
17390, 17264, 17232, 17168, 17240, 17265, 17231, 17380, 17350,
17241, 17367, 17218, 17175, 17513, 17336, 17192, 17288, 17276,
17197, 17498, 17178, 17387, 17429, 17325, 17517, 17248, 17474,
17508, 17305, 17518, 17346, 17375, 17176, 17256, 17236, 17455,
17350, 17171, 17515, 17351, 17471, 17339, 17183, 17226, 17222,
17340, 17417, 17434, 17180, 17198, 17263, 17333, 17187, 17364,
17297, 17446, 17383, 17480, 17214, 17292, 17290, 17428, 17494,
17287, 17323, 17277, 17168, 17332, 17520, 17283, 17218, 17397,
17502, 17421, 17496, 17252, 17383, 17243, 17290, 17238, 17317,
17214, 17287, 17186, 17355, 17467, 17411, 17201, 17200, 17463,
17464, 17280, 17487, 17197, 17184, 17196, 17519, 17483, 17383,
17300, 17372, 17415, 17259, 17264, 17317, 17327, 17201, 17531,
17319, 17475, 17271, 17257, 17174, 17439, 17362, 17519, 17367,
17355, 17330, 17333, 17445, 17298, 17191, 17397, 17478, 17285,
17276, 17385, 17257, 17252, 17380, 17245, 17515, 17206, 17312,
17184, 17168, 17371, 17225, 17218, 17179, 17284, 17527, 17513,
17169, 17406, 17239, 17294, 17490, 17323, 17430, 17389, 17312,
17224, 17247, 17365, 17230, 17383, 17414, 17276, 17196, 17308,
17510, 17457, 17421, 17330, 17449, 17428, 17189, 17337, 17172,
17277, 17329, 17296, 17521, 17204, 17367, 17253, 17504, 17214,
17420, 17530, 17464, 17278, 17393, 17267, 17376, 17485, 17192,
17170, 17431, 17429, 17308, 17367, 17421, 17211, 17213, 17175,
17391, 17336, 17457, 17464, 17211, 17277, 17326, 17186, 17378,
17336, 17168, 17480, 17397, 17354, 17308, 17528, 17338, 17200,
17401, 17393, 17282, 17500, 17211, 17441, 17347, 17466, 17332,
17173, 17457, 17256, 17455, 17494, 17459, 17521, 17232, 17231,
17360, 17354, 17284, 17498, 17192, 17424, 17438, 17523, 17512,
17475, 17323, 17325, 17305, 17490, 17207, 17517, 17481, 17341,
17194, 17310, 17500, 17282, 17446, 17172, 17515, 17308, 17192,
17359, 17392, 17280, 17466, 17268, 17275, 17400, 17203, 17418,
17494, 17327, 17477, 17343, 17250, 17303, 17350, 17354, 17169,
17184, 17314, 17271, 17211, 17325, 17369, 17210, 17492, 17319,
17266, 17324, 17467, 17381, 17417, 17383, 17245, 17338, 17182,
17445, 17219, 17469, 17296, 17241, 17288, 17499, 17515, 17361,
17345, 17296, 17250, 17199, 17325, 17172, 17189, 17333, 17239,
17420, 17444, 17208, 17266, 17515, 17259, 17486, 17216, 17365,
17301, 17198, 17372, 17467, 17413, 17283, 17332, 17249, 17343,
17520, 17478, 17203, 17409, 17214, 17235, 17471, 17179, 17180,
17228, 17508, 17465, 17235, 17518, 17267, 17422, 17282, 17205,
17383, 17492, 17318, 17457, 17352, 17491, 17434, 17402, 17340,
17386, 17353, 17501, 17341, 17324, 17429, 17303, 17345, 17336,
17242, 17492, 17471, 17389, 17221, 17291, 17519, 17458, 17199,
17331, 17179, 17388, 17168, 17441, 17372, 17205, 17389, 17170,
17238, 17411, 17378, 17271, 17503, 17229, 17285, 17495, 17231,
17376, 17409, 17487, 17214, 17491, 17303, 17527, 17232, 17214,
17401, 17513, 17482, 17285, 17449, 17289, 17271, 17421, 17458,
17409, 17498, 17232, 17306, 17318, 17435, 17394, 17459, 17385,
17380, 17494, 17317, 17196, 17250, 17276, 17519, 17440, 17457,
17365), class = "Date"), sales = c(100, 99.95, 82.5, 369.95,
339.95, 299, 149, 429.86, 903.21, 62.93, 337.85, 134.7, 125,
49.9, 694.995, 114.95, 249.8, 2048.01, 54.95, 179.2, 83.93, 39.95,
69.95, 275, 59.95, 248, 59.95, 41.95, 146.45, 107.5, 228.85,
119.95, 42, 369.95, 189.9, 281.25, 755, 114.95, 1095, 649.95,
49.95, 104.9, 270.9, 79.95, 267.47, 318.85, 37.46, 330.44, 474,
39.96, 20, 199.95, 179, 199.86, 329.95, 398.81, 603.85, 99, 569.75,
526.4, 99.95, 1135.12, 39.97, 153.89, 119.95, 442.69, 418.16,
607.2, 866, 476.2, 200, 636.9, 75.62, 464.39, 814.85, 109, 251.99,
20, 15, 69.95, 209.91, 381.76, 1956.33, 64.9, 59.95, 33.94, 177.96,
1179, 33.97, 195.09, 404, 225, 420, 860.5, 341.25, 58.95, 168.75,
122.85, 202.9, 49.96, 96.75, 129.9, 133.42, 124.95, 164.9, 303.7,
361.86, 225, 44.95, 110.93, 46.95, 227.02, 74.95, 59.95, 410,
358, 139, 49.9, 553.1, 138.33, 99.8, 100.02, 802, 300, 909.95,
860, 83.97, 59.95, 109.9, 64.95, 119.95, 198.95, 119, 140.96,
99.95, 104.9, 349, 249.95, 20, 164.94, 8.95, 89.95, 288.85, 1341.95,
29, 299, 245, 119, 390.25, 228.9, 49.95, 39.9, 193.9, 39.95,
115.94, 84.9, 81.95, 145, 114, 93.75, 193.95, 34.95, 76, 183.95,
99, 332, 69.95, 250, 159.92, 990.8, 69.95, 448.9, 89.95, 558.27,
814, 299, 440, 76.9, 117.9, 138, 60, 35, 99, 705.575, 39.95,
99.91, 149, 235.86, 123.7, 46.25, 133.6, 89.95, 59.95, 357.95,
149.88, 78.97, 159.9, 169.85, 79.95, 354.86, 159.9, 39, 40, 49.95,
34.95, 279.85, 69.9, 187.85, 416.29, 523.96, 219.9, 343.96, 37.95,
230, 683.95, 31.95, 39.9, 85, 322, 372.95, 349.86, 165.75, 715,
638.85, 125, 988.9, 194.9, 854, 628.9, 69.9, 436, 39.95, 624,
179.95, 447.2, 59.95, 382.91, 348.9, 249, 199.95, 84.95, 258.95,
264, 34.95, 493.73, 880.14, 96.9, 166.48, 131.06, 627.95, 102.87,
244.8, 524, 528, 221.21, 109, 39.9, 309.9, 638.01, 49.95, 589.8,
329, 200.9, 129.95, 49.96, 199.96, 39, 146.25, 39.95, 179.91,
126.85, 128.85, 874.95, 254, 237.75, 990, 238.95, 176.57, 167,
55.95, 566.25, 455, 173.78, 94.85, 109.95, 29, 24.95, 79.905,
39.95, 39.95, 79.905, 27.97, 105.95, 375, 139.95, 37, 277.6,
37, 20, 113.15, 121.95, 623.55, 103.25, 15, 35.96, 180.95, 148.95,
183.92, 756.75, 285, 165, 149, 204.95, 248.95, 11, 325.95, 359.89,
99.95, 212.95, 89, 38, 26.95, 144, 309.95, 49, 99.95, 52.55,
130.94, 175.01, 76, 360, 370.01, 119.95, 167.5, 119.95, 218.95,
190.12, 364.32, 157.5, 275, 38, 119.95, 178, 95.06, 265, 360,
287.45, 38, 97.96, 118.9, 75, 183.96, 79, 258.95, 111.16, 99.95,
79.95, 15, 144.8, 348.95, 114.9, 59.95, 119.85, 210, 103.85,
39.95, 712.85, 272.9, 667.96, 239, 100.9, 428, 319.1, 363.08,
189.67, 69.95, 273.75, 165, 159.7, 161.2, 165, 932.31, 207.85,
420.69, 570.02, 314.16, 516.05, 218.95, 402, 183.1, 257.29, 95.85,
303.95, 828.99, 292.96, 610.44, 272.71, 348.65, 960.56, 262.34,
302.64, 512.57, 110.85, 686.06, 69.9, 119.9, 175.86, 97.94, 224.95,
198.96, 149, 12.95, 59.95, 109.9, 74.95, 114.9, 290.07, 108.75,
139.88, 592.5, 59.9, 209.95, 59.95, 299, 33.71, 99.95, 59.95,
25, 129.9, 536.25, 27.97, 470, 23.96, 39.95, 77.46, 74.95, 247.96,
351.87, 249.91, 339.09, 322.91, 199.85, 29.95, 58, 38, 584.6,
120.8, 151.46, 975, 99, 99.9, 327.45, 60, 49.95, 29, 135, 52.55,
129.95, 225, 67.96, 469.95, 478.4, 65, 560, 75, 69.95, 184.95,
233.9, 264.85, 520, 55, 145, 64.95, 456.96, 124.95, 139, 74.95,
99.95, 99, 306.81, 409.7, 101.9, 139.9, 135, 119.95, 209.9, 59.95,
218.95, 179.9, 70, 315.84, 843.84, 91.89, 198.95, 139.9, 335.95,
393.8, 223.8, 219.95, 509.9)), .Names = c("cust", "date", "sales"
), row.names = c(10163L, 641L, 8117L, 11001L, 10007L, 3980L,
9627L, 8274L, 10523L, 1156L, 4764L, 6554L, 4229L, 5281L, 3209L,
3880L, 11070L, 224L, 12424L, 3039L, 440L, 2512L, 2369L, 2516L,
2171L, 4365L, 8859L, 7548L, 7767L, 7095L, 3450L, 13017L, 11118L,
5218L, 2327L, 12777L, 4658L, 3945L, 14473L, 4950L, 11627L, 8134L,
10141L, 8653L, 7103L, 11405L, 3890L, 937L, 3410L, 6374L, 9657L,
13022L, 13101L, 13449L, 12429L, 3132L, 9398L, 993L, 10383L, 1639L,
7650L, 4612L, 7327L, 7005L, 8140L, 2122L, 7050L, 8865L, 4153L,
2931L, 32L, 3216L, 4174L, 2894L, 8478L, 7382L, 3258L, 8024L,
2333L, 362L, 13575L, 6844L, 1137L, 5013L, 4509L, 1330L, 12808L,
492L, 8732L, 10216L, 6426L, 13806L, 3541L, 11890L, 13321L, 5686L,
13871L, 7235L, 8294L, 412L, 3845L, 3094L, 11170L, 7397L, 196L,
13703L, 7444L, 11735L, 6979L, 745L, 2688L, 2537L, 7018L, 9833L,
10394L, 631L, 1409L, 4091L, 6724L, 905L, 7889L, 5350L, 10872L,
8572L, 12063L, 2153L, 5206L, 5095L, 10166L, 12569L, 4935L, 6297L,
4537L, 3L, 6684L, 13988L, 4770L, 2312L, 9097L, 13006L, 9937L,
12744L, 3650L, 8580L, 3336L, 5102L, 3128L, 6097L, 2163L, 4939L,
858L, 7596L, 11572L, 9590L, 1558L, 1482L, 11443L, 11466L, 4648L,
12317L, 1313L, 763L, 1272L, 13913L, 12165L, 8582L, 5473L, 8162L,
9726L, 3941L, 4136L, 6100L, 6517L, 1560L, 14516L, 6206L, 11906L,
4355L, 3876L, 307L, 10599L, 7848L, 13914L, 8008L, 7597L, 6605L,
6732L, 10833L, 5417L, 1079L, 9099L, 12013L, 4882L, 4489L, 8643L,
3877L, 3653L, 8462L, 3399L, 13664L, 1767L, 5911L, 764L, 16L,
8126L, 2604L, 2319L, 530L, 4825L, 14296L, 13553L, 71L, 9392L,
3168L, 5246L, 12423L, 6304L, 10234L, 8804L, 5914L, 2563L, 3482L,
7946L, 2864L, 8586L, 9689L, 4491L, 1274L, 5754L, 13403L, 11233L,
9940L, 6607L, 10973L, 10170L, 983L, 6874L, 226L, 4544L, 6568L,
5319L, 14065L, 1672L, 8013L, 3682L, 13095L, 2169L, 9893L, 14464L,
11470L, 4605L, 8930L, 4237L, 8323L, 12239L, 1121L, 130L, 10280L,
10207L, 5756L, 8014L, 9942L, 2007L, 2110L, 337L, 8891L, 6829L,
11234L, 11472L, 2008L, 4548L, 6462L, 869L, 8365L, 6831L, 22L,
12072L, 9108L, 7545L, 5759L, 14346L, 6916L, 1491L, 9227L, 8934L,
4734L, 12895L, 2010L, 10682L, 7274L, 11536L, 6696L, 281L, 11238L,
3810L, 11154L, 12603L, 11314L, 14071L, 2919L, 2887L, 7768L, 7549L,
4830L, 12801L, 1126L, 10052L, 10541L, 14219L, 13499L, 11909L,
6307L, 6413L, 5663L, 12427L, 1833L, 13795L, 12116L, 7039L, 1221L,
5869L, 12896L, 4737L, 10896L, 232L, 13667L, 5760L, 1127L, 7733L,
8907L, 4655L, 11539L, 4299L, 4449L, 9204L, 1637L, 9855L, 12610L,
6524L, 11972L, 7099L, 3616L, 5564L, 7373L, 7553L, 74L, 770L,
5986L, 4366L, 2014L, 6414L, 8099L, 1965L, 12498L, 6211L, 4195L,
6369L, 11578L, 8504L, 9813L, 8594L, 3408L, 6922L, 672L, 10847L,
2380L, 11626L, 5324L, 3249L, 5003L, 12848L, 13670L, 7810L, 7177L,
5325L, 3618L, 1438L, 6416L, 235L, 992L, 6741L, 3178L, 9900L,
10798L, 1906L, 4198L, 13676L, 3944L, 12285L, 2250L, 7950L, 5494L,
1386L, 8173L, 11583L, 9656L, 4782L, 6702L, 3573L, 7102L, 14014L,
12019L, 1638L, 9503L, 2177L, 3052L, 11717L, 544L, 611L, 2773L,
13300L, 11506L, 3053L, 13859L, 4244L, 9990L, 4740L, 1723L, 8596L,
12502L, 6160L, 11241L, 7468L, 12465L, 10385L, 9258L, 7001L, 8685L,
7511L, 12957L, 7044L, 6375L, 10210L, 5567L, 7180L, 6836L, 3300L,
12504L, 11719L, 8816L, 2476L, 5170L, 13939L, 11272L, 1441L, 6658L,
545L, 8774L, 27L, 10687L, 8176L, 1724L, 8817L, 139L, 3133L, 9602L,
8377L, 4369L, 13059L, 2835L, 4891L, 12721L, 2892L, 8326L, 9505L,
12336L, 2182L, 12467L, 5569L, 14311L, 2925L, 2183L, 9232L, 13568L,
12152L, 4894L, 10981L, 5064L, 4370L, 9947L, 11275L, 9507L, 12804L,
2927L, 5721L, 6164L, 10418L, 8979L, 11325L, 8657L, 8474L, 12625L,
6118L, 1285L, 3621L, 4502L, 13941L, 10659L, 11244L, 7951L), class = "data.frame")