Fits Gamma-Gompertz/NBD models on transactional data with static and without covariates.
# S4 method for class 'clv.data'
ggomnbd(
clv.data,
start.params.model = c(),
optimx.args = list(),
verbose = TRUE,
...
)
# S4 method for class 'clv.data.static.covariates'
ggomnbd(
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, ggomnbd
returns either an object of
class clv.ggomnbd or clv.ggomnbd.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 GGompertz/NBD model are r, alpha, beta, b and s
. r
: shape parameter of the Gamma distribution of the purchase process.
The smaller r
, the stronger the heterogeneity of the purchase process.alpha
: scale parameter of the Gamma distribution of the purchase process.beta
: scale parameter for the Gamma distribution for the lifetime process.b
: scale parameter of the Gompertz distribution (constant across customers).s
: shape parameter of the Gamma distribution for the lifetime process.
The smaller s
, the stronger the heterogeneity of customer lifetimes.
If no start parameters are given, r=0.5, alpha=2, b=0.1, s=1, beta=0.1 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.
There are two key differences of the gamma/Gompertz/NBD (GGompertz/NBD) model compared to the relative to the well-known Pareto/NBD model: (i) its probability density function can exhibit a mode at zero or an interior mode, and (ii) it can be skewed to the right or to the left. Therefore, the GGompertz/NBD model is more flexible than the Pareto/NBD model. According to Bemmaor and Glady (2012) can indicate substantial differences in expected residual lifetimes compared to the Pareto/NBD. The GGompertz/NBD tends to be appropriate when firms are reputed and their offerings are differentiated.
Bemmaor AC, Glady N (2012). “Modeling Purchasing Behavior with Sudden “Death”: A Flexible Customer Lifetime Model” Management Science, 58(5), 1012-1021.
Adler J (2022). “Comment on “Modeling Purchasing Behavior with Sudden “Death”: A Flexible Customer Lifetime Model” Management Science 69(3):1929-1930.
The expression for the PMF was derived by Adler J (2024). (unpublished)
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 ggomnbd model
ggomnbd(clv.data.apparel)
#> Starting estimation...
#> Estimation finished!
#> GGompertz/NBD Standard Model
#>
#> Call:
#> ggomnbd(clv.data = clv.data.apparel)
#>
#> Coefficients:
#> r alpha b s beta
#> 1.308e+00 4.633e+01 5.250e-06 4.811e-01 3.706e-04
#> KKT1: TRUE
#> KKT2: FALSE
# Give initial guesses for the model parameters
ggomnbd(clv.data.apparel,
start.params.model = c(r=0.5, alpha=15, b=5, beta=10, s=0.5))
#> Starting estimation...
#> Estimation finished!
#> Warning: Estimation failed with NA coefficients. The returned object contains results but further usage is restricted. You might want to try to fit the model again with method Nelder-Mead (using optimx.args=list(method="Nelder-Mead")) or try different starting values. See examples.
#> Warning: Hessian could not be derived. Setting all entries to NA.
#> GGompertz/NBD Standard Model
#>
#> Call:
#> ggomnbd(clv.data = clv.data.apparel, start.params.model = c(r = 0.5,
#> alpha = 15, b = 5, beta = 10, s = 0.5))
#>
#> Coefficients:
#> r alpha b s beta
#> NA NA NA NA NA
#> KKT1: NA
#> KKT2: NA
# pass additional parameters to the optimizer (optimx)
# Use Nelder-Mead as optimization method and print
# detailed information about the optimization process
apparel.ggomnbd <- ggomnbd(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] 5
#>
#> $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: 0x11dce02d8>
#> <environment: 0x13ace59d8>
#>
#> $have.bounds
#> [1] FALSE
#>
#> $method
#> [1] "Nelder-Mead"
#>
#> Method: Nelder-Mead
#> Nelder-Mead direct search function minimizer
#> function value for initial parameters = 5007.682901
#> Scaled convergence tolerance is 7.46203e-05
#> Stepsize computed as 0.230259
#> BUILD 6 5442.156737 4940.535538
#> EXTENSION 8 5274.518932 4478.460845
#> LO-REDUCTION 10 5042.844993 4478.460845
#> LO-REDUCTION 12 5007.682901 4478.460845
#> EXTENSION 14 4975.291614 4204.231102
#> LO-REDUCTION 16 4940.535538 4204.231102
#> EXTENSION 18 4560.511729 3846.998230
#> LO-REDUCTION 20 4544.492656 3846.998230
#> LO-REDUCTION 22 4478.460845 3846.998230
#> EXTENSION 24 4224.209660 3655.491805
#> LO-REDUCTION 26 4204.231102 3655.491805
#> LO-REDUCTION 28 3966.230645 3655.491805
#> LO-REDUCTION 30 3907.444304 3655.491805
#> EXTENSION 32 3846.998230 3514.922022
#> LO-REDUCTION 34 3688.613512 3514.922022
#> LO-REDUCTION 36 3672.786917 3514.922022
#> REFLECTION 38 3669.920469 3510.550033
#> REFLECTION 40 3655.491805 3498.571310
#> LO-REDUCTION 42 3543.401435 3497.105491
#> LO-REDUCTION 44 3542.285254 3497.105491
#> LO-REDUCTION 46 3514.922022 3497.105491
#> LO-REDUCTION 48 3510.550033 3497.105491
#> HI-REDUCTION 50 3506.803363 3497.105491
#> REFLECTION 52 3502.798591 3494.496828
#> LO-REDUCTION 54 3502.181541 3494.496828
#> LO-REDUCTION 56 3498.571310 3494.496828
#> REFLECTION 58 3497.313598 3493.565337
#> EXTENSION 60 3497.105491 3489.279358
#> EXTENSION 62 3495.039577 3487.467587
#> LO-REDUCTION 64 3494.621786 3487.467587
#> LO-REDUCTION 66 3494.496828 3487.467587
#> EXTENSION 68 3493.565337 3486.220414
#> LO-REDUCTION 70 3490.573813 3486.217731
#> LO-REDUCTION 72 3489.279358 3486.217731
#> LO-REDUCTION 74 3487.974737 3486.136583
#> LO-REDUCTION 76 3487.467587 3486.136583
#> HI-REDUCTION 78 3486.962485 3486.136583
#> LO-REDUCTION 80 3486.301259 3486.136583
#> HI-REDUCTION 82 3486.220414 3486.065167
#> HI-REDUCTION 84 3486.217731 3486.065167
#> HI-REDUCTION 86 3486.207573 3486.065167
#> REFLECTION 88 3486.184057 3485.992249
#> HI-REDUCTION 90 3486.136583 3485.992249
#> LO-REDUCTION 92 3486.081667 3485.992249
#> HI-REDUCTION 94 3486.072748 3485.992249
#> REFLECTION 96 3486.065167 3485.986712
#> REFLECTION 98 3486.048959 3485.965877
#> EXTENSION 100 3486.024422 3485.917933
#> EXTENSION 102 3486.019173 3485.840122
#> EXTENSION 104 3485.992249 3485.775640
#> EXTENSION 106 3485.986712 3485.667857
#> EXTENSION 108 3485.965877 3485.434055
#> LO-REDUCTION 110 3485.917933 3485.434055
#> EXTENSION 112 3485.840122 3484.693242
#> LO-REDUCTION 114 3485.775640 3484.693242
#> EXTENSION 116 3485.667857 3484.002742
#> LO-REDUCTION 118 3485.483175 3484.002742
#> EXTENSION 120 3485.434055 3483.471043
#> LO-REDUCTION 122 3484.959840 3483.471043
#> REFLECTION 124 3484.693242 3483.356447
#> LO-REDUCTION 126 3484.553868 3483.356447
#> LO-REDUCTION 128 3484.002742 3483.356447
#> HI-REDUCTION 130 3483.811724 3483.356447
#> REFLECTION 132 3483.676112 3483.295254
#> REFLECTION 134 3483.653586 3483.273009
#> LO-REDUCTION 136 3483.471043 3483.273009
#> REFLECTION 138 3483.419501 3483.194748
#> REFLECTION 140 3483.356447 3483.164309
#> REFLECTION 142 3483.319503 3483.129896
#> LO-REDUCTION 144 3483.295254 3483.129896
#> LO-REDUCTION 146 3483.273009 3483.129896
#> LO-REDUCTION 148 3483.194748 3483.129896
#> REFLECTION 150 3483.164309 3483.112342
#> REFLECTION 152 3483.155804 3483.093604
#> REFLECTION 154 3483.142984 3483.084739
#> LO-REDUCTION 156 3483.140003 3483.084739
#> LO-REDUCTION 158 3483.129896 3483.082021
#> LO-REDUCTION 160 3483.112342 3483.081444
#> HI-REDUCTION 162 3483.094962 3483.081444
#> LO-REDUCTION 164 3483.093604 3483.079062
#> EXTENSION 166 3483.087381 3483.046706
#> LO-REDUCTION 168 3483.084739 3483.046706
#> LO-REDUCTION 170 3483.082021 3483.046706
#> LO-REDUCTION 172 3483.081444 3483.046706
#> LO-REDUCTION 174 3483.079062 3483.046706
#> EXTENSION 176 3483.070740 3483.027238
#> LO-REDUCTION 178 3483.061490 3483.027238
#> LO-REDUCTION 180 3483.059875 3483.027238
#> EXTENSION 182 3483.057996 3483.003021
#> LO-REDUCTION 184 3483.047079 3483.003021
#> EXTENSION 186 3483.046706 3482.977434
#> LO-REDUCTION 188 3483.028818 3482.977434
#> EXTENSION 190 3483.027238 3482.957825
#> EXTENSION 192 3483.018135 3482.916903
#> LO-REDUCTION 194 3483.003021 3482.916903
#> REFLECTION 196 3482.977758 3482.906631
#> EXTENSION 198 3482.977434 3482.882348
#> LO-REDUCTION 200 3482.957825 3482.882348
#> LO-REDUCTION 202 3482.929074 3482.882348
#> LO-REDUCTION 204 3482.916903 3482.882348
#> LO-REDUCTION 206 3482.906631 3482.882348
#> HI-REDUCTION 208 3482.905887 3482.882348
#> EXTENSION 210 3482.894189 3482.871572
#> LO-REDUCTION 212 3482.893320 3482.871572
#> HI-REDUCTION 214 3482.893276 3482.871572
#> EXTENSION 216 3482.888397 3482.857974
#> LO-REDUCTION 218 3482.883513 3482.857974
#> LO-REDUCTION 220 3482.882348 3482.857974
#> EXTENSION 222 3482.881510 3482.848978
#> EXTENSION 224 3482.871572 3482.833107
#> EXTENSION 226 3482.868137 3482.817666
#> LO-REDUCTION 228 3482.867681 3482.817666
#> EXTENSION 230 3482.857974 3482.807759
#> LO-REDUCTION 232 3482.848978 3482.807759
#> HI-REDUCTION 234 3482.833107 3482.807759
#> EXTENSION 236 3482.832063 3482.794215
#> EXTENSION 238 3482.826967 3482.785922
#> HI-REDUCTION 240 3482.818498 3482.785922
#> LO-REDUCTION 242 3482.817666 3482.785922
#> LO-REDUCTION 244 3482.807759 3482.785922
#> EXTENSION 246 3482.806784 3482.761353
#> LO-REDUCTION 248 3482.794215 3482.761353
#> LO-REDUCTION 250 3482.790644 3482.761353
#> LO-REDUCTION 252 3482.788720 3482.761353
#> EXTENSION 254 3482.785922 3482.755701
#> EXTENSION 256 3482.780827 3482.740430
#> LO-REDUCTION 258 3482.771469 3482.740430
#> REFLECTION 260 3482.768076 3482.737903
#> LO-REDUCTION 262 3482.761353 3482.737903
#> LO-REDUCTION 264 3482.755701 3482.737903
#> LO-REDUCTION 266 3482.748851 3482.737903
#> LO-REDUCTION 268 3482.747416 3482.737903
#> REFLECTION 270 3482.743241 3482.735445
#> LO-REDUCTION 272 3482.740598 3482.735445
#> LO-REDUCTION 274 3482.740430 3482.735445
#> EXTENSION 276 3482.739764 3482.732195
#> EXTENSION 278 3482.738342 3482.728411
#> LO-REDUCTION 280 3482.737903 3482.728411
#> EXTENSION 282 3482.736837 3482.727144
#> EXTENSION 284 3482.735445 3482.714835
#> EXTENSION 286 3482.732195 3482.701571
#> LO-REDUCTION 288 3482.729380 3482.701571
#> LO-REDUCTION 290 3482.728411 3482.701571
#> EXTENSION 292 3482.727144 3482.693941
#> EXTENSION 294 3482.716837 3482.663532
#> LO-REDUCTION 296 3482.714835 3482.663532
#> EXTENSION 298 3482.709825 3482.628475
#> LO-REDUCTION 300 3482.701571 3482.628475
#> LO-REDUCTION 302 3482.693941 3482.628475
#> EXTENSION 304 3482.674222 3482.569643
#> LO-REDUCTION 306 3482.663532 3482.569643
#> EXTENSION 308 3482.637750 3482.507080
#> LO-REDUCTION 310 3482.636899 3482.507080
#> EXTENSION 312 3482.628475 3482.440233
#> EXTENSION 314 3482.572557 3482.391042
#> EXTENSION 316 3482.569643 3482.343151
#> EXTENSION 318 3482.521875 3482.216396
#> LO-REDUCTION 320 3482.507080 3482.216396
#> LO-REDUCTION 322 3482.440233 3482.216396
#> LO-REDUCTION 324 3482.391042 3482.216396
#> EXTENSION 326 3482.343151 3482.159796
#> REFLECTION 328 3482.304538 3482.113614
#> REFLECTION 330 3482.279491 3482.111540
#> LO-REDUCTION 332 3482.252750 3482.111540
#> REFLECTION 334 3482.216396 3482.080384
#> HI-REDUCTION 336 3482.159796 3482.080384
#> LO-REDUCTION 338 3482.146908 3482.080384
#> EXTENSION 340 3482.130251 3482.036502
#> LO-REDUCTION 342 3482.113614 3482.036502
#> LO-REDUCTION 344 3482.111540 3482.036502
#> EXTENSION 346 3482.107501 3482.006635
#> LO-REDUCTION 348 3482.080384 3482.006635
#> REFLECTION 350 3482.073242 3482.003591
#> REFLECTION 352 3482.065516 3481.989694
#> LO-REDUCTION 354 3482.036502 3481.989694
#> LO-REDUCTION 356 3482.023909 3481.989694
#> LO-REDUCTION 358 3482.006635 3481.989694
#> HI-REDUCTION 360 3482.003591 3481.989694
#> REFLECTION 362 3481.996197 3481.989261
#> HI-REDUCTION 364 3481.994979 3481.989261
#> LO-REDUCTION 366 3481.994685 3481.988358
#> HI-REDUCTION 368 3481.990599 3481.988358
#> LO-REDUCTION 370 3481.990454 3481.988177
#> LO-REDUCTION 372 3481.989694 3481.988177
#> HI-REDUCTION 374 3481.989647 3481.988100
#> HI-REDUCTION 376 3481.989261 3481.988100
#> HI-REDUCTION 378 3481.988358 3481.988100
#> HI-REDUCTION 380 3481.988297 3481.987946
#> LO-REDUCTION 382 3481.988185 3481.987837
#> HI-REDUCTION 384 3481.988177 3481.987837
#> LO-REDUCTION 386 3481.988117 3481.987837
#> HI-REDUCTION 388 3481.988100 3481.987837
#> HI-REDUCTION 390 3481.987946 3481.987825
#> REFLECTION 392 3481.987862 3481.987761
#> LO-REDUCTION 394 3481.987850 3481.987752
#> REFLECTION 396 3481.987847 3481.987744
#> HI-REDUCTION 398 3481.987837 3481.987744
#> LO-REDUCTION 400 3481.987825 3481.987744
#> Exiting from Nelder Mead minimizer
#> 402 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.b log.s log.beta
#> 0.2642132 3.8328455 -5.8976873 -0.8657877 -1.7463581
#>
#> $value
#> [1] 3481.988
#>
#> $message
#> NULL
#>
#> $convcode
#> [1] 0
#>
#> $fevals
#> function
#> 402
#>
#> $gevals
#> gradient
#> NA
#>
#> $nitns
#> [1] NA
#>
#> $kkt1
#> [1] TRUE
#>
#> $kkt2
#> [1] TRUE
#>
#> $xtimes
#> user.self
#> 0.147
#>
#> Assemble the answers
#> Estimation finished!
# estimated coefs
coef(apparel.ggomnbd)
#> r alpha b s beta
#> 1.302405809 46.193794125 0.002745788 0.420720023 0.174407964
# summary of the fitted model
summary(apparel.ggomnbd)
#> GGompertz/NBD Standard Model
#>
#> Call:
#> ggomnbd(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 1.302406 0.229943 5.664 1.48e-08 ***
#> alpha 46.193794 7.513529 6.148 7.84e-10 ***
#> b 0.002746 0.028817 0.095 0.924
#> s 0.420720 1.184962 0.355 0.723
#> beta 0.174408 1.572658 0.111 0.912
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Optimization info:
#> LL -3481.9877
#> AIC 6973.9755
#> BIC 6995.9601
#> KKT 1 TRUE
#> KKT 2 TRUE
#> fevals 402.0000
#> Method Nelder-Mead
# predict CLV etc for holdout period
predict(apparel.ggomnbd)
#> 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 249.79933
#> 2: 63.31 38.10316 136.91419
#> 3: 333.35 37.12434 59.28538
#> 4: 0.00 33.08404 126.47710
#> 5: 0.00 37.12434 59.28538
#> ---
#> 596: 113.80 28.29614 113.74903
#> 597: 253.61 37.12434 59.28538
#> 598: 0.00 37.12434 59.28538
#> 599: 0.00 34.87739 144.08847
#> 600: 13.99 16.11315 92.74449
#> CET PAlive
#> <num> <num>
#> 1: 3.916603 0.9143792
#> 2: 3.593251 0.8388887
#> 3: 1.596941 0.6590848
#> 4: 3.822904 0.8925040
#> 5: 1.596941 0.6590848
#> ---
#> 596: 4.019948 0.9385066
#> 597: 1.596941 0.6590848
#> 598: 1.596941 0.6590848
#> 599: 4.131286 0.9644998
#> 600: 5.755828 0.9368629
# predict CLV etc for the next 15 periods
predict(apparel.ggomnbd, 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 19.918293
#> 2: 0.0 38.10316 10.917150
#> 3: 0.0 37.12434 4.727249
#> 4: 0.0 33.08404 10.084926
#> 5: 0.0 37.12434 4.727249
#> ---
#> 596: 0.0 28.29614 9.070027
#> 597: 0.0 37.12434 4.727249
#> 598: 0.0 37.12434 4.727249
#> 599: 0.0 34.87739 11.489208
#> 600: 0.0 16.11315 7.395184
#> CET PAlive
#> <num> <num>
#> 1: 0.3122988 0.9143792
#> 2: 0.2865157 0.8388887
#> 3: 0.1273356 0.6590848
#> 4: 0.3048275 0.8925040
#> 5: 0.1273356 0.6590848
#> ---
#> 596: 0.3205393 0.9385066
#> 597: 0.1273356 0.6590848
#> 598: 0.1273356 0.6590848
#> 599: 0.3294171 0.9644998
#> 600: 0.4589534 0.9368629
# }
# \donttest{
# To estimate the ggomnbd 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 ggomnbd with static covariates
ggomnbd(clv.data.static.cov)
#> Starting estimation...
#> Estimation finished!
#> GGompertz/NBD with Static Covariates Model
#>
#> Call:
#> ggomnbd(clv.data = clv.data.static.cov)
#>
#> Coefficients:
#> r alpha b s beta
#> 1.648e+00 1.039e+02 2.168e-05 3.770e-01 6.581e-03
#> life.Gender life.Channel trans.Gender trans.Channel
#> -2.025e-02 2.743e+00 4.700e-01 7.367e-01
#> KKT1: TRUE
#> KKT2: FALSE
#> Constraints: FALSE
#> Regularization: FALSE
# Give initial guesses for both covariate parameters
ggomnbd(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!
#> GGompertz/NBD with Static Covariates Model
#>
#> Call:
#> ggomnbd(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 b s beta
#> 1.646e+00 1.037e+02 3.938e-05 3.792e-01 1.187e-02
#> life.Gender life.Channel trans.Gender trans.Channel
#> -1.991e-02 2.726e+00 4.696e-01 7.360e-01
#> KKT1: TRUE
#> KKT2: FALSE
#> Constraints: FALSE
#> Regularization: FALSE
# Use regularization
ggomnbd(clv.data.static.cov, reg.lambdas = c(trans = 5, life=5))
#> Starting estimation...
#> Estimation finished!
#> GGompertz/NBD with Static Covariates Model
#>
#> Call:
#> ggomnbd(clv.data = clv.data.static.cov, reg.lambdas = c(trans = 5,
#> life = 5))
#>
#> Coefficients:
#> r alpha b s beta
#> 1.303e+00 4.659e+01 1.457e-02 2.320e-01 5.241e-01
#> life.Gender life.Channel trans.Gender trans.Channel
#> -6.463e-04 -5.911e-05 6.165e-03 6.661e-03
#> KKT1: TRUE
#> KKT2: TRUE
#> Constraints: FALSE
#> Regularization: TRUE
# Force the same coefficient to be used for both covariates
ggomnbd(clv.data.static.cov, names.cov.constr = "Gender",
start.params.constr = c(Gender=0.5))
#> Starting estimation...
#> Estimation finished!
#> GGompertz/NBD with Static Covariates Model
#>
#> Call:
#> ggomnbd(clv.data = clv.data.static.cov, names.cov.constr = "Gender",
#> start.params.constr = c(Gender = 0.5))
#>
#> Coefficients:
#> r alpha b s beta
#> 1.615e+00 1.040e+02 3.463e-03 3.232e-01 1.899e+00
#> life.Channel trans.Channel constr.Gender
#> 3.172e+00 7.326e-01 4.923e-01
#> KKT1: TRUE
#> KKT2: TRUE
#> Constraints: TRUE
#> Regularization: FALSE
# Fit model only with the Channel covariate for life but
# keep all trans covariates as is
ggomnbd(clv.data.static.cov, names.cov.life = c("Channel"))
#> Starting estimation...
#> Estimation finished!
#> GGompertz/NBD with Static Covariates Model
#>
#> Call:
#> ggomnbd(clv.data = clv.data.static.cov, names.cov.life = c("Channel"))
#>
#> Coefficients:
#> r alpha b s beta
#> 1.639e+00 1.036e+02 4.731e-03 3.329e-01 1.472e+00
#> life.Channel trans.Gender trans.Channel
#> 2.869e+00 4.713e-01 7.365e-01
#> KKT1: TRUE
#> KKT2: TRUE
#> Constraints: FALSE
#> Regularization: FALSE
# }