Fits BG/NBD models on transactional data without and with static covariates.
# S4 method for class 'clv.data'
bgnbd(
clv.data,
start.params.model = c(),
optimx.args = list(),
verbose = TRUE,
...
)
# S4 method for class 'clv.data.static.covariates'
bgnbd(
clv.data,
start.params.model = 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(),
...
)
The data object on which the model is fitted.
Named start parameters containing the optimization start parameters for the model without covariates.
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.
Show details about the running of the function.
Ignored
Which of the set Lifetime covariates should be used. Missing parameter indicates all covariates shall be used.
Which of the set Transaction covariates should be used. Missing parameter indicates all covariates shall be used.
Named start parameters containing the optimization start parameters for all lifetime covariates.
Named start parameters containing the optimization start parameters for all transaction covariates.
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.
Named start parameters containing the optimization start parameters for the constraint covariates.
Named lambda parameters used for the L2 regularization of the lifetime and the transaction covariate parameters. Lambdas have to be >= 0.
Depending on the data object on which the model was fit, bgnbd
returns either an object of
class clv.bgnbd or clv.bgnbd.static.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.
Model parameters for the BG/NBD model are r, alpha, a, and b
. r
: shape parameter of the Gamma distribution of the purchase process. alpha
: scale parameter of the Gamma distribution of the purchase process. a
: shape parameter of the Beta distribution of the dropout process.b
: shape parameter of the Beta distribution of the dropout process.
If no start parameters are given, r = 1, alpha = 3, a = 1, b = 3 is used. All model start parameters are required to be > 0. If no start values are given for the covariate parameters, 0.1 is used.
Note that the DERT expression has not been derived (yet) and it consequently is not possible to calculated values for DERT and CLV.
The BG/NBD is an "easy" alternative to the Pareto/NBD model that is easier to implement. The BG/NBD model slight adapts the behavioral "story" associated with the Pareto/NBD model in order to simplify the implementation. The BG/NBD model uses a beta-geometric and exponential gamma mixture distributions to model customer behavior. The key difference to the Pareto/NBD model is that a customer can only churn right after a transaction. This simplifies computations significantly, however has the drawback that a customer cannot churn until he/she makes a transaction. The Pareto/NBD model assumes that a customer can churn at any time.
The standard BG/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).
The likelihood function is the likelihood function associated with the basic model where alpha, a, and b are replaced with alpha = alpha0*exp(-g1z1), a = a_0*exp(g2z2), and b = b0*exp(g3z2) while r remains unchanged. Note that in the current implementation, we constrain the covariate parameters and data for the lifetime process to be equal (g2=g3 and z2=z3).
Fader PS, Hardie BGS, Lee KL (2005). ““Counting Your Customers” the Easy Way: An Alternative to the Pareto/NBD Model” Marketing Science, 24(2), 275-284.
Fader PS, Hardie BGS (2013). “Overcoming the BG/NBD Model's #NUM! Error Problem” URL http://brucehardie.com/notes/027/bgnbd_num_error.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, Lee KL (2007). “Creating a Fit Histogram for the BG/NBD Model” URL https://www.brucehardie.com/notes/014/bgnbd_fit_histogram.pdf
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).
newcustomer
to predict the expected number of transactions for an average new customer.
# \donttest{
data("apparelTrans")
clv.data.apparel <- clvdata(apparelTrans, date.format = "ymd",
time.unit = "w", estimation.split = 52)
# Fit standard bgnbd model
bgnbd(clv.data.apparel)
#> Starting estimation...
#> Estimation finished!
#> BG/NBD Standard Model
#>
#> Call:
#> bgnbd(clv.data = clv.data.apparel)
#>
#> Coefficients:
#> r alpha a b
#> 0.8053 28.1251 33.9420 297.9476
#> KKT1: TRUE
#> KKT2: TRUE
# Give initial guesses for the model parameters
bgnbd(clv.data.apparel,
start.params.model = c(r=0.5, alpha=15, a = 2, b=5))
#> Starting estimation...
#> Estimation finished!
#> BG/NBD Standard Model
#>
#> Call:
#> bgnbd(clv.data = clv.data.apparel, start.params.model = c(r = 0.5,
#> alpha = 15, a = 2, b = 5))
#>
#> Coefficients:
#> r alpha a b
#> 0.8053 28.1250 17.8092 155.9075
#> KKT1: TRUE
#> KKT2: TRUE
# pass additional parameters to the optimizer (optimx)
# Use Nelder-Mead as optimization method and print
# detailed information about the optimization process
apparel.bgnbd <- bgnbd(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"
#> Function has 4 arguments
#> Analytic gradient not made available.
#> Analytic Hessian not made available.
#> Scale check -- log parameter ratio= 0 log bounds ratio= NA
#> 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] TRUE
#>
#> $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: 0x11dce02d8>
#> <environment: 0x1295115a0>
#>
#> $have.bounds
#> [1] FALSE
#>
#> $method
#> [1] "Nelder-Mead"
#>
#> Method: Nelder-Mead
#> Nelder-Mead direct search function minimizer
#> function value for initial parameters = 4151.799882
#> Scaled convergence tolerance is 6.18666e-05
#> Stepsize computed as 0.109861
#> BUILD 5 4280.255070 4100.393179
#> EXTENSION 7 4153.744504 3915.863835
#> LO-REDUCTION 9 4151.799882 3915.863835
#> LO-REDUCTION 11 4149.964916 3915.863835
#> EXTENSION 13 4100.393179 3743.714488
#> EXTENSION 15 3999.765299 3643.905892
#> LO-REDUCTION 17 3934.809847 3643.905892
#> EXTENSION 19 3915.863835 3545.539279
#> REFLECTION 21 3743.714488 3533.732535
#> LO-REDUCTION 23 3651.998327 3533.732535
#> LO-REDUCTION 25 3643.905892 3533.732535
#> LO-REDUCTION 27 3546.207593 3533.732535
#> HI-REDUCTION 29 3545.539279 3533.732535
#> HI-REDUCTION 31 3543.179053 3533.732535
#> REFLECTION 33 3539.305199 3532.507588
#> EXTENSION 35 3538.374535 3530.696459
#> EXTENSION 37 3538.091523 3519.769546
#> LO-REDUCTION 39 3533.732535 3519.769546
#> LO-REDUCTION 41 3532.507588 3519.769546
#> EXTENSION 43 3530.696459 3510.869170
#> EXTENSION 45 3528.960114 3500.645882
#> EXTENSION 47 3521.674508 3497.483952
#> REFLECTION 49 3519.769546 3496.981145
#> REFLECTION 51 3510.869170 3487.401037
#> HI-REDUCTION 53 3500.645882 3487.401037
#> LO-REDUCTION 55 3498.387294 3487.401037
#> HI-REDUCTION 57 3497.483952 3487.401037
#> LO-REDUCTION 59 3496.981145 3487.401037
#> EXTENSION 61 3493.779517 3483.484534
#> LO-REDUCTION 63 3492.391145 3483.484534
#> REFLECTION 65 3487.562394 3482.506270
#> LO-REDUCTION 67 3487.401037 3482.506270
#> LO-REDUCTION 69 3485.059649 3482.406091
#> LO-REDUCTION 71 3483.484534 3482.406091
#> LO-REDUCTION 73 3483.119256 3482.311166
#> LO-REDUCTION 75 3482.548478 3482.295479
#> HI-REDUCTION 77 3482.506270 3482.295479
#> HI-REDUCTION 79 3482.406091 3482.295479
#> REFLECTION 81 3482.332045 3482.239338
#> EXTENSION 83 3482.311166 3482.118275
#> HI-REDUCTION 85 3482.308885 3482.118275
#> LO-REDUCTION 87 3482.295479 3482.118275
#> LO-REDUCTION 89 3482.239338 3482.118275
#> LO-REDUCTION 91 3482.199259 3482.118275
#> REFLECTION 93 3482.172675 3482.105284
#> HI-REDUCTION 95 3482.142830 3482.105284
#> LO-REDUCTION 97 3482.129588 3482.102046
#> REFLECTION 99 3482.118275 3482.092313
#> HI-REDUCTION 101 3482.117122 3482.092313
#> HI-REDUCTION 103 3482.105284 3482.092313
#> LO-REDUCTION 105 3482.102046 3482.092313
#> EXTENSION 107 3482.099316 3482.081815
#> LO-REDUCTION 109 3482.098622 3482.081815
#> REFLECTION 111 3482.095412 3482.081388
#> LO-REDUCTION 113 3482.092313 3482.081388
#> LO-REDUCTION 115 3482.089506 3482.081242
#> EXTENSION 117 3482.084208 3482.063702
#> LO-REDUCTION 119 3482.081815 3482.063702
#> LO-REDUCTION 121 3482.081388 3482.063702
#> EXTENSION 123 3482.081242 3482.056140
#> EXTENSION 125 3482.070868 3482.034983
#> LO-REDUCTION 127 3482.070791 3482.034983
#> EXTENSION 129 3482.063702 3482.004107
#> EXTENSION 131 3482.056140 3481.985483
#> EXTENSION 133 3482.042600 3481.970263
#> EXTENSION 135 3482.034983 3481.929101
#> EXTENSION 137 3482.004107 3481.899058
#> LO-REDUCTION 139 3481.985483 3481.899058
#> REFLECTION 141 3481.970263 3481.884194
#> LO-REDUCTION 143 3481.929101 3481.884194
#> LO-REDUCTION 145 3481.916239 3481.884194
#> LO-REDUCTION 147 3481.911364 3481.884194
#> REFLECTION 149 3481.899058 3481.873543
#> LO-REDUCTION 151 3481.894943 3481.873543
#> EXTENSION 153 3481.887940 3481.860026
#> HI-REDUCTION 155 3481.884280 3481.860026
#> LO-REDUCTION 157 3481.884194 3481.860026
#> EXTENSION 159 3481.875645 3481.834342
#> LO-REDUCTION 161 3481.873543 3481.834342
#> EXTENSION 163 3481.861245 3481.808343
#> LO-REDUCTION 165 3481.860026 3481.808343
#> EXTENSION 167 3481.844796 3481.771985
#> EXTENSION 169 3481.834342 3481.710388
#> LO-REDUCTION 171 3481.811157 3481.710388
#> EXTENSION 173 3481.808343 3481.659444
#> LO-REDUCTION 175 3481.771985 3481.659444
#> EXTENSION 177 3481.738120 3481.546219
#> LO-REDUCTION 179 3481.710388 3481.546219
#> LO-REDUCTION 181 3481.673018 3481.546219
#> EXTENSION 183 3481.659444 3481.442660
#> EXTENSION 185 3481.580223 3481.332356
#> LO-REDUCTION 187 3481.560677 3481.332356
#> LO-REDUCTION 189 3481.546219 3481.332356
#> EXTENSION 191 3481.442660 3481.149769
#> LO-REDUCTION 193 3481.363321 3481.149769
#> EXTENSION 195 3481.336982 3481.070098
#> LO-REDUCTION 197 3481.332356 3481.070098
#> REFLECTION 199 3481.178984 3481.010361
#> REFLECTION 201 3481.149769 3480.994551
#> LO-REDUCTION 203 3481.122596 3480.994551
#> EXTENSION 205 3481.070098 3480.878659
#> LO-REDUCTION 207 3481.016512 3480.878659
#> LO-REDUCTION 209 3481.010361 3480.878659
#> LO-REDUCTION 211 3480.994551 3480.878659
#> EXTENSION 213 3480.936156 3480.837135
#> LO-REDUCTION 215 3480.906129 3480.837135
#> EXTENSION 217 3480.899800 3480.762303
#> LO-REDUCTION 219 3480.878659 3480.762303
#> LO-REDUCTION 221 3480.839151 3480.762303
#> LO-REDUCTION 223 3480.837135 3480.762303
#> EXTENSION 225 3480.820055 3480.724384
#> EXTENSION 227 3480.819875 3480.682886
#> LO-REDUCTION 229 3480.800900 3480.682886
#> EXTENSION 231 3480.762303 3480.571699
#> LO-REDUCTION 233 3480.724384 3480.571699
#> EXTENSION 235 3480.697648 3480.512261
#> LO-REDUCTION 237 3480.682886 3480.512261
#> REFLECTION 239 3480.578663 3480.484309
#> LO-REDUCTION 241 3480.571699 3480.484309
#> LO-REDUCTION 243 3480.519896 3480.484309
#> HI-REDUCTION 245 3480.512261 3480.484309
#> LO-REDUCTION 247 3480.506665 3480.484309
#> REFLECTION 249 3480.496582 3480.473331
#> LO-REDUCTION 251 3480.490801 3480.473331
#> LO-REDUCTION 253 3480.487491 3480.473331
#> LO-REDUCTION 255 3480.484309 3480.473331
#> LO-REDUCTION 257 3480.484017 3480.473331
#> REFLECTION 259 3480.478597 3480.471558
#> EXTENSION 261 3480.476817 3480.468428
#> LO-REDUCTION 263 3480.476590 3480.468428
#> LO-REDUCTION 265 3480.473331 3480.468428
#> LO-REDUCTION 267 3480.472230 3480.468428
#> REFLECTION 269 3480.471558 3480.467359
#> LO-REDUCTION 271 3480.469478 3480.467359
#> EXTENSION 273 3480.468893 3480.465987
#> EXTENSION 275 3480.468428 3480.462986
#> LO-REDUCTION 277 3480.467832 3480.462986
#> LO-REDUCTION 279 3480.467359 3480.462986
#> LO-REDUCTION 281 3480.465987 3480.462986
#> EXTENSION 283 3480.464129 3480.459635
#> LO-REDUCTION 285 3480.464061 3480.459635
#> EXTENSION 287 3480.463354 3480.458583
#> EXTENSION 289 3480.462986 3480.455487
#> EXTENSION 291 3480.460281 3480.450407
#> LO-REDUCTION 293 3480.459635 3480.450407
#> LO-REDUCTION 295 3480.458583 3480.450407
#> LO-REDUCTION 297 3480.455487 3480.450407
#> EXTENSION 299 3480.452277 3480.448651
#> EXTENSION 301 3480.452089 3480.445790
#> LO-REDUCTION 303 3480.451616 3480.445790
#> EXTENSION 305 3480.450407 3480.445291
#> LO-REDUCTION 307 3480.448651 3480.445291
#> EXTENSION 309 3480.448212 3480.442242
#> EXTENSION 311 3480.446452 3480.441184
#> EXTENSION 313 3480.445790 3480.439890
#> LO-REDUCTION 315 3480.445291 3480.439890
#> REFLECTION 317 3480.442242 3480.438633
#> LO-REDUCTION 319 3480.441486 3480.438633
#> REFLECTION 321 3480.441184 3480.437912
#> HI-REDUCTION 323 3480.440012 3480.437912
#> LO-REDUCTION 325 3480.439890 3480.437912
#> EXTENSION 327 3480.439170 3480.436583
#> LO-REDUCTION 329 3480.438633 3480.436583
#> LO-REDUCTION 331 3480.438345 3480.436583
#> REFLECTION 333 3480.437912 3480.436268
#> EXTENSION 335 3480.437323 3480.435759
#> LO-REDUCTION 337 3480.436626 3480.435759
#> LO-REDUCTION 339 3480.436583 3480.435759
#> LO-REDUCTION 341 3480.436289 3480.435759
#> EXTENSION 343 3480.436268 3480.435378
#> LO-REDUCTION 345 3480.436044 3480.435378
#> EXTENSION 347 3480.435836 3480.435224
#> LO-REDUCTION 349 3480.435759 3480.435224
#> REFLECTION 351 3480.435696 3480.435101
#> LO-REDUCTION 353 3480.435378 3480.435101
#> HI-REDUCTION 355 3480.435277 3480.435101
#> LO-REDUCTION 357 3480.435224 3480.435101
#> HI-REDUCTION 359 3480.435185 3480.435101
#> HI-REDUCTION 361 3480.435171 3480.435101
#> Exiting from Nelder Mead minimizer
#> 363 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.a log.b
#> -0.2161996 3.3372999 4.2457936 6.4203498
#>
#> $value
#> [1] 3480.435
#>
#> $message
#> NULL
#>
#> $convcode
#> [1] 0
#>
#> $fevals
#> function
#> 363
#>
#> $gevals
#> gradient
#> NA
#>
#> $nitns
#> [1] NA
#>
#> $kkt1
#> [1] TRUE
#>
#> $kkt2
#> [1] FALSE
#>
#> $xtimes
#> user.self
#> 0.045
#>
#> Assemble the answers
#> Estimation finished!
# estimated coefs
coef(apparel.bgnbd)
#> r alpha a b
#> 0.8055745 28.1430359 69.8111419 614.2179147
# summary of the fitted model
summary(apparel.bgnbd)
#> BG/NBD Standard Model
#>
#> Call:
#> bgnbd(clv.data = clv.data.apparel, optimx.args = list(method = "Nelder-Mead",
#> control = list(trace = 6)))
#>
#> Fitting period:
#> Estimation start 2005-01-02
#> Estimation end 2006-01-01
#> Estimation length 52.0000 Weeks
#>
#> Coefficients:
#> Estimate Std. Error z-val Pr(>|z|)
#> r 8.056e-01 2.808e+00 0.287 0.774
#> alpha 2.814e+01 2.808e+00 10.022 <2e-16 ***
#> a 6.981e+01 3.162e+03 0.022 0.982
#> b 6.142e+02 2.790e+04 0.022 0.982
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Optimization info:
#> LL -3480.4351
#> AIC 6968.8702
#> BIC 6986.4579
#> KKT 1 TRUE
#> KKT 2 FALSE
#> fevals 363.0000
#> Method Nelder-Mead
# predict CLV etc for holdout period
predict(apparel.bgnbd)
#> 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 predicted.mean.spending predicted.total.spending
#> <num> <num> <num>
#> 1: 524.10 63.77959 214.72904
#> 2: 63.31 38.10316 121.52449
#> 3: 333.35 37.12434 74.71381
#> 4: 0.00 33.08404 109.75045
#> 5: 0.00 37.12434 74.71381
#> ---
#> 596: 113.80 28.29614 96.76034
#> 597: 253.61 37.12434 74.71381
#> 598: 0.00 37.12434 74.71381
#> 599: 0.00 34.87739 121.18754
#> 600: 13.99 16.11315 73.87009
#> CET PAlive
#> <num> <num>
#> 1: 3.366736 0.8522351
#> 2: 3.189355 0.8073340
#> 3: 2.012529 1.0000000
#> 4: 3.317323 0.8397270
#> 5: 2.012529 1.0000000
#> ---
#> 596: 3.419559 0.8656065
#> 597: 2.012529 1.0000000
#> 598: 2.012529 1.0000000
#> 599: 3.474674 0.8795578
#> 600: 4.584461 0.8467480
# predict CLV etc for the next 15 periods
predict(apparel.bgnbd, prediction.end = 15)
#> Predicting from 2006-01-02 until (incl.) 2006-04-16 (15 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-04-16 15 2
#> 2: 10 2006-01-02 2006-04-16 15 0
#> 3: 100 2006-01-02 2006-04-16 15 0
#> 4: 101 2006-01-02 2006-04-16 15 0
#> 5: 102 2006-01-02 2006-04-16 15 0
#> ---
#> 596: 95 2006-01-02 2006-04-16 15 0
#> 597: 96 2006-01-02 2006-04-16 15 0
#> 598: 97 2006-01-02 2006-04-16 15 0
#> 599: 98 2006-01-02 2006-04-16 15 0
#> 600: 99 2006-01-02 2006-04-16 15 0
#> actual.total.spending predicted.mean.spending predicted.total.spending
#> <num> <num> <num>
#> 1: 217.5 63.77959 17.889131
#> 2: 0.0 38.10316 10.124236
#> 3: 0.0 37.12434 5.502632
#> 4: 0.0 33.08404 9.143338
#> 5: 0.0 37.12434 5.502632
#> ---
#> 596: 0.0 28.29614 8.061128
#> 597: 0.0 37.12434 5.502632
#> 598: 0.0 37.12434 5.502632
#> 599: 0.0 34.87739 10.096165
#> 600: 0.0 16.11315 6.912589
#> CET PAlive
#> <num> <num>
#> 1: 0.2804836 0.8522351
#> 2: 0.2657060 0.8073340
#> 3: 0.1482217 1.0000000
#> 4: 0.2763670 0.8397270
#> 5: 0.1482217 1.0000000
#> ---
#> 596: 0.2848844 0.8656065
#> 597: 0.1482217 1.0000000
#> 598: 0.1482217 1.0000000
#> 599: 0.2894759 0.8795578
#> 600: 0.4290031 0.8467480
# }
# \donttest{
# To estimate the bgnbd 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 bgnbd with static covariates
bgnbd(clv.data.static.cov)
#> Starting estimation...
#> Estimation finished!
#> BG/NBD with Static Covariates Model
#>
#> Call:
#> bgnbd(clv.data = clv.data.static.cov)
#>
#> Coefficients:
#> r alpha a b life.Gender
#> 0.9457 57.4808 24.6330 211.4040 9.8270
#> life.Channel trans.Gender trans.Channel
#> -4.4347 0.5427 0.5743
#> KKT1: TRUE
#> KKT2: FALSE
#> Constraints: FALSE
#> Regularization: FALSE
# Give initial guesses for both covariate parameters
bgnbd(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!
#> BG/NBD with Static Covariates Model
#>
#> Call:
#> bgnbd(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 a b life.Gender
#> 0.9421 57.2548 11.8422 109.9750 5.0240
#> life.Channel trans.Gender trans.Channel
#> 1.4778 0.5314 0.5849
#> KKT1: TRUE
#> KKT2: FALSE
#> Constraints: FALSE
#> Regularization: FALSE
# Use regularization
bgnbd(clv.data.static.cov, reg.lambdas = c(trans = 5, life=5))
#> Starting estimation...
#> Estimation finished!
#> BG/NBD with Static Covariates Model
#>
#> Call:
#> bgnbd(clv.data = clv.data.static.cov, reg.lambdas = c(trans = 5,
#> life = 5))
#>
#> Coefficients:
#> r alpha a b life.Gender
#> 8.143e-01 2.852e+01 9.055e-01 6.886e+00 1.104e-03
#> life.Channel trans.Gender trans.Channel
#> 3.655e-04 5.582e-03 6.673e-03
#> KKT1: FALSE
#> KKT2: TRUE
#> Constraints: FALSE
#> Regularization: TRUE
# Force the same coefficient to be used for both covariates
bgnbd(clv.data.static.cov, names.cov.constr = "Gender",
start.params.constr = c(Gender=0.5))
#> Starting estimation...
#> Estimation finished!
#> BG/NBD with Static Covariates Model
#>
#> Call:
#> bgnbd(clv.data = clv.data.static.cov, names.cov.constr = "Gender",
#> start.params.constr = c(Gender = 0.5))
#>
#> Coefficients:
#> r alpha a b life.Channel
#> 0.9413 57.2692 7.9569 73.4228 0.7795
#> trans.Channel constr.Gender
#> 0.5861 0.5331
#> KKT1: TRUE
#> KKT2: FALSE
#> Constraints: TRUE
#> Regularization: FALSE
# Fit model only with the Channel covariate for life but
# keep all trans covariates as is
bgnbd(clv.data.static.cov, names.cov.life = c("Channel"))
#> Starting estimation...
#> Estimation finished!
#> BG/NBD with Static Covariates Model
#>
#> Call:
#> bgnbd(clv.data = clv.data.static.cov, names.cov.life = c("Channel"))
#>
#> Coefficients:
#> r alpha a b life.Channel
#> 0.9430 57.2833 15.2632 141.7392 2.5725
#> trans.Gender trans.Channel
#> 0.5312 0.5837
#> KKT1: TRUE
#> KKT2: TRUE
#> Constraints: FALSE
#> Regularization: FALSE
# }