R/f_interface_setstaticcovariates.R
SetStaticCovariates.Rd
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"
)
CLV data object to add the covariates data to.
Static covariate data as data.frame
or data.table
for the lifetime process.
Static 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
.
An object of class clv.data.static.covariates
.
See the class definition clv.data.static.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 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.
# \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 311.1429 Weeks
#> Holdout length -
#>
#> Transaction Data Summary
#> Estimation Holdout Total
#> Number of customers - - 600
#> First Transaction in period 2005-01-02 - 2005-01-02
#> Last Transaction in period 2010-12-20 - 2010-12-20
#> Total # Transactions 3183 - 3183
#> Mean # Transactions per cust 5.305 - 5.305
#> (SD) 6.119 - 6.119
#> Mean Spending per Transaction 39.069 - 39.069
#> (SD) 66.519 - 66.519
#> Total Spending 124356.900 - 124356.900
#> Total # zero repeaters 175 - -
#> Percentage of zero repeaters 29.167 - -
#> Mean Interpurchase time 37.817 - 37.817
#> (SD) 42.339 - 42.339
#>
#> 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.4521 58.3840 0.7280 49.3643 -0.7065
#> trans.Gender
#> 0.2823
#> KKT1: TRUE
#> KKT2: TRUE
#>
#> Used Options:
#> Correlation: FALSE
#> Constraints: FALSE
#> Regularization: FALSE
# }