Fits Pareto/NBD models on transactional data with and without covariates.

# S4 method for clv.data
pnbd(
  clv.data,
  start.params.model = c(),
  use.cor = FALSE,
  start.param.cor = c(),
  optimx.args = list(),
  verbose = TRUE,
  ...
)

# S4 method for clv.data.static.covariates
pnbd(
  clv.data,
  start.params.model = c(),
  use.cor = FALSE,
  start.param.cor = c(),
  optimx.args = list(),
  verbose = TRUE,
  names.cov.life = c(),
  names.cov.trans = c(),
  start.params.life = c(),
  start.params.trans = c(),
  names.cov.constr = c(),
  start.params.constr = c(),
  reg.lambdas = c(),
  ...
)

# S4 method for clv.data.dynamic.covariates
pnbd(
  clv.data,
  start.params.model = c(),
  use.cor = FALSE,
  start.param.cor = c(),
  optimx.args = list(),
  verbose = TRUE,
  names.cov.life = c(),
  names.cov.trans = c(),
  start.params.life = c(),
  start.params.trans = c(),
  names.cov.constr = c(),
  start.params.constr = c(),
  reg.lambdas = c(),
  ...
)

Arguments

clv.data

The data object on which the model is fitted.

start.params.model

Named start parameters containing the optimization start parameters for the model without covariates.

use.cor

Whether the correlation between the transaction and lifetime process should be estimated.

start.param.cor

Start parameter for the optimization of the correlation.

optimx.args

Additional arguments to control the optimization which are forwarded to optimx::optimx. If multiple optimization methods are specified, only the result of the last method is further processed.

verbose

Show details about the running of the function.

...

Ignored

names.cov.life

Which of the set Lifetime covariates should be used. Missing parameter indicates all covariates shall be used.

names.cov.trans

Which of the set Transaction covariates should be used. Missing parameter indicates all covariates shall be used.

start.params.life

Named start parameters containing the optimization start parameters for all lifetime covariates.

start.params.trans

Named start parameters containing the optimization start parameters for all transaction covariates.

names.cov.constr

Which covariates should be forced to use the same parameters for the lifetime and transaction process. The covariates need to be present as both, lifetime and transaction covariates.

start.params.constr

Named start parameters containing the optimization start parameters for the constraint covariates.

reg.lambdas

Named lambda parameters used for the L2 regularization of the lifetime and the transaction covariate parameters. Lambdas have to be >= 0.

Value

Depending on the data object on which the model was fit, pnbd returns either an object of class clv.pnbd, clv.pnbd.static.cov, or clv.pnbd.dynamic.cov.

The function summary can be used to obtain and print a summary of the results. The generic accessor functions coefficients, vcov, fitted, logLik, AIC, BIC, and nobs are available.

Details

Model parameters for the Pareto/NBD model are alpha, r, beta, and s.
s: shape parameter of the Gamma distribution for the lifetime process. The smaller s, the stronger the heterogeneity of customer lifetimes.
beta: rate parameter for the Gamma distribution for the lifetime process.
r: shape parameter of the Gamma distribution of the purchase process. The smaller r, the stronger the heterogeneity of the purchase process.
alpha: rate parameter of the Gamma distribution of the purchase process.

Based on these parameters, the average purchase rate while customers are active is r/alpha and the average dropout rate is s/beta.

Ideally, the starting parameters for r and s represent your best guess concerning the heterogeneity of customers in their buy and die rate. If covariates are included into the model additionally parameters for the covariates affecting the attrition and the purchase process are part of the model.

If no start parameters are given, 1.0 is used for all model parameters and 0.1 for covariate parameters. The model start parameters are required to be > 0.

The Pareto/NBD model

The Pareto/NBD is the first model addressing the issue of modeling customer purchases and attrition simultaneously for non-contractual settings. The model uses a Pareto distribution, a combination of an Exponential and a Gamma distribution, to explicitly model customers' (unobserved) attrition behavior in addition to customers' purchase process.
In general, the Pareto/NBD model consist of two parts. A first process models the purchase behavior of customers as long as the customers are active. A second process models customers' attrition. Customers live (and buy) for a certain unknown time until they become inactive and "die". Customer attrition is unobserved. Inactive customers may not be reactivated. For technical details we refer to the original paper by Schmittlein, Morrison and Colombo (1987) and the detailed technical note of Fader and Hardie (2005).

