# \donttest{
data("apparelTrans")
# Fit pnbd standard model on data, WITH holdout
apparel.holdout <- clvdata(apparelTrans, time.unit="w",
estimation.split=52, date.format="ymd")
apparel.pnbd <- pnbd(apparel.holdout)
# Predict until the end of the holdout period
predict(apparel.pnbd)
# Predict until 10 periods (weeks in this case) after
# the end of the 37 weeks fitting period
predict(apparel.pnbd, prediction.end = 10) # ends on 2010-11-28
# Predict until 31th Dec 2016 with the timepoint as a character
predict(apparel.pnbd, prediction.end = "2016-12-31")
# Predict until 31th Dec 2016 with the timepoint as a Date
predict(apparel.pnbd, prediction.end = lubridate::ymd("2016-12-31"))
# Predict future transactions but not spending and CLV
predict(apparel.pnbd, predict.spending = FALSE)
# Predict spending by fitting a Gamma-Gamma model
predict(apparel.pnbd, predict.spending = gg)
# Fit a spending model separately and use it to predict spending
apparel.gg <- gg(apparel.holdout, remove.first.transaction = FALSE)
predict(apparel.pnbd, predict.spending = apparel.gg)
# Fit pnbd standard model WITHOUT holdout
pnc <- pnbd(clvdata(apparelTrans, time.unit="w", date.format="ymd"))
# This fails, because without holdout, a prediction.end is required
if (FALSE) {
predict(pnc)
}
# But it works if providing a prediction.end
predict(pnc, prediction.end = 10) # ends on 2016-12-17
# Predict the number of transactions a single, fictional, average new
# customer is expected to make in the first 3.45 weeks since coming alive
# See ?newcustomer() for more examples
predict(apparel.pnbd, newdata = newcustomer(num.periods=3.45))
# }
Run the code above in your browser using DataLab