Probabilistic customer attrition models predict in general three expected characteristics for every customer:

  • "conditional expected transactions" (CET), which is the number of transactions to expect from a customer during the prediction period,

  • "probability of a customer being alive" (PAlive) at the end of the estimation period and

  • "discounted expected residual transactions" (DERT) for every customer, which is the total number of transactions for the residual lifetime of a customer discounted to the end of the estimation period. In the case of time-varying covariates, instead of DERT, "discounted expected conditional transactions" (DECT) is predicted. DECT does only cover a finite time horizon in contrast to DERT. For continuous.discount.factor=0, DECT corresponds to CET.

In order to derive a monetary value such as CLV, customer spending has to be considered. If the clv.data object contains spending information, customer spending can be predicted using a Gamma/Gamma spending model for parameter predict.spending and the predicted CLV is be calculated (if the transaction model supports DERT/DECT). In this case, the prediction additionally contains the following two columns:

  • "predicted.mean.spending", the mean spending per transactions as predicted by the spending model.

  • "CLV", the customer lifetime value. CLV is the product of DERT/DECT and predicted spending.

Uncertainty estimates are available for all predicted quantities using bootstrapping.

New customer prediction

The fitted model can also be used to predict the number of transactions a fictional, single, average newly alive customer is expected to make at the moment of the first transaction ("coming alive"). This is, for a customer which has no existing order history. For covariate models, the prediction is for an average customer with the given covariates.

The individual-level unconditional expectation that is also used for the tracking plot is used to obtain this prediction. For models without covariates, the prediction hence is the same for all customers and independent of when a customer comes alive. For models with covariates, the prediction is the same for all customers with the same covariates.

The data on which the model was fit and which is stored in it is NOT used for this prediction. See examples and newcustomer for more details.

# S3 method for class 'clv.fitted.transactions'
predict(
  object,
  newdata = NULL,
  prediction.end = NULL,
  predict.spending = gg,
  continuous.discount.factor = log(1 + 0.1),
  uncertainty = c("none", "boots"),
  level = 0.9,
  num.boots = 100,
  verbose = TRUE,
  ...
)

# S4 method for class 'clv.fitted.transactions'
predict(
  object,
  newdata = NULL,
  prediction.end = NULL,
  predict.spending = gg,
  continuous.discount.factor = log(1 + 0.1),
  uncertainty = c("none", "boots"),
  level = 0.9,
  num.boots = 100,
  verbose = TRUE,
  ...
)

Arguments

object

A fitted clv transaction model for which prediction is desired.

newdata

A clv data object or data for the new customer prediction (see newcustomer) for which predictions should be made with the fitted model. If none or NULL is given, predictions are made for the data on which the model was fit.

prediction.end

Until what point in time to predict. This can be the number of periods (numeric) or a form of date/time object. See details.

predict.spending

Whether and how to predict spending and based on it also CLV, if possible. See details.

continuous.discount.factor

continuous discount factor to use to calculate DERT/DECT. Defaults to a 10% continuous annual rate. See details.

uncertainty

Method to produce confidence intervals of the predictions (parameter uncertainty). Either "none" (default) or "boots".

level

Required confidence level, if uncertainty="boots".

num.boots

Number of bootstrap repetitions, if uncertainty="boots". A low number may not produce intervals for all customers if they are not sampled.

verbose

Show details about the running of the function.

...

Ignored

Value

An object of class data.table with columns:

Id

The respective customer identifier

period.first

First timepoint of prediction period

period.last

Last timepoint of prediction period

period.length

Number of time units covered by the period indicated by period.first and period.last (including both ends).

PAlive

Probability to be alive at the end of the estimation period

CET

The Conditional Expected Transactions: The number of transactions expected until prediction.end.

DERT or DECT

Discounted Expected Residual Transactions or Discounted Expected Conditional Transactions for dynamic covariates models

actual.x

