SetStaticCovariates: Add Static Covariates to a CLV data object

View source: R/f_interface_setstaticcovariates.R

SetStaticCovariatesR Documentation

Add Static Covariates to a CLV data object

Description

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.

Usage

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.

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.

Value

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

Examples




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)

# fit model with static covariates
pnbd(clv.data.apparel.cov)



CLVTools documentation built on Oct. 13, 2024, 9:07 a.m.