Pareto/NBD model with static covariates

The standard Pareto/NBD model captures heterogeneity was solely using Gamma distributions. However, often exogenous knowledge, such as for example customer demographics, is available. The supplementary knowledge may explain part of the heterogeneity among the customers and therefore increase the predictive accuracy of the model. In addition, we can rely on these parameter estimates for inference, i.e. identify and quantify effects of contextual factors on the two underlying purchase and attrition processes. For technical details we refer to the technical note by Fader and Hardie (2007).

Pareto/NBD model with dynamic covariates

In many real-world applications customer purchase and attrition behavior may be influenced by covariates that vary over time. In consequence, the timing of a purchase and the corresponding value of at covariate a that time becomes relevant. Time-varying covariates can affect customer on aggregated level as well as on an individual level: In the first case, all customers are affected simultaneously, in the latter case a covariate is only relevant for a particular customer. For technical details we refer to the paper by Bachmann, Meierer and Näf (2020).

Note

The Pareto/NBD model with dynamic covariates can currently not be fit with data that has a temporal resolution of less than one day (data that was built with time unit hours).

References

Schmittlein DC, Morrison DG, Colombo R (1987). “Counting Your Customers: Who-Are They and What Will They Do Next?” Management Science, 33(1), 1-24.

Bachmann P, Meierer M, Naef, J (2021). “The Role of Time-Varying Contextual Factors in Latent Attrition Models for Customer Base Analysis” Marketing Science 40(4). 783-809.

Fader PS, Hardie BGS (2005). “A Note on Deriving the Pareto/NBD Model and Related Expressions.” URL http://www.brucehardie.com/notes/009/pareto_nbd_derivations_2005-11-05.pdf.

Fader PS, Hardie BGS (2007). “Incorporating time-invariant covariates into the Pareto/NBD and BG/NBD models.” URL http://www.brucehardie.com/notes/019/time_invariant_covariates.pdf.

Fader PS, Hardie BGS (2020). “Deriving an Expression for P(X(t)=x) Under the Pareto/NBD Model.” URL https://www.brucehardie.com/notes/012/pareto_NBD_pmf_derivation_rev.pdf

See also

clvdata to create a clv data object, SetStaticCovariates to add static covariates to an existing clv data object.

gg to fit customer's average spending per transaction with the Gamma-Gamma model

predict to predict expected transactions, probability of being alive, and customer lifetime value for every customer

plot to plot the unconditional expectation as predicted by the fitted model

pmf for the probability to make exactly x transactions in the estimation period, given by the probability mass function (PMF).

The generic functions vcov, summary, fitted.

SetDynamicCovariates to add dynamic covariates on which the pnbd model can be fit.

Examples

# \donttest{
data("apparelTrans")
clv.data.apparel <- clvdata(apparelTrans, date.format = "ymd",
                            time.unit = "w", estimation.split = 40)

# Fit standard pnbd model
pnbd(clv.data.apparel)
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD Standard Model
#> 
#> Call:
#> pnbd(clv.data = clv.data.apparel)
#> 
#> Coefficients:
#>       r    alpha        s     beta  
#>  0.7866   5.3349   0.3570  11.6152  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 

# Give initial guesses for the model parameters
pnbd(clv.data.apparel,
     start.params.model = c(r=0.5, alpha=15, s=0.5, beta=10))
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD Standard Model
#> 
#> Call:
#> pnbd(clv.data = clv.data.apparel, start.params.model = c(r = 0.5, 
#>     alpha = 15, s = 0.5, beta = 10))
#> 
#> Coefficients:
#>       r    alpha        s     beta  
#>  0.7858   5.3312   0.3606  11.8221  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 


# pass additional parameters to the optimizer (optimx)
#    Use Nelder-Mead as optimization method and print
#    detailed information about the optimization process
apparel.pnbd <- pnbd(clv.data.apparel,
                     optimx.args = list(method="Nelder-Mead",
                                        control=list(trace=6)))
