Add dynamic covariates PMF cpp implementation for pnbd model #284
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant enhancements to the Pareto/NBD model with dynamic covariates in the
CLVToolspackage. The changes include new functionality for calculating the probability mass function (PMF) with dynamic covariates, additional helper functions, C++ integration for computational efficiency, and improved data preparation for covariate-based modelling.New functionality for dynamic covariates:
Added a new function
pnbd_dyncov_pmf_per_customerto calculate the PMF for the Pareto/NBD model with dynamic covariates for a single customer. This function integrates dynamic transaction and lifetime covariates into the PMF computation. (R/RcppExports.R,src/RcppExports.cpp,src/pnbd_dyncov_pmf.h) [1] [2] [3]Introduced helper functions for calculating covariate effects (
Bbar,Dbar,S1,S2_ij, etc.) and time boundaries (bu_i) used in the PMF computation. These functions support detailed modelling of customer behaviour over time. (R/RcppExports.R,src/pnbd_dyncov_pmf.h) [1] [2]Data preparation and R integration:
Implemented
pnbd_dyncov_prepare_datato preprocess transaction and covariate data for PMF computation. This function handles merging, transformations, and computation of time intervals and covariate effects. (R/pnbd_dyncov_pmf.R)Added an R interface function
pnbd_dyncov_pmfwith an option to use either the R or C++ implementation for PMF calculation. This allows flexibility in balancing ease of use and computational performance. (R/pnbd_dyncov_pmf.R)C++ integration for performance:
Introduced a C++ implementation of the dynamic covariate PMF computation to improve performance for large datasets. This includes the
pnbd_dyncov_pmf_per_customerfunction and supporting components. (src/pnbd_dyncov_pmf.h,src/RcppExports.cpp) [1] [2] [3]Added a wrapper for the GSL hypergeometric function
2F1with error handling to support numerical stability in PMF calculations. (R/RcppExports.R,src/pnbd_dyncov_pmf.h) [1] [2]Refactoring and renaming:
pnbd_dyncov_pmftopnbd_dyncov_pmf_rto distinguish the R implementation from the new interface function. (R/pnbd_dyncov_pmf.R)