Fit latent Gamma-Gamma model for customer spending with a formula interface
spending(formula, data, optimx.args = list(), verbose = TRUE)
Formula specifying the model to be fit. See Details.
Either a clv.data
object or a data.frame
containing transaction
data on which the model specified in formula
will be fit.
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.
Returns an object of the respective model which was fit.
Spending models for inputs: gg.
latentAttrition to fit latent attrition models with a formula interface
# \donttest{
data("cdnow")
clv.cdnow <- clvdata(data.transactions = cdnow, date.format="ymd",
time.unit = "weeks")
# Fit gg
spending(~gg(), data=clv.cdnow)
#> Starting estimation...
#> Estimation finished!
#> Gamma-Gamma Model
#>
#> Call:
#> spending(formula = ~gg(), data = clv.cdnow)
#>
#> Coefficients:
#> p q gamma
#> 4.685 4.188 24.369
#> KKT1: TRUE
#> KKT2: TRUE
# Fit gg with start params
spending(~gg(start.params.model=c(p=0.5, q=15, gamma=2)),
data=clv.cdnow)
#> Starting estimation...
#> Estimation finished!
#> Gamma-Gamma Model
#>
#> Call:
#> spending(formula = ~gg(start.params.model = c(p = 0.5, q = 15,
#> gamma = 2)), data = clv.cdnow)
#>
#> Coefficients:
#> p q gamma
#> 4.683 4.190 24.391
#> KKT1: TRUE
#> KKT2: TRUE
# Fit gg, do not remove first transaction
spending(~gg(remove.first.transaction=FALSE), data=clv.cdnow)
#> Starting estimation...
#> Estimation finished!
#> Gamma-Gamma Model
#>
#> Call:
#> spending(formula = ~gg(remove.first.transaction = FALSE), data = clv.cdnow)
#>
#> Coefficients:
#> p q gamma
#> 7.060 3.752 12.894
#> KKT1: TRUE
#> KKT2: TRUE
# same, abreviate parameters
spending(~gg(remo=F), data=clv.cdnow)
#> Starting estimation...
#> Estimation finished!
#> Gamma-Gamma Model
#>
#> Call:
#> spending(formula = ~gg(remo = F), data = clv.cdnow)
#>
#> Coefficients:
#> p q gamma
#> 7.060 3.752 12.894
#> KKT1: TRUE
#> KKT2: TRUE
# Fit gg on given data.frame transaction data, no split
spending(data()~gg(), data=cdnow)
#> Starting estimation...
#> Estimation finished!
#> Gamma-Gamma Model
#>
#> Call:
#> spending(formula = data() ~ gg(), data = cdnow)
#>
#> Coefficients:
#> p q gamma
#> 4.685 4.188 24.369
#> KKT1: TRUE
#> KKT2: TRUE
# Fit gg on given data.frame, split after 39 periods
spending(data(split=39)~gg(), data=cdnow)
#> Starting estimation...
#> Estimation finished!
#> Gamma-Gamma Model
#>
#> Call:
#> spending(formula = data(split = 39) ~ gg(), data = cdnow)
#>
#> Coefficients:
#> p q gamma
#> 6.238 3.746 15.478
#> KKT1: TRUE
#> KKT2: TRUE
# same but also give date format and period definition
spending(data(split=39, format=ymd, unit=w)~gg(), data=cdnow)
#> Starting estimation...
#> Estimation finished!
#> Gamma-Gamma Model
#>
#> Call:
#> spending(formula = data(split = 39, format = ymd, unit = w) ~
#> gg(), data = cdnow)
#>
#> Coefficients:
#> p q gamma
#> 6.238 3.746 15.478
#> KKT1: TRUE
#> KKT2: TRUE
## No covariate may be selected or covariate data.frame may be
## given because currently no spending model uses covariates
# }