#> Starting estimation...
#> fn is  fn1 
#> Looking for method =  Nelder-Mead 
#> Methods to be used:[1] "Nelder-Mead"
#> optcfg:$fname
#> [1] "fn1"
#> 
#> $npar
#> [1] 4
#> 
#> $ctrl
#> $ctrl$follow.on
#> [1] FALSE
#> 
#> $ctrl$save.failures
#> [1] TRUE
#> 
#> $ctrl$trace
#> [1] 6
#> 
#> $ctrl$kkt
#> [1] TRUE
#> 
#> $ctrl$all.methods
#> [1] FALSE
#> 
#> $ctrl$starttests
#> [1] FALSE
#> 
#> $ctrl$maximize
#> [1] FALSE
#> 
#> $ctrl$dowarn
#> [1] TRUE
#> 
#> $ctrl$usenumDeriv
#> [1] FALSE
#> 
#> $ctrl$kkttol
#> [1] 0.001
#> 
#> $ctrl$kkt2tol
#> [1] 1e-06
#> 
#> $ctrl$badval
#> [1] 8.988466e+307
#> 
#> $ctrl$scaletol
#> [1] 3
#> 
#> $ctrl$have.bounds
#> [1] FALSE
#> 
#> 
#> $usenumDeriv
#> [1] FALSE
#> 
#> $ufn
#> function (par) 
#> fn(par, ...)
#> <bytecode: 0x7fb5826c0950>
#> <environment: 0x7fb58724c140>
#> 
#> $have.bounds
#> [1] FALSE
#> 
#> $method
#> [1] "Nelder-Mead"
#> 
#> Method:  Nelder-Mead 
#>   Nelder-Mead direct search function minimizer
#> function value for initial parameters = 3324.183952
#>   Scaled convergence tolerance is 4.95342e-05
#> Stepsize computed as 0.100000
#> BUILD              5 3370.858623 3309.338871
#> EXTENSION          7 3349.894066 3246.484880
#> LO-REDUCTION       9 3324.183952 3246.484880
#> EXTENSION         11 3311.326140 3192.670595
#> EXTENSION         13 3309.338871 3136.995127
#> EXTENSION         15 3246.890840 3070.661973
#> LO-REDUCTION      17 3246.484880 3070.661973
#> EXTENSION         19 3192.670595 2962.711423
#> LO-REDUCTION      21 3136.995127 2962.711423
#> LO-REDUCTION      23 3092.779244 2962.711423
#> EXTENSION         25 3070.661973 2904.899192
#> EXTENSION         27 2979.692293 2901.790592
#> REFLECTION        29 2971.137892 2896.215344
#> LO-REDUCTION      31 2962.711423 2890.642122
#> LO-REDUCTION      33 2906.533400 2890.642122
#> LO-REDUCTION      35 2904.899192 2890.642122
#> HI-REDUCTION      37 2901.790592 2890.642122
#> LO-REDUCTION      39 2896.854291 2890.642122
#> LO-REDUCTION      41 2896.733398 2890.642122
#> LO-REDUCTION      43 2896.215344 2890.642122
#> EXTENSION         45 2895.169640 2884.464824
#> LO-REDUCTION      47 2891.545912 2884.464824
#> LO-REDUCTION      49 2890.755169 2884.464824
#> EXTENSION         51 2890.642122 2882.953045
#> REFLECTION        53 2888.700681 2882.446051
#> LO-REDUCTION      55 2884.570203 2882.446051
#> HI-REDUCTION      57 2884.464824 2882.446051
#> LO-REDUCTION      59 2883.270678 2882.446051
#> HI-REDUCTION      61 2882.953045 2882.396690
#> HI-REDUCTION      63 2882.895319 2882.314190
#> HI-REDUCTION      65 2882.482512 2882.248928
#> HI-REDUCTION      67 2882.446051 2882.248928
#> HI-REDUCTION      69 2882.396690 2882.240024
#> LO-REDUCTION      71 2882.314190 2882.191572
#> LO-REDUCTION      73 2882.251157 2882.163573
#> LO-REDUCTION      75 2882.248928 2882.163573
#> HI-REDUCTION      77 2882.240024 2882.163573
#> HI-REDUCTION      79 2882.191572 2882.162231
#> HI-REDUCTION      81 2882.167468 2882.140209
#> LO-REDUCTION      83 2882.166824 2882.140209
#> HI-REDUCTION      85 2882.163573 2882.140209
#> LO-REDUCTION      87 2882.162231 2882.138172
#> REFLECTION        89 2882.144473 2882.137304
#> LO-REDUCTION      91 2882.141601 2882.135061
#> HI-REDUCTION      93 2882.140209 2882.132257
#> REFLECTION        95 2882.138172 2882.129096
#> EXTENSION         97 2882.137304 2882.117858
#> LO-REDUCTION      99 2882.135061 2882.117858
#> LO-REDUCTION     101 2882.132257 2882.117858
#> EXTENSION        103 2882.129096 2882.106725
#> EXTENSION        105 2882.126478 2882.091916
#> LO-REDUCTION     107 2882.119912 2882.091916
#> LO-REDUCTION     109 2882.117858 2882.091916
#> EXTENSION        111 2882.106725 2882.071824
#> LO-REDUCTION     113 2882.104616 2882.071824
#> EXTENSION        115 2882.099252 2882.044612
#> EXTENSION        117 2882.091916 2882.012574
#> LO-REDUCTION     119 2882.079287 2882.012574
#> EXTENSION        121 2882.071824 2881.969055
#> EXTENSION        123 2882.044612 2881.898069
#> LO-REDUCTION     125 2882.032117 2881.898069
#> EXTENSION        127 2882.012574 2881.780423
#> LO-REDUCTION     129 2881.969055 2881.780423
#> EXTENSION        131 2881.918692 2881.640737
#> LO-REDUCTION     133 2881.898069 2881.640737
#> EXTENSION        135 2881.809312 2881.425073
#> LO-REDUCTION     137 2881.780423 2881.425073
#> EXTENSION        139 2881.647928 2881.303066
#> EXTENSION        141 2881.640737 2881.229749
#> REFLECTION       143 2881.430767 2881.166043
#> LO-REDUCTION     145 2881.425073 2881.166043
#> HI-REDUCTION     147 2881.303066 2881.166043
#> EXTENSION        149 2881.279120 2881.119888
#> EXTENSION        151 2881.277302 2881.042370
#> LO-REDUCTION     153 2881.229749 2881.042370
#> EXTENSION        155 2881.166043 2880.967832
#> EXTENSION        157 2881.119888 2880.879994
#> LO-REDUCTION     159 2881.087359 2880.879994
#> REFLECTION       161 2881.042370 2880.879853
#> LO-REDUCTION     163 2880.967832 2880.879853
#> LO-REDUCTION     165 2880.901343 2880.879853
#> HI-REDUCTION     167 2880.882262 2880.869537
#> REFLECTION       169 2880.881546 2880.868296
#> REFLECTION       171 2880.879994 2880.855871
#> HI-REDUCTION     173 2880.879853 2880.854640
#> HI-REDUCTION     175 2880.869537 2880.854640
#> EXTENSION        177 2880.868296 2880.818013
#> LO-REDUCTION     179 2880.857420 2880.818013
#> LO-REDUCTION     181 2880.855871 2880.818013
#> LO-REDUCTION     183 2880.854640 2880.818013
#> EXTENSION        185 2880.842474 2880.781988
#> LO-REDUCTION     187 2880.842315 2880.781988
#> LO-REDUCTION     189 2880.832743 2880.781988
#> EXTENSION        191 2880.818013 2880.720303
#> EXTENSION        193 2880.795624 2880.670354
#> LO-REDUCTION     195 2880.787343 2880.670354
#> EXTENSION        197 2880.781988 2880.617628
#> EXTENSION        199 2880.720303 2880.439926
#> LO-REDUCTION     201 2880.680023 2880.439926
#> EXTENSION        203 2880.670354 2880.358120
#> EXTENSION        205 2880.617628 2880.277481
#> EXTENSION        207 2880.473779 2879.924264
#> LO-REDUCTION     209 2880.439926 2879.924264
#> LO-REDUCTION     211 2880.358120 2879.924264
#> LO-REDUCTION     213 2880.277481 2879.924264
#> EXTENSION        215 2880.105129 2879.758291
#> EXTENSION        217 2880.090475 2879.608276
#> LO-REDUCTION     219 2879.960968 2879.608276
#> LO-REDUCTION     221 2879.924264 2879.608276
#> HI-REDUCTION     223 2879.758291 2879.608276
#> REFLECTION       225 2879.713263 2879.550139
#> LO-REDUCTION     227 2879.630410 2879.550139
#> EXTENSION        229 2879.610548 2879.511643
#> LO-REDUCTION     231 2879.608276 2879.511643
#> REFLECTION       233 2879.568497 2879.480952
#> LO-REDUCTION     235 2879.550139 2879.480952
#> LO-REDUCTION     237 2879.526502 2879.480952
#> LO-REDUCTION     239 2879.511643 2879.480932
#> REFLECTION       241 2879.492292 2879.478755
#> LO-REDUCTION     243 2879.484230 2879.476099
#> LO-REDUCTION     245 2879.480952 2879.475526
#> REFLECTION       247 2879.480932 2879.471443
#> HI-REDUCTION     249 2879.478755 2879.471443
#> HI-REDUCTION     251 2879.476099 2879.471443
#> LO-REDUCTION     253 2879.475526 2879.471441
#> LO-REDUCTION     255 2879.473131 2879.470985
#> LO-REDUCTION     257 2879.472498 2879.470985
#> HI-REDUCTION     259 2879.471443 2879.470914
#> HI-REDUCTION     261 2879.471441 2879.470638
#> REFLECTION       263 2879.471127 2879.470444
#> HI-REDUCTION     265 2879.470985 2879.470444
#> HI-REDUCTION     267 2879.470914 2879.470444
#> HI-REDUCTION     269 2879.470638 2879.470444
#> REFLECTION       271 2879.470543 2879.470242
#> LO-REDUCTION     273 2879.470526 2879.470242
#> EXTENSION        275 2879.470450 2879.470087
#> LO-REDUCTION     277 2879.470444 2879.470087
#> LO-REDUCTION     279 2879.470311 2879.470087
#> LO-REDUCTION     281 2879.470242 2879.470087
#> REFLECTION       283 2879.470158 2879.470001
#> HI-REDUCTION     285 2879.470109 2879.470001
#> LO-REDUCTION     287 2879.470101 2879.470001
#> LO-REDUCTION     289 2879.470087 2879.470001
#> Exiting from Nelder Mead minimizer
#>     291 function evaluations used
#> Post processing for method  Nelder-Mead 
#> Successful convergence! 
#> Compute Hessian approximation at finish of  Nelder-Mead 
#> Compute gradient approximation at finish of  Nelder-Mead 
#> Save results from method  Nelder-Mead 
#> $par
#>     log.r log.alpha     log.s  log.beta 
#> -0.238902  1.675864 -1.030490  2.452082 
#> 
#> $value
#> [1] 2879.47
#> 
#> $message
#> NULL
#> 
#> $convcode
#> [1] 0
#> 
#> $fevals
#> function 
#>      291 
#> 
#> $gevals
#> gradient 
#>       NA 
#> 
#> $nitns
#> [1] NA
#> 
#> $kkt1
#> [1] TRUE
#> 
#> $kkt2
#> [1] TRUE
#> 
#> $xtimes
#> user.self 
#>     0.122 
#> 
#> Assemble the answers
#> Estimation finished!

