Description Usage Arguments Examples
Estimates the bgnbd model base on “Counting Your Customers” the Easy Way: An Alternative to the Pareto/NBD Model (2005) by Peter S FaderPeter S FaderBruce G. S. HardieKa Lok Lee
1 |
Tx |
lenght of time since the consumers first purchase. |
tx |
recency of the last purchase (time of the last purchase - time of the first). |
n |
count fo repeat purchases. |
start |
initial values for the bgnbd model. |
lower |
lower argument for optimization defaults to |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | data(cdnowSample)
## helper function to get the model variables
getMf <- function(set){
set$week <- as.numeric(set$date - min(set$date)) / 7
maxWeek <- max(set$week)
set %>%
group_by(s_id) %>% ## for each customer ID
summarise(
## total time being a client
Tx = maxWeek - min(week),
## time between last and first transactions
tx = max(week) - min(week),
## weeks with purchases (ignoring first purchase week)
n = length(unique(week)) - 1,
)
}
splitDate <- as.Date("1997-09-30")
calibrateSet <- getMf(filter(cdnowSample, date <= splitDate))
set.seed(345)
model <- bgnbd(Tx = calibrateSet$Tx, tx = calibrateSet$tx,
n = calibrateSet$n, start = c(1, 3, 1, 2.4))
pred <- predict(model, Tx = calibrateSet$Tx, tx = calibrateSet$tx, n = calibrateSet$n, 39)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.