Maximum likelihood estimation of the gamma-gamma model of spend per transaction, with time-varying and time-invariant covariates and unobserved cross-sectional heterogeneity, following Fader and Hardie (2024) < https://brucehardie.com/notes/045/>.
GammaGammaCov implements the gamma-gamma model of spend per transaction with both time-varying and time-invariant covariates, following the methodology of Fader and Hardie (2024).
Install the released version from CRAN:
install.packages("GammaGammaCov")
Or install the development version from GitHub:
# install.packages("remotes")
remotes::install_github("kaloklee/GammaGammaCov")
spend_data_sample)Data are in transaction (long) format: one row per transaction, with the customer identifier, the amount spent, and the covariate values in effect at the time of that transaction.
Here we demonstrate estimation using spend_data_sample, a small simulated dataset included for rapid experimentation and testing:
library(GammaGammaCov)
# Load the quick-start sample dataset
spend_data_sample <- GammaGammaCov::spend_data_sample
# Estimate the spend model with dynamic covariates
fit <- GGcov_MLE(
Price ~ discount + gender + channel,
data = spend_data_sample,
subject = "Id"
)
# Print parameter estimates, standard errors, and Wald confidence intervals
print(fit)
# Plot the distribution of the baseline spending rate across customers
GGcov_plot_mixing(fit)
GGcov_expected_spend() returns the posterior conditional expectation of the monetary value of a future transaction, given the customer's history and the covariate values of that transaction (assumed known). Here we predict each customer's next transaction at a 10% discount:
# Each customer's gender and channel, taken from their last observed row
last_rows <- spend_data_sample[!duplicated(spend_data_sample$Id, fromLast = TRUE), ]
future <- last_rows[, c("Id", "discount", "gender", "channel")]
future$discount <- 0.1
GGcov_expected_spend(fit, newdata = future, history = spend_data_sample)
For a more comprehensive demonstration of the package's functionality, browse the introductory vignette online, or build it locally:
remotes::install_github("kaloklee/GammaGammaCov", build_vignettes = TRUE)
vignette("introduction_to_ggcov_vignette", package = "GammaGammaCov")
Licensed under the Apache License 2.0.
Questions, issues, or contributions: Ka Lok Lee (kaloklee@gmail.com).