# estimated coefs
coef(apparel.pnbd)
#>         r     alpha         s      beta 
#>  0.787492  5.343412  0.356832 11.612502 

# summary of the fitted model
summary(apparel.pnbd)
#> Pareto/NBD Standard  Model 
#> 
#> Call:
#> pnbd(clv.data = clv.data.apparel, optimx.args = list(method = "Nelder-Mead", 
#>     control = list(trace = 6)))
#> 
#> Fitting period:                               
#> Estimation start  2005-01-03   
#> Estimation end    2005-10-10   
#> Estimation length 40.0000 Weeks
#> 
#> Coefficients:
#>       Estimate Std. Error z-val Pr(>|z|)    
#> r       0.7875     0.1326 5.941 2.83e-09 ***
#> alpha   5.3434     0.9039 5.912 3.38e-09 ***
#> s       0.3568     0.1833 1.947   0.0515 .  
#> beta   11.6125    10.6334 1.092   0.2748    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Optimization info:                  
#> LL     -2879.4700 
#> AIC    5766.9400  
#> BIC    5781.0258  
#> KKT 1  TRUE       
#> KKT 2  TRUE       
#> fevals 291.0000   
#> Method Nelder-Mead
#> 
#> Used Options:                 
#> Correlation FALSE

# predict CLV etc for holdout period
predict(apparel.pnbd)
#> Predicting from 2005-10-11 until (incl.) 2006-07-16 (39.86 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#>        Id period.first period.last period.length actual.x actual.total.spending
#>   1:    1   2005-10-11  2006-07-16      39.85714        0                  0.00
#>   2:   10   2005-10-11  2006-07-16      39.85714        0                  0.00
#>   3:  100   2005-10-11  2006-07-16      39.85714       23                737.53
#>   4: 1000   2005-10-11  2006-07-16      39.85714       23               1069.91
#>   5: 1001   2005-10-11  2006-07-16      39.85714       11                364.00
#>  ---                                                                           
#> 246: 1219   2005-10-11  2006-07-16      39.85714       14                413.76
#> 247:  122   2005-10-11  2006-07-16      39.85714        0                  0.00
#> 248: 1220   2005-10-11  2006-07-16      39.85714        0                  0.00
#> 249: 1221   2005-10-11  2006-07-16      39.85714        9                302.65
#> 250: 1222   2005-10-11  2006-07-16      39.85714        0                  0.00
#>         PAlive        CET       DERT predicted.mean.spending predicted.CLV
#>   1: 0.3571652  0.2214654 0.05854369                39.95483      2.339103
#>   2: 0.4226928  0.9277460 0.24524673                55.23031     13.545053
#>   3: 0.9156048 13.5446396 3.58048291                43.57390    156.015602
#>   4: 0.9967799 13.1757590 3.48297048                41.60921    144.923640
#>   5: 0.5100298  3.5289953 0.93287881                45.58153     42.522040
#>  ---                                                                      
#> 246: 0.9579466  3.6111037 0.95458391                33.58728     32.061875
#> 247: 0.3571652  0.2214654 0.05854369                39.95483      2.339103
#> 248: 0.3571652  0.2214654 0.05854369                39.95483      2.339103
#> 249: 0.9434610  4.2993712 1.13652527                34.28958     38.970974
#> 250: 0.4137006  0.5822653 0.15391999                47.35500      7.288881

