View source: R/f_interface_setdynamiccovariates.R
SetDynamicCovariates | R Documentation |
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 |
CLV data object to add the covariates data to. |
data.cov.life |
Dynamic covariate data as |
data.cov.trans |
Dynamic covariate data as |
names.cov.life |
Vector with names of the columns in |
names.cov.trans |
Vector with names of the columns in |
name.id |
Name of the column to find the Id data for both, |
name.date |
Name of the column to find the Date data for both, |
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.
An object of class clv.data.dynamic.covariates
.
See the class definition clv.data.dynamic.covariates
for more details about the returned object.
## Not run:
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)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.