View source: R/f_interface_latentattrition.R
latentAttrition | R Documentation |
Fit latent attrition models for transaction behavior, using a formula to specify the covariates.
latentAttrition(
formula,
family,
data,
optimx.args = list(),
verbose = TRUE,
...
)
formula |
Formula to select and transform covariates in |
family |
A latentAttrition model. One of |
data |
A |
optimx.args |
Additional arguments to control the optimization which are forwarded to |
verbose |
Show details about the running of the function. |
... |
Forwarded to model specified in |
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.
Models for inputs to family: pnbd, ggomnbd, bgnbd.
spending to fit spending models with a formula interface
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)
latentAttrition(formula =, family=bgnbd, data=clv.nocov)
latentAttrition(formula =, family=ggomnbd, data=clv.nocov)
# 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))
# Fit pnbd with all present covariates
latentAttrition(formula=~.|., family=pnbd, data=clv.staticcov)
# Fit pnbd with selected covariates
latentAttrition(formula=~Gender|Channel+Gender, family=pnbd,
data=clv.staticcov)
# 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))
# Fit pnbd with transformed covariate data
latentAttrition(formula=~Gender|I(log(Channel+2)), family=pnbd,
data=clv.staticcov)
# Fit pnbd with all covs and regularization
latentAttrition(formula=~.|., family=pnbd, data=clv.staticcov,
reg.lambdas = c(life=3, trans=8))
# Fit pnbd with all covs and constraint parameters for Channel
latentAttrition(formula=~.|., family=pnbd, data=clv.staticcov,
names.cov.constr='Channel')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.