# predict CLV etc for the next 15 periods
predict(apparel.pnbd, prediction.end = 15)
#> Predicting from 2005-10-11 until (incl.) 2006-01-23 (15 Weeks).
#> Estimating gg model to predict spending...
#> Starting estimation...
#> Estimation finished!
#>        Id period.first period.last period.length actual.x actual.total.spending
#>   1:    1   2005-10-11  2006-01-23            15        0                  0.00
#>   2:   10   2005-10-11  2006-01-23            15        0                  0.00
#>   3:  100   2005-10-11  2006-01-23            15       10                224.71
#>   4: 1000   2005-10-11  2006-01-23            15       10                343.11
#>   5: 1001   2005-10-11  2006-01-23            15        6                206.65
#>  ---                                                                           
#> 246: 1219   2005-10-11  2006-01-23            15       11                325.05
#> 247:  122   2005-10-11  2006-01-23            15        0                  0.00
#> 248: 1220   2005-10-11  2006-01-23            15        0                  0.00
#> 249: 1221   2005-10-11  2006-01-23            15        7                158.46
#> 250: 1222   2005-10-11  2006-01-23            15        0                  0.00
#>         PAlive        CET       DERT predicted.mean.spending predicted.CLV
#>   1: 0.3571652 0.08876335 0.05854369                39.95483      2.339103
#>   2: 0.4226928 0.37184063 0.24524673                55.23031     13.545053
#>   3: 0.9156048 5.42869219 3.58048291                43.57390    156.015602
#>   4: 0.9967799 5.28084482 3.48297048                41.60921    144.923640
#>   5: 0.5100298 1.41442148 0.93287881                45.58153     42.522040
#>  ---                                                                      
#> 246: 0.9579466 1.44733052 0.95458391                33.58728     32.061875
#> 247: 0.3571652 0.08876335 0.05854369                39.95483      2.339103
#> 248: 0.3571652 0.08876335 0.05854369                39.95483      2.339103
#> 249: 0.9434610 1.72318818 1.13652527                34.28958     38.970974
#> 250: 0.4137006 0.23337194 0.15391999                47.35500      7.288881
# }
# \donttest{
# Estimate correlation as well
pnbd(clv.data.apparel, use.cor = TRUE)
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD Standard Model
#> 
#> Call:
#> pnbd(clv.data = clv.data.apparel, use.cor = TRUE)
#> 
#> Coefficients:
#>               r            alpha                s             beta  
#>        0.790394         5.355977         0.278047         7.116957  
#> Cor(life,trans)  
#>       -0.009087  
#> KKT1: TRUE 
#> KKT2: FALSE 
#> 
#> Used Options:
#> Correlation:     TRUE 
# }
# \donttest{
# To estimate the pnbd model with static covariates,
#   add static covariates to the data
data("apparelStaticCov")
clv.data.static.cov <-
 SetStaticCovariates(clv.data.apparel,
                     data.cov.life = apparelStaticCov,
                     names.cov.life = c("Gender", "Channel"),
                     data.cov.trans = apparelStaticCov,
                     names.cov.trans = c("Gender", "Channel"))