Actual number of transactions until prediction.end. Only if there is a holdout period and the prediction ends in it, otherwise not reported.

actual.total.spending

Actual total spending until prediction.end. Only if there is a holdout period and the prediction ends in it, otherwise not reported.

predicted.mean.spending

The mean spending per transactions as predicted by the spending model.

predicted.total.spending

The predicted total spending until prediction.end (CET*predicted.mean.spending).

predicted.CLV

Customer Lifetime Value based on DERT/DECT and predicted.mean.spending.

If predicting for new customers (using newcustomer()), a numeric scalar indicating the expected number of transactions is returned instead.

Details

predict.spending indicates whether to predict customers' spending and if so, the spending model to use. Accepted inputs are either a logical (TRUE/FALSE), a method to fit a spending model (i.e. gg), or an already fitted spending model. If provided TRUE, a Gamma-Gamma model is fit with default options. If argument newdata is provided, the spending model is fit on newdata. Predicting spending is only possible if the transaction data contains spending information. See examples for illustrations of valid inputs.

The newdata argument has to be a clv data object of the exact same class as the data object on which the model was fit. In case the model was fit with covariates, newdata needs to contain identically named covariate data.

The use case for newdata is mainly two-fold: First, to estimate model parameters only on a sample of the data and then use the fitted model object to predict or plot for the full data set provided through newdata. Second, for models with dynamic covariates, to provide a clv data object with longer covariates than contained in the data on which the model was estimated what allows to predict or plot further. When providing newdata, some models might require additional steps that can significantly increase runtime.

To predict for new customers, the output of newcustomer has to be given to newdata. See examples.

prediction.end indicates until when to predict or plot and can be given as either a point in time (of class Date, POSIXct, or character) or the number of periods. If prediction.end is of class character, the date/time format set when creating the data object is used for parsing. If prediction.end is the number of periods, the end of the fitting period serves as the reference point from which periods are counted. Only full periods may be specified. If prediction.end is omitted or NULL, it defaults to the end of the holdout period if present and to the end of the estimation period otherwise.

The first prediction period is defined to start right after the end of the estimation period. If for example weekly time units are used and the estimation period ends on Sunday 2019-01-01, then the first day of the first prediction period is Monday 2019-01-02. Each prediction period includes a total of 7 days and the first prediction period therefore will end on, and include, Sunday 2019-01-08. Subsequent prediction periods again start on Mondays and end on Sundays. If prediction.end indicates a timepoint on which to end, this timepoint is included in the prediction period.

continuous.discount.factor is the continuous rate used to discount the expected residual transactions (DERT/DECT). An annual rate of (100 x d)% equals a continuous rate delta = ln(1+d). To account for time units which are not annual, the continuous rate has to be further adjusted to delta=ln(1+d)/k, where k are the number of time units in a year.

Uncertainty Estimates

Bootstrapping is used to provide confidence intervals of all predicted metrics. These provide an estimate of parameter uncertainty. To create bootstrapped data, customer ids are sampled with replacement until reaching original length and all transactions of the sampled customers are used to create a new clv.data object. A new model is fit on the bootstrapped data with the exact same specification as used when fitting object (incl. start parameters and `optimx.args`) and it is then used to predict on this data.

It is highly recommended to fit the original model (object) with a robust optimization method, such as Nelder-Mead (optimx.args=list(method='Nelder-Mead')). This ensures that the model can also be fit on the bootstrapped data.

