Fit latent attrition models for transaction behavior, using a formula to specify the covariates.

latentAttrition(
  formula,
  family,
  data,
  optimx.args = list(),
  verbose = TRUE,
  ...
)

Arguments

formula

Formula to select and transform covariates in data. Has to be left empty if data contains no covariates. See Details.

family

A latentAttrition model. One of pnbd, bgnbd, or ggomnbd.

data

A clv.data object.

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.

...

Forwarded to model specified in family.

Details

A two-part formula is used to select and transform the covariates stored in data before the model is estimated on it. May not be given if data contains no covariates.

The formula left hand side (LHS) has to remain empty and may never be specified.

The formula right hand side (RHS) follows a two-part notation using | as separator.

  • 1st part: Which covariates to include for the lifetime process, potentially transforming them and adding interactions. The dot ('.') refers to all lifetime covariates.

  • 2nd part: Which covariates to include for the transaction process, potentially transforming them and adding interactions. The dot ('.') refers to all transaction covariates

e.g: ~ covlife | covtrans

See the example section for illustrations on how to specify the formula parameter.

See also

Models for inputs to family: pnbd, ggomnbd, bgnbd.

spending to fit spending models with a formula interface

Examples

# \donttest{

data("apparelTrans")
data("apparelStaticCov")

clv.nocov <-
    clvdata(apparelTrans, time.unit="w", date.format="ymd")

# Create static covariate data with 2 covariates
clv.staticcov  <-
  SetStaticCovariates(clv.nocov,
                      data.cov.life  = apparelStaticCov,
                      names.cov.life = c("Gender", "Channel"),
                      data.cov.trans = apparelStaticCov,
                      names.cov.trans = c("Gender", "Channel"))

# Fit models without covariates.
# Note that NO formula may be specified in this case
latentAttrition(formula =, family=pnbd, data=clv.nocov)
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD Standard Model
#> 
#> Call:
#> latentAttrition(family = pnbd, data = clv.nocov)
#> 
#> Coefficients:
#>       r    alpha        s     beta  
#>  1.3768  47.2937   0.6746  62.8325  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
latentAttrition(formula =, family=bgnbd, data=clv.nocov)
#> Starting estimation...
#> Estimation finished!
#> BG/NBD Standard Model
#> 
#> Call:
#> latentAttrition(family = bgnbd, data = clv.nocov)
#> 
#> Coefficients:
#>       r    alpha        a        b  
#>  0.4447  14.2235   0.6653   3.2849  
#> KKT1: TRUE 
#> KKT2: TRUE 
latentAttrition(formula =, family=ggomnbd, data=clv.nocov)
#> Starting estimation...
#> Estimation finished!
#> GGompertz/NBD Standard Model
#> 
#> Call:
#> latentAttrition(family = ggomnbd, data = clv.nocov)
#> 
#> Coefficients:
#>         r      alpha          b          s       beta  
#> 1.376e+00  4.725e+01  4.050e-07  6.743e-01  2.542e-05  
#> KKT1: TRUE 
#> KKT2: FALSE 

# Fit pnbd with start parameters and correlation
# required args are passed as part of '...'
latentAttrition(formula =, family=pnbd, data=clv.nocov,
                use.cor=TRUE,
                start.params.model=c(r=1, alpha=10, s=2, beta=8))
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD Standard Model
#> 
#> Call:
#> latentAttrition(family = pnbd, data = clv.nocov, use.cor = TRUE, 
#>     start.params.model = c(r = 1, alpha = 10, s = 2, beta = 8))
#> 
#> Coefficients:
#>               r            alpha                s             beta  
#>       1.2588082       43.0074084        0.4502443       28.1249106  
#> Cor(life,trans)  
#>      -0.0005874  
#> KKT1: FALSE 
#> KKT2: FALSE 
#> 
#> Used Options:
#> Correlation:     TRUE 