# Fit pnbd with static covariates
pnbd(clv.data.static.cov)
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> pnbd(clv.data = clv.data.static.cov)
#> 
#> Coefficients:
#>             r          alpha              s           beta    life.Gender  
#>        1.4197        35.5729         0.2727         8.4407         1.5067  
#>  life.Channel   trans.Gender  trans.Channel  
#>       -1.7005         1.4210         0.4022  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     FALSE 
#> Regularization:  FALSE 

# Give initial guesses for both covariate parameters
pnbd(clv.data.static.cov, start.params.trans = c(Gender=0.75, Channel=0.7),
                   start.params.life  = c(Gender=0.5, Channel=0.5))
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> pnbd(clv.data = clv.data.static.cov, start.params.life = c(Gender = 0.5, 
#>     Channel = 0.5), start.params.trans = c(Gender = 0.75, Channel = 0.7))
#> 
#> Coefficients:
#>             r          alpha              s           beta    life.Gender  
#>        1.4181        35.5968         0.2730         8.6001         1.5230  
#>  life.Channel   trans.Gender  trans.Channel  
#>       -1.7011         1.4227         0.4023  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     FALSE 
#> Regularization:  FALSE 

# Use regularization
pnbd(clv.data.static.cov, reg.lambdas = c(trans = 5, life=5))
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> pnbd(clv.data = clv.data.static.cov, reg.lambdas = c(trans = 5, 
#>     life = 5))
#> 
#> Coefficients:
#>             r          alpha              s           beta    life.Gender  
#>     0.7927218      5.4471984      0.3583809     11.6113953     -0.0005224  
#>  life.Channel   trans.Gender  trans.Channel  
#>    -0.0024106      0.0105961      0.0087095  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     FALSE 
#> Regularization:  TRUE 

# Force the same coefficient to be used for both covariates
pnbd(clv.data.static.cov, names.cov.constr = "Gender",
                   start.params.constr = c(Gender=0.5))
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> pnbd(clv.data = clv.data.static.cov, names.cov.constr = "Gender", 
#>     start.params.constr = c(Gender = 0.5))
#> 
#> Coefficients:
#>             r          alpha              s           beta   life.Channel  
#>         1.424         35.470          0.274          7.867         -1.690  
#> trans.Channel  constr.Gender  
#>         0.402          1.416  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     TRUE 
#> Regularization:  FALSE 

# Fit model only with the Channel covariate for life but
# keep all trans covariates as is
pnbd(clv.data.static.cov, names.cov.life = c("Channel"))
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> pnbd(clv.data = clv.data.static.cov, names.cov.life = c("Channel"))
#> 
#> Coefficients:
#>             r          alpha              s           beta   life.Channel  
#>        1.4917        32.1539         0.2496         1.7971        -1.6949  
#>  trans.Gender  trans.Channel  
#>        1.2723         0.3937  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     FALSE 
#> Regularization:  FALSE 
# }
# Add dynamic covariates data to the data object
#   add dynamic covariates to the data
# \donttest{
if (FALSE) {
data("apparelDynCov")
clv.data.dyn.cov <-
  SetDynamicCovariates(clv.data = clv.data.apparel,
                       data.cov.life = apparelDynCov,
                       data.cov.trans = apparelDynCov,
                       names.cov.life = c("Marketing", "Gender", "Channel"),
                       names.cov.trans = c("Marketing", "Gender", "Channel"),
                       name.date = "Cov.Date")


# Fit PNBD with dynamic covariates
pnbd(clv.data.dyn.cov)

# The same fitting options as for the
#  static covariate are available
pnbd(clv.data.dyn.cov, reg.lambdas = c(trans=10, life=2))
}
# }