Add dynamic covariate data to an existing data object of class clv.data. The returned object can be used to fit models with dynamic 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.

SetDynamicCovariates(
  clv.data,
  data.cov.life,
  data.cov.trans,
  names.cov.life,
  names.cov.trans,
  name.id = "Id",
  name.date = "Date"
)

Arguments

clv.data

CLV data object to add the covariates data to.

data.cov.life

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

data.cov.trans

Dynamic 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.

name.date

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

Value

An object of class clv.data.dynamic.covariates. See the class definition clv.data.dynamic.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 1 row for every combination of timepoint and customer. For each customer appearing in the transaction data there needs to be covariate data at every timepoint that marks the start of a period as defined by time.unit. It has to range from the start of the estimation sample (timepoint.estimation.start) until the end of the period in which the end of the holdout sample (timepoint.holdout.end) falls. See the the provided data apparelDynCov for illustration. Covariates of class character or factor are converted to k-1 numeric dummies.

Date as character If the Date column in the covariate data is of type character, the date.format given when creating the the clv.data object is used for parsing.

Examples

if (FALSE) { data("apparelTrans") data("apparelDynCov") # Create a clv data object without covariates clv.data.apparel <- clvdata(apparelTrans, time.unit="w", date.format="ymd") # Add static covariate data clv.data.dyn.cov <- SetDynamicCovariates(clv.data.apparel, data.cov.life = apparelDynCov, names.cov.life = c("Marketing", "Gender", "Channel"), data.cov.trans = apparelDynCov, names.cov.trans = c("Marketing", "Gender", "Channel"), name.id = "Id", name.date = "Cov.Date") # summary output about covariates data summary(clv.data.dyn.cov) # fit pnbd model with dynamic covariates pnbd(clv.data.dyn.cov) }