bgnbd: Estimates the bgnbd model base on “Counting Your Customers”...

Description Usage Arguments Examples

Description

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

Usage

1
bgnbd(Tx, tx, n, start = rep(1.5, 4), lower = rep(0.01, 4), ...)

Arguments

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 c(0.01, 0.01, 0.01, 0.01).

Examples

 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)

usobiaga/shopping documentation built on July 8, 2019, 1:32 a.m.