spend.marginal.likelihood: Gamma-gamma marginal likelihood

Description Usage Arguments Details Value References Examples

View source: R/spend.R

Description

Calculates the marginal likelihood of a customer's average transaction value.

Usage

1
spend.marginal.likelihood(params, m.x, x)

Arguments

params

a vector of gamma-gamma parameters: p, q, and gamma, in that order. p is the shape parameter for each transaction. The scale parameter for each transaction is distributed across customers according to a gamma distribution with parameters q (shape) and gamma (scale).

m.x

the customer's average observed transaction value in the calibration period. May also be a vector of average observed transaction values - see details.

x

the number of transactions the customer made in the calibration period. May also be a vector of frequencies - see details.

Details

m.x and x may be vectors. The standard rules for vector operations apply - if they are not of the same length, the shorter vector will be recycled (start over at the first element) until it is as long as the longest vector. It is advisable to keep vectors to the same length and to use single values for parameters that are to be the same for all calculations. If one of these parameters has a length greater than one, the output will be a vector of probabilities.

This function will issue a warning if any of m.x or x is 0, and will return a marginal likelihood of 0 for those values.

f(m.x | p, q, gamma, x).

Value

The marginal distribution of a customer's average transaction value. If m.x or x has a length greater than 1, a vector of marginal likelihoods will be returned.

References

Fader, Peter S., Bruce G.S. Hardie, and Ka L. Lee. “RFM and CLV: Using Iso-Value Curves for Customer Base Analysis.” Journal of Marketing Research Vol.42, pp.415-430. November. 2005. Web.

See equation 3.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
params <- c(6, 4, 16)

# calculate the marginal distribution of the average transaction value
# of a customer who spent an average of $35 over 3 transactions.
spend.marginal.likelihood(params, m.x=35, x=3)

# Several values can also be computed at once:
spend.marginal.likelihood(params, m.x=30:40, x=3)
spend.marginal.likelihood(params, m.x=35, x=1:10)
spend.marginal.likelihood(params, m.x=30:40, x=1:11)

Example output

Loading required package: hypergeo
[1] 0.01628041
 [1] 0.02178306 0.02058508 0.01943300 0.01833037 0.01727922 0.01628041
 [7] 0.01533388 0.01443890 0.01359421 0.01279820 0.01204899
 [1] 0.01457300 0.01580541 0.01628041 0.01653229 0.01668839 0.01679462
 [7] 0.01687158 0.01692991 0.01697564 0.01701246
 [1] 0.01892075 0.01983798 0.01943300 0.01865303 0.01774288 0.01679462
 [7] 0.01585007 0.01493027 0.01404619 0.01320346 0.01240461

BTYD documentation built on Nov. 18, 2021, 1:10 a.m.