# \donttest{
data("cdnow")
# Fit ParetoNBD model on the CDnow data
clv.cdnow <- clvdata(cdnow, time.unit="w",
estimation.split=37,
date.format="ymd")
pnbd.cdnow <- pnbd(clv.cdnow)
## TRACKING PLOT
# Plot actual repeat transaction, overlayed with the
# expected repeat transactions as by the fitted model
plot(pnbd.cdnow)
# Plot cumulative expected transactions of only the model
plot(pnbd.cdnow, cumulative=TRUE, transactions=FALSE)
# Plot until 2001-10-21
plot(pnbd.cdnow, prediction.end = "2001-10-21")
# Plot until 2001-10-21, as date
plot(pnbd.cdnow,
prediction.end = lubridate::dym("21-2001-10"))
# Plot 15 time units after end of estimation period
plot(pnbd.cdnow, prediction.end = 15)
# Save the data generated for plotting
# (period, actual transactions, expected transactions)
plot.out <- plot(pnbd.cdnow, prediction.end = 15)
# A ggplot object is returned that can be further tweaked
library("ggplot2")
gg.pnbd.cdnow <- plot(pnbd.cdnow)
gg.pnbd.cdnow + ggtitle("PNBD on CDnow")
## PMF PLOT
plot(pnbd.cdnow, which="pmf")
# For transactions 0 to 15, also have
# to change label for remaining
plot(pnbd.cdnow, which="pmf", trans.bins=0:15,
label.remaining="16+")
# For transactions 0 to 15 bins, no remaining
plot(pnbd.cdnow, which="pmf", trans.bins=0:15,
calculate.remaining=FALSE)
## MODEL COMPARISON
# compare vs bgnbd
bgnbd.cdnow <- bgnbd(clv.cdnow)
ggomnbd.cdnow <- ggomnbd(clv.cdnow)
# specify colors as names of other.models
# note that ggomnbd collapses into the pnbd on this dataset
plot(pnbd.cdnow, cumulative=TRUE,
other.models=list(blue=bgnbd.cdnow, "#00ff00"=ggomnbd.cdnow))
# specify names as label, using standard colors
plot(pnbd.cdnow, which="pmf",
other.models=list(bgnbd.cdnow),
label=c("Pareto/NBD", "BG/NBD"))
# }
Run the code above in your browser using DataLab