# \donttest{
data("apparelTrans")
data("apparelStaticCov")
data("apparelDynCov")
clv.data.apparel <- clvdata(apparelTrans, date.format = "ymd",
time.unit = "w", estimation.split = 40)
clv.data.static.cov <-
SetStaticCovariates(clv.data.apparel,
data.cov.life = apparelStaticCov,
names.cov.life = "Gender",
data.cov.trans = apparelStaticCov,
names.cov.trans = c("Gender", "Channel"))
clv.data.dyn.cov <-
SetDynamicCovariates(clv.data = clv.data.apparel,
data.cov.life = apparelDynCov,
data.cov.trans = apparelDynCov,
names.cov.life = c("Marketing", "Gender"),
names.cov.trans = c("Marketing", "Gender"),
name.date = "Cov.Date")
# No covariate model
p.apparel <- pnbd(clv.data.apparel)
# Predict the number of transactions an average new
# customer is expected to make in the first 3.68 weeks
predict(
p.apparel,
newdata=newcustomer(num.periods=3.68)
)
# Static covariate model
p.apparel.static <- pnbd(clv.data.static.cov)
# Predict the number of transactions an average new
# customer who is female (Gender=1) and who was acquired
# online (Channel=1) is expected to make in the first 3.68 weeks
predict(
p.apparel.static,
newdata=newcustomer.static(
num.periods=3.68,
# For the lifetime process, only Gender was used when fitting
data.cov.life=data.frame(Gender=1),
data.cov.trans=data.frame(Gender=1, Channel=0)
)
)
if (FALSE) {
# Dynamic covariate model
p.apparel.dyn <- pnbd(clv.data.dyn.cov)
# Predict the number of transactions an average new
# customer who is male (Gender=0), who was contacted
# 4, 0, and 7 times with direct marketing, and who was
# acquired on "2005-02-16" (first.transaction) is expected
# to make in the first 2.12 weeks.
# Note that the time range is very different from the one used
# when fitting the model. Cov.Date still has to match the
# beginning of the week.
predict(
p.apparel.dyn,
newdata=newcustomer.dynamic(
num.periods=2.12,
data.cov.life=data.frame(
Cov.Date=c("2051-02-12", "2051-02-19", "2051-02-26"),
Gender=c(0, 0, 0),
Marketing=c(4, 0, 7)),
data.cov.trans=data.frame(
Cov.Date=c("2051-02-12", "2051-02-19", "2051-02-26"),
Gender=c(0, 0, 0),
Marketing=c(4, 0, 7)),
first.transaction = "2051-02-16"
)
)
}
# }
Run the code above in your browser using DataLab