All prediction parameters, incl prediction.end and continuous.discount.factor, are forwarded to the prediction on the bootstrapped data. Per customer, the boundaries of the confidence intervals of each predicted metric are the sample quantiles (quantile(x, probs=c((1-level)/2, 1-(1-level)/2)).

See clv.bootstrapped.apply to create a custom bootstrapping procedure.

See also

models to predict transactions: pnbd, bgnbd, ggomnbd.

models to predict spending: gg.

predict for spending models

clv.bootstrapped.apply for bootstrapped model estimation

newcustomer to create data to predict for newly alive customers.

Examples


# \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)
#> Starting estimation...
#> Estimation finished!

# Predict until the end of the holdout period
predict(apparel.pnbd)
#> Predicting from 2006-01-02 until (incl.) 2010-12-20 (259.14 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#> Key: <Id>
#>          Id period.first period.last period.length actual.x
#>      <char>       <Date>      <Date>         <num>    <int>
#>   1:      1   2006-01-02  2010-12-20      259.1429        5
#>   2:     10   2006-01-02  2010-12-20      259.1429        2
#>   3:    100   2006-01-02  2010-12-20      259.1429        9
#>   4:    101   2006-01-02  2010-12-20      259.1429        0
#>   5:    102   2006-01-02  2010-12-20      259.1429        0
#>  ---                                                       
#> 596:     95   2006-01-02  2010-12-20      259.1429        5
#> 597:     96   2006-01-02  2010-12-20      259.1429        3
#> 598:     97   2006-01-02  2010-12-20      259.1429        0
#> 599:     98   2006-01-02  2010-12-20      259.1429        0
#> 600:     99   2006-01-02  2010-12-20      259.1429        1
#>      actual.total.spending    PAlive      CET       DERT
#>                      <num>     <num>    <num>      <num>
#>   1:                524.10 0.9162891 4.081243 0.21733995
#>   2:                 63.31 0.8411075 3.746377 0.19950721
#>   3:                333.35 0.6575400 1.659795 0.08838968
#>   4:                  0.00 0.8946137 3.984698 0.21219864
#>   5:                  0.00 0.6575400 1.659795 0.08838968
#>  ---                                                    
#> 596:                113.80 0.9400738 4.187182 0.22298158
#> 597:                253.61 0.6575400 1.659795 0.08838968
#> 598:                  0.00 0.6575400 1.659795 0.08838968
#> 599:                  0.00 0.9655367 4.300596 0.22902127
#> 600:                 13.99 0.9384834 5.991230 0.31905325
#>      predicted.mean.spending predicted.total.spending predicted.CLV
#>                        <num>                    <num>         <num>
#>   1:                63.77959                260.30000     13.861854
#>   2:                38.10316                142.74877      7.601854
#>   3:                37.12434                 61.61878      3.281408
#>   4:                33.08404                131.82992      7.020388
#>   5:                37.12434                 61.61878      3.281408
#>  ---                                                               
#> 596:                28.29614                118.48111      6.309519
#> 597:                37.12434                 61.61878      3.281408
#> 598:                37.12434                 61.61878      3.281408
#> 599:                34.87739                149.99357      7.987664
#> 600:                16.11315                 96.53757      5.140952

# 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
#> Predicting from 2006-01-02 until (incl.) 2006-03-12 (10 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#> Key: <Id>
#>          Id period.first period.last period.length actual.x
#>      <char>       <Date>      <Date>         <int>    <int>
#>   1:      1   2006-01-02  2006-03-12            10        1
#>   2:     10   2006-01-02  2006-03-12            10        0
#>   3:    100   2006-01-02  2006-03-12            10        0
#>   4:    101   2006-01-02  2006-03-12            10        0
#>   5:    102   2006-01-02  2006-03-12            10        0
#>  ---                                                       
#> 596:     95   2006-01-02  2006-03-12            10        0
#> 597:     96   2006-01-02  2006-03-12            10        0
#> 598:     97   2006-01-02  2006-03-12            10        0
#> 599:     98   2006-01-02  2006-03-12            10        0
#> 600:     99   2006-01-02  2006-03-12            10        0
#>      actual.total.spending    PAlive        CET       DERT
#>                      <num>     <num>      <num>      <num>
#>   1:                131.07 0.9162891 0.21100460 0.21733995
#>   2:                  0.00 0.8411075 0.19369167 0.19950721
#>   3:                  0.00 0.6575400 0.08581316 0.08838968
#>   4:                  0.00 0.8946137 0.20601315 0.21219864
#>   5:                  0.00 0.6575400 0.08581316 0.08838968
#>  ---                                                      
#> 596:                  0.00 0.9400738 0.21648178 0.22298158
#> 597:                  0.00 0.6575400 0.08581316 0.08838968
#> 598:                  0.00 0.6575400 0.08581316 0.08838968
#> 599:                  0.00 0.9655367 0.22234542 0.22902127
#> 600:                  0.00 0.9384834 0.30975300 0.31905325
#>      predicted.mean.spending predicted.total.spending predicted.CLV
#>                        <num>                    <num>         <num>
#>   1:                63.77959                13.457787     13.861854
#>   2:                38.10316                 7.380264      7.601854
#>   3:                37.12434                 3.185757      3.281408
#>   4:                33.08404                 6.815748      7.020388
#>   5:                37.12434                 3.185757      3.281408
#>  ---                                                               
#> 596:                28.29614                 6.125600      6.309519
#> 597:                37.12434                 3.185757      3.281408
#> 598:                37.12434                 3.185757      3.281408
#> 599:                34.87739                 7.754827      7.987664
#> 600:                16.11315                 4.991095      5.140952

# Predict until 31th Dec 2016 with the timepoint as a character
predict(apparel.pnbd, prediction.end = "2016-12-31")
#> Predicting from 2006-01-02 until (incl.) 2016-12-31 (573.86 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#> Key: <Id>
#>          Id period.first period.last period.length    PAlive       CET
#>      <char>       <Date>      <Date>         <num>     <num>     <num>
#>   1:      1   2006-01-02  2016-12-31      573.8571 0.9162891  7.439917
#>   2:     10   2006-01-02  2016-12-31      573.8571 0.8411075  6.829472
#>   3:    100   2006-01-02  2016-12-31      573.8571 0.6575400  3.025729
#>   4:    101   2006-01-02  2016-12-31      573.8571 0.8946137  7.263921
#>   5:    102   2006-01-02  2016-12-31      573.8571 0.6575400  3.025729
#>  ---                                                                  
#> 596:     95   2006-01-02  2016-12-31      573.8571 0.9400738  7.633040
#> 597:     96   2006-01-02  2016-12-31      573.8571 0.6575400  3.025729
#> 598:     97   2006-01-02  2016-12-31      573.8571 0.6575400  3.025729
#> 599:     98   2006-01-02  2016-12-31      573.8571 0.9655367  7.839788
#> 600:     99   2006-01-02  2016-12-31      573.8571 0.9384834 10.921736
#>            DERT predicted.mean.spending predicted.total.spending predicted.CLV
#>           <num>                   <num>                    <num>         <num>
#>   1: 0.21733995                63.77959                 474.5149     13.861854
#>   2: 0.19950721                38.10316                 260.2244      7.601854
#>   3: 0.08838968                37.12434                 112.3282      3.281408
#>   4: 0.21219864                33.08404                 240.3199      7.020388
#>   5: 0.08838968                37.12434                 112.3282      3.281408
#>  ---                                                                          
#> 596: 0.22298158                28.29614                 215.9856      6.309519
#> 597: 0.08838968                37.12434                 112.3282      3.281408
#> 598: 0.08838968                37.12434                 112.3282      3.281408
#> 599: 0.22902127                34.87739                 273.4313      7.987664
#> 600: 0.31905325                16.11315                 175.9835      5.140952

# Predict until 31th Dec 2016 with the timepoint as a Date
predict(apparel.pnbd, prediction.end = lubridate::ymd("2016-12-31"))
#> Predicting from 2006-01-02 until (incl.) 2016-12-31 (573.86 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#> Key: <Id>
#>          Id period.first period.last period.length    PAlive       CET
#>      <char>       <Date>      <Date>         <num>     <num>     <num>
#>   1:      1   2006-01-02  2016-12-31      573.8571 0.9162891  7.439917
#>   2:     10   2006-01-02  2016-12-31      573.8571 0.8411075  6.829472
#>   3:    100   2006-01-02  2016-12-31      573.8571 0.6575400  3.025729
#>   4:    101   2006-01-02  2016-12-31      573.8571 0.8946137  7.263921
#>   5:    102   2006-01-02  2016-12-31      573.8571 0.6575400  3.025729
#>  ---                                                                  
#> 596:     95   2006-01-02  2016-12-31      573.8571 0.9400738  7.633040
#> 597:     96   2006-01-02  2016-12-31      573.8571 0.6575400  3.025729
#> 598:     97   2006-01-02  2016-12-31      573.8571 0.6575400  3.025729
#> 599:     98   2006-01-02  2016-12-31      573.8571 0.9655367  7.839788
#> 600:     99   2006-01-02  2016-12-31      573.8571 0.9384834 10.921736
#>            DERT predicted.mean.spending predicted.total.spending predicted.CLV
#>           <num>                   <num>                    <num>         <num>
#>   1: 0.21733995                63.77959                 474.5149     13.861854
#>   2: 0.19950721                38.10316                 260.2244      7.601854
#>   3: 0.08838968                37.12434                 112.3282      3.281408
#>   4: 0.21219864                33.08404                 240.3199      7.020388
#>   5: 0.08838968                37.12434                 112.3282      3.281408
#>  ---                                                                          
#> 596: 0.22298158                28.29614                 215.9856      6.309519
#> 597: 0.08838968                37.12434                 112.3282      3.281408
#> 598: 0.08838968                37.12434                 112.3282      3.281408
#> 599: 0.22902127                34.87739                 273.4313      7.987664
#> 600: 0.31905325                16.11315                 175.9835      5.140952


# Predict future transactions but not spending and CLV
predict(apparel.pnbd, predict.spending = FALSE)
#> Predicting from 2006-01-02 until (incl.) 2010-12-20 (259.14 Weeks).
#> Key: <Id>
#>          Id period.first period.last period.length actual.x
#>      <char>       <Date>      <Date>         <num>    <int>
#>   1:      1   2006-01-02  2010-12-20      259.1429        5
#>   2:     10   2006-01-02  2010-12-20      259.1429        2
#>   3:    100   2006-01-02  2010-12-20      259.1429        9
#>   4:    101   2006-01-02  2010-12-20      259.1429        0
#>   5:    102   2006-01-02  2010-12-20      259.1429        0
#>  ---                                                       
#> 596:     95   2006-01-02  2010-12-20      259.1429        5
#> 597:     96   2006-01-02  2010-12-20      259.1429        3
#> 598:     97   2006-01-02  2010-12-20      259.1429        0
#> 599:     98   2006-01-02  2010-12-20      259.1429        0
#> 600:     99   2006-01-02  2010-12-20      259.1429        1
#>      actual.total.spending    PAlive      CET       DERT
#>                      <num>     <num>    <num>      <num>
#>   1:                524.10 0.9162891 4.081243 0.21733995
#>   2:                 63.31 0.8411075 3.746377 0.19950721
#>   3:                333.35 0.6575400 1.659795 0.08838968
#>   4:                  0.00 0.8946137 3.984698 0.21219864
#>   5:                  0.00 0.6575400 1.659795 0.08838968
#>  ---                                                    
#> 596:                113.80 0.9400738 4.187182 0.22298158
#> 597:                253.61 0.6575400 1.659795 0.08838968
#> 598:                  0.00 0.6575400 1.659795 0.08838968
#> 599:                  0.00 0.9655367 4.300596 0.22902127
#> 600:                 13.99 0.9384834 5.991230 0.31905325

# Predict spending by fitting a Gamma-Gamma model
predict(apparel.pnbd, predict.spending = gg)
#> Predicting from 2006-01-02 until (incl.) 2010-12-20 (259.14 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#> Key: <Id>
#>          Id period.first period.last period.length actual.x
#>      <char>       <Date>      <Date>         <num>    <int>
#>   1:      1   2006-01-02  2010-12-20      259.1429        5
#>   2:     10   2006-01-02  2010-12-20      259.1429        2
#>   3:    100   2006-01-02  2010-12-20      259.1429        9
#>   4:    101   2006-01-02  2010-12-20      259.1429        0
#>   5:    102   2006-01-02  2010-12-20      259.1429        0
#>  ---                                                       
#> 596:     95   2006-01-02  2010-12-20      259.1429        5
#> 597:     96   2006-01-02  2010-12-20      259.1429        3
#> 598:     97   2006-01-02  2010-12-20      259.1429        0
#> 599:     98   2006-01-02  2010-12-20      259.1429        0
#> 600:     99   2006-01-02  2010-12-20      259.1429        1
#>      actual.total.spending    PAlive      CET       DERT
#>                      <num>     <num>    <num>      <num>
#>   1:                524.10 0.9162891 4.081243 0.21733995
#>   2:                 63.31 0.8411075 3.746377 0.19950721
#>   3:                333.35 0.6575400 1.659795 0.08838968
#>   4:                  0.00 0.8946137 3.984698 0.21219864
#>   5:                  0.00 0.6575400 1.659795 0.08838968
#>  ---                                                    
#> 596:                113.80 0.9400738 4.187182 0.22298158
#> 597:                253.61 0.6575400 1.659795 0.08838968
#> 598:                  0.00 0.6575400 1.659795 0.08838968
#> 599:                  0.00 0.9655367 4.300596 0.22902127
#> 600:                 13.99 0.9384834 5.991230 0.31905325
#>      predicted.mean.spending predicted.total.spending predicted.CLV
#>                        <num>                    <num>         <num>
#>   1:                63.77959                260.30000     13.861854
#>   2:                38.10316                142.74877      7.601854
#>   3:                37.12434                 61.61878      3.281408
#>   4:                33.08404                131.82992      7.020388
#>   5:                37.12434                 61.61878      3.281408
#>  ---                                                               
#> 596:                28.29614                118.48111      6.309519
#> 597:                37.12434                 61.61878      3.281408
#> 598:                37.12434                 61.61878      3.281408
#> 599:                34.87739                149.99357      7.987664
#> 600:                16.11315                 96.53757      5.140952

# Fit a spending model separately and use it to predict spending
apparel.gg <- gg(apparel.holdout, remove.first.transaction = FALSE)
#> Starting estimation...
#> Estimation finished!
predict(apparel.pnbd, predict.spending = apparel.gg)
#> Predicting from 2006-01-02 until (incl.) 2010-12-20 (259.14 Weeks).
#> Key: <Id>
#>          Id period.first period.last period.length actual.x
#>      <char>       <Date>      <Date>         <num>    <int>
#>   1:      1   2006-01-02  2010-12-20      259.1429        5
#>   2:     10   2006-01-02  2010-12-20      259.1429        2
#>   3:    100   2006-01-02  2010-12-20      259.1429        9
#>   4:    101   2006-01-02  2010-12-20      259.1429        0
#>   5:    102   2006-01-02  2010-12-20      259.1429        0
#>  ---                                                       
#> 596:     95   2006-01-02  2010-12-20      259.1429        5
#> 597:     96   2006-01-02  2010-12-20      259.1429        3
#> 598:     97   2006-01-02  2010-12-20      259.1429        0
#> 599:     98   2006-01-02  2010-12-20      259.1429        0
#> 600:     99   2006-01-02  2010-12-20      259.1429        1
#>      actual.total.spending    PAlive      CET       DERT
#>                      <num>     <num>    <num>      <num>
#>   1:                524.10 0.9162891 4.081243 0.21733995
#>   2:                 63.31 0.8411075 3.746377 0.19950721
#>   3:                333.35 0.6575400 1.659795 0.08838968
#>   4:                  0.00 0.8946137 3.984698 0.21219864
#>   5:                  0.00 0.6575400 1.659795 0.08838968
#>  ---                                                    
#> 596:                113.80 0.9400738 4.187182 0.22298158
#> 597:                253.61 0.6575400 1.659795 0.08838968
#> 598:                  0.00 0.6575400 1.659795 0.08838968
#> 599:                  0.00 0.9655367 4.300596 0.22902127
#> 600:                 13.99 0.9384834 5.991230 0.31905325
#>      predicted.mean.spending predicted.total.spending predicted.CLV
#>                        <num>                    <num>         <num>
#>   1:               136.73183                558.03579     29.717289
#>   2:                29.00428                108.66095      5.786562
#>   3:                48.90849                 81.17806      4.323006
#>   4:                31.76895                126.58969      6.741328
#>   5:                77.59707                128.79522      6.858780
#>  ---                                                               
#> 596:                21.67439                 90.75460      4.832989
#> 597:                45.64301                 75.75803      4.034371
#> 598:                29.53283                 49.01844      2.610398
#> 599:                32.46527                139.62002      7.435238
#> 600:                22.06995                132.22615      7.041489


# Fit pnbd standard model WITHOUT holdout
pnc <- pnbd(clvdata(apparelTrans, time.unit="w", date.format="ymd"))
#> Starting estimation...
#> Estimation finished!

# This fails, because without holdout, a prediction.end is required
if (FALSE) { # \dontrun{
predict(pnc)
} # }

# But it works if providing a prediction.end
predict(pnc, prediction.end = 10) # ends on 2016-12-17
#> Predicting from 2010-12-21 until (incl.) 2011-02-28 (10 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#> Key: <Id>
#>          Id period.first period.last period.length      PAlive         CET
#>      <char>       <Date>      <Date>         <int>       <num>       <num>
#>   1:      1   2010-12-21  2011-02-28            10 0.007191623 0.001466915
#>   2:     10   2010-12-21  2011-02-28            10 0.836860928 0.101279050
#>   3:    100   2010-12-21  2011-02-28            10 0.922281780 0.264629016
#>   4:    101   2010-12-21  2011-02-28            10 0.053020374 0.003484528
#>   5:    102   2010-12-21  2011-02-28            10 0.061489323 0.002340870
#>  ---                                                                      
#> 596:     95   2010-12-21  2011-02-28            10 0.697534261 0.142279953
#> 597:     96   2010-12-21  2011-02-28            10 0.551357052 0.066726640
#> 598:     97   2010-12-21  2011-02-28            10 0.061489323 0.002340870
#> 599:     98   2010-12-21  2011-02-28            10 0.077985685 0.005125262
#> 600:     99   2010-12-21  2011-02-28            10 0.065543374 0.007932227
#>             DERT predicted.mean.spending predicted.total.spending predicted.CLV
#>            <num>                   <num>                    <num>         <num>
#>   1: 0.001524793                77.79363                0.1141167    0.11861922
#>   2: 0.105275083                36.04491                3.6505939    3.79463052
#>   3: 0.275070134                37.23417                9.8532412   10.24200757
#>   4: 0.003622012                36.01842                0.1255072    0.13045916
#>   5: 0.002433231                37.73097                0.0883233    0.09180815
#>  ---                                                                           
#> 596: 0.147893705                28.17770                4.0091225    4.16730515
#> 597: 0.069359385                59.20915                3.9508274    4.10671002
#> 598: 0.002433231                37.73097                0.0883233    0.09180815
#> 599: 0.005327482                36.71922                0.1881956    0.19562100
#> 600: 0.008245198                25.00120                0.1983152    0.20613989

# 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))
#> [1] 0.09627075

# }