Add static covariate data to an existing data object of class clv.data. The returned object then can be used to fit models with static covariates.

No covariate data can be added to a clv data object which already has any covariate set.

At least 1 covariate is needed for both processes and no categorical covariate may be of only a single category.

SetStaticCovariates(
  clv.data,
  data.cov.life,
  data.cov.trans,
  names.cov.life,
  names.cov.trans,
  name.id = "Id"
)

Arguments

clv.data

CLV data object to add the covariates data to.

data.cov.life

Static covariate data as data.frame or data.table for the lifetime process.

data.cov.trans

Static covariate data as data.frame or data.table for the transaction process.

names.cov.life

Vector with names of the columns in data.cov.life that contain the covariates.

names.cov.trans

Vector with names of the columns in data.cov.trans that contain the covariates.

name.id

Name of the column to find the Id data for both, data.cov.life and data.cov.trans.

Value

An object of class clv.data.static.covariates. See the class definition clv.data.static.covariates for more details about the returned object.

Details

data.cov.life and data.cov.trans are data.frames or data.tables that each contain exactly one single row of covariate data for every customer appearing in the transaction data. Covariates of class character or factor are converted to k-1 numeric dummy variables.

Examples

# \donttest{ data("apparelTrans") data("apparelStaticCov") # Create a clv data object without covariates clv.data.apparel <- clvdata(apparelTrans, time.unit="w", date.format="ymd") # Add static covariate data clv.data.apparel.cov <- SetStaticCovariates(clv.data.apparel, data.cov.life = apparelStaticCov, names.cov.life = "Gender", data.cov.trans = apparelStaticCov, names.cov.trans = "Gender", name.id = "Id") # more summary output summary(clv.data.apparel.cov)
#> CLV Transaction Data with Static Covariates #> #> Time unit Weeks #> Estimation length 79.8571 Weeks #> Holdout length - #> #> Transaction Data Summary #> Estimation Holdout Total #> Number of customers - - 250 #> First Transaction in period 2005-01-03 - 2005-01-03 #> Last Transaction in period 2006-07-16 - 2006-07-16 #> Total # Transactions 2257 - 2257 #> Mean # Transactions per cust 9.028 - 9.028 #> (SD) 12.603 - 12.603 #> Mean Spending per Transaction 39.051 - 39.051 #> (SD) 50.503 - 50.503 #> Total Spending 88139.130 - 88139.130 #> Total # zero repeaters 65 - 65 #> Percentage # zero repeaters 0.260 - 0.260 #> Mean Interpurchase time 9.462 - 9.462 #> (SD) 12.266 - 12.266 #> #> Covariates #> Trans. Covariates Gender #> # covs 1 #> Life. Covariates Gender #> # covs 1 #>
# fit model with static covariates pnbd(clv.data.apparel.cov)
#> Starting estimation...
#> Estimation finished!
#> Pareto NBD with Static Covariates Model #> #> Call: #> pnbd(clv.data = clv.data.apparel.cov) #> #> Coefficients: #> r alpha s beta life.Gender #> 1.1126 19.4120 0.4541 32.3265 1.0757 #> trans.Gender #> 1.3096 #> KKT1: TRUE #> KKT2: TRUE #> #> Used Options: #> Correlation: FALSE #> Constraints: FALSE #> Regularization: FALSE
# }