# Fit pnbd with all present covariates
latentAttrition(formula=~.|., family=pnbd, data=clv.staticcov)
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> latentAttrition(formula = ~. | ., family = pnbd, data = clv.staticcov)
#> 
#> Coefficients:
#>             r          alpha              s           beta    life.Gender  
#>        1.6943        85.6670         0.6985        56.4854        -0.6634  
#>  life.Channel   trans.Gender  trans.Channel  
#>        0.5544         0.3004         0.5583  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     FALSE 
#> Regularization:  FALSE 

# Fit pnbd with selected covariates
latentAttrition(formula=~Gender|Channel+Gender, family=pnbd,
                data=clv.staticcov)
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> latentAttrition(formula = ~Gender | Channel + Gender, family = pnbd, 
#>     data = clv.staticcov)
#> 
#> Coefficients:
#>             r          alpha              s           beta    life.Gender  
#>        1.6988        83.8248         0.6881        42.9313        -0.7195  
#> trans.Channel   trans.Gender  
#>        0.5112         0.2945  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     FALSE 
#> Regularization:  FALSE 

# Fit pnbd with start parameters for covariates
latentAttrition(formula=~Gender|., family=pnbd,
                data=clv.staticcov,
                start.params.life = c(Gender = 0.6),
                start.params.trans = c(Gender = 0.6, Channel = 0.4))
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> latentAttrition(formula = ~Gender | ., family = pnbd, data = clv.staticcov, 
#>     start.params.life = c(Gender = 0.6), start.params.trans = c(Gender = 0.6, 
#>         Channel = 0.4))
#> 
#> Coefficients:
#>             r          alpha              s           beta    life.Gender  
#>        1.7004        83.8950         0.6873        42.7870        -0.7208  
#>  trans.Gender  trans.Channel  
#>        0.2944         0.5115  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     FALSE 
#> Regularization:  FALSE 

# Fit pnbd with transformed covariate data
latentAttrition(formula=~Gender|I(log(Channel+2)), family=pnbd,
                data=clv.staticcov)
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> latentAttrition(formula = ~Gender | I(log(Channel + 2)), family = pnbd, 
#>     data = clv.staticcov)
#> 
#> Coefficients:
#>                         r                      alpha  
#>                    1.6467                   160.1213  
#>                         s                       beta  
#>                    0.6695                    38.2271  
#>               life.Gender  trans.I.log.Channel...2..  
#>                   -0.8432                     1.2318  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     FALSE 
#> Regularization:  FALSE 

# Fit pnbd with all covs and regularization
latentAttrition(formula=~.|., family=pnbd, data=clv.staticcov,
                reg.lambdas = c(life=3, trans=8))
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> latentAttrition(formula = ~. | ., family = pnbd, data = clv.staticcov, 
#>     reg.lambdas = c(life = 3, trans = 8))
#> 
#> Coefficients:
#>             r          alpha              s           beta    life.Gender  
#>      1.383495      47.741272       0.676110      62.860816      -0.006224  
#>  life.Channel   trans.Gender  trans.Channel  
#>      0.003006       0.003998       0.005636  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     FALSE 
#> Regularization:  TRUE 

# Fit pnbd with all covs and constraint parameters for Channel
latentAttrition(formula=~.|., family=pnbd, data=clv.staticcov,
                names.cov.constr='Channel')
#> Starting estimation...
#> Estimation finished!
#> Pareto/NBD with Static Covariates Model
#> 
#> Call:
#> latentAttrition(formula = ~. | ., family = pnbd, data = clv.staticcov, 
#>     names.cov.constr = "Channel")
#> 
#> Coefficients:
#>              r           alpha               s            beta     life.Gender  
#>         1.6938         85.6338          0.6995         56.7011         -0.6637  
#>   trans.Gender  constr.Channel  
#>         0.3002          0.5581  
#> KKT1: TRUE 
#> KKT2: TRUE 
#> 
#> Used Options:
#> Correlation:     FALSE 
#> Constraints:     TRUE 
#> Regularization:  FALSE 

# }