R/f_interface_setdynamiccovariates.R
SetDynamicCovariates.Rd
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"
)
CLV data object to add the covariates data to.
Dynamic covariate data as data.frame
or data.table
for the lifetime process.
Dynamic covariate data as data.frame
or data.table
for the transaction process.
Vector with names of the columns in data.cov.life
that contain the covariates.
Vector with names of the columns in data.cov.trans
that contain the covariates.
Name of the column to find the Id data for both, data.cov.life
and data.cov.trans
.
Name of the column to find the Date data for both, data.cov.life
and data.cov.trans
.
An object of class clv.data.dynamic.covariates
.
See the class definition clv.data.dynamic.covariates
for more details about the returned object.
data.cov.life
and data.cov.trans
are data.frame
s or data.table
s 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.
if (FALSE) { # \dontrun{
data("apparelTrans")
data("apparelDynCov")
# Create a clv data object without covariates
clv.data.apparel <- clvdata(apparelTrans, time.unit="w",
date.format="ymd")
# Add dynamic covariate data
clv.data.dyn.cov <-
SetDynamicCovariates(clv.data.apparel,
data.cov.life = apparelDynCov,
names.cov.life = c("High.Season", "Gender", "Channel"),
data.cov.trans = apparelDynCov,
names.cov.trans = c("High.Season", "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)
} # }