Skip to content

Commit

Permalink
Prepare release v0.7
Browse files Browse the repository at this point in the history
Cran comments, news.md
docu:typos, roxygen, non-ascii chars, info on cohorts
rcpp: inconsistent inputchecks
Added more information on plotting the expected and actual repeat transactions (setting the stage for adressing #142)
Tests: transaction object copied when adding covariates, enable for multiple optimization methods, verify zero-repeaters
  • Loading branch information
pschil committed Oct 7, 2020
1 parent ec582ea commit 57628d2
Show file tree
Hide file tree
Showing 33 changed files with 294 additions and 189 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: CLVTools
Title: Tools for Customer Lifetime Value Estimation
Version: 0.7.0
Date: 2020-06-25
Date: 2020-08-26
Authors@R: c(
person(given="Patrick", family="Bachmann", email = "[email protected]", role = c("cre","aut")),
person(given="Jeffrey", family="Naef", email = "[email protected]",role = "aut"),
Expand Down
13 changes: 13 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# CLVTools 0.7.0

### NEW FEATURES
* Refactor the Gamma-Gamma (GG) model to predict mean spending per transaction into an independent model
* The prediction for transaction models can now be combined with separately fit spending models
* Write the unconditional expectation functions in Rcpp for faster plotting (Pareto/NBD and Beta-Geometric/NBD)
* Improved documentation and walkthrough

### BUG FIXES
* Pareto/NBD LogLikelihood: For the case Tcal = t.x and for the case alpha == beta
* Static or dynamic covariates with syntactically invalid names (spaces, start with numbers, etc) could not be fit


# CLVTools 0.6.0

### NEW FEATURES
Expand Down
2 changes: 1 addition & 1 deletion R/class_clv_gg.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @templateVar name_model_full GammaGamma
#' @templateVar name_model_full Gamma-Gamma
#' @templateVar name_class_clvmodel clv.model.gg
#' @template template_class_clvfittedspendingmodels
#'
Expand Down
7 changes: 0 additions & 7 deletions R/clv_template_controlflow_estimate.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ clv.template.controlflow.estimate <- function(clv.fitted,
optimx.args,
verbose,
...){
# ***TODO: For development purposes only: All additional args have to be named!
l.elipsis <- list(...)
if(length(l.elipsis)>0){
names.ellipsis.args <- names(list(...))
stopifnot(!is.null(names.ellipsis.args))
stopifnot(all(nchar(names(list(...)))>0))
}

# input checks ------------------------------------------------------------------------------------------
# checks for model first
Expand Down
10 changes: 1 addition & 9 deletions R/clv_template_controlflow_predict.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
clv.template.controlflow.predict <- function(clv.fitted, verbose, user.newdata, ...){

# ***TODO: For development purposes only: All additional args have to be named!
l.elipsis <- list(...)
if(length(l.elipsis)>0){
names.ellipsis.args <- names(list(...))
stopifnot(!is.null(names.ellipsis.args))
stopifnot(all(nchar(names(list(...)))>0))
}

# Check if can predict -----------------------------------------------------------------------------------------
# Cannot predict if there are any NAs in any of the prediction.params
clv.controlflow.check.prediction.params(clv.fitted = clv.fitted)
Expand Down Expand Up @@ -40,7 +32,7 @@ clv.template.controlflow.predict <- function(clv.fitted, verbose, user.newdata,
dt.predictions = dt.predictions, verbose = verbose, ...)
setkeyv(dt.predictions, "Id")

# Actuals ---------------------------------------------------------------------------------------------¨
# Actuals ---------------------------------------------------------------------------------------------
has.actuals <- clv.controlflow.predict.get.has.actuals(clv.fitted, dt.predictions = dt.predictions)
dt.predictions <- clv.controlflow.predict.add.actuals(clv.fitted = clv.fitted, dt.predictions = dt.predictions,
has.actuals = has.actuals, verbose = verbose, ...)
Expand Down
2 changes: 1 addition & 1 deletion R/f_interface_bgnbd.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ setGeneric("bgnbd", def = function(clv.data, start.params.model=c(), optimx.args
#' the technical note by Fader and Hardie (2007).
#'
#' The likelihood function is the likelihood function associated with the basic model where
#' alpha, a, and b are replaced with alpha = alpha0*exp(g1z1), a = a_0*exp(g2z2), and b = b0*exp(g3z2)
#' alpha, a, and b are replaced with alpha = alpha0*exp(-g1z1), a = a_0*exp(g2z2), and b = b0*exp(g3z2)
#' while r remains unchanged. Note that in the current implementation, we constrain the covariate parameters
#' and data for the lifetime process to be equal (g2=g3 and z2=z3).
#' }
Expand Down
9 changes: 6 additions & 3 deletions R/f_interface_pnbd.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#' The smaller r, the stronger the heterogeneity of the purchase process.\cr
#' \code{alpha}: scale parameter of the Gamma distribution of the purchase process.
#'
#' Based on these parameters, the average purchase rate while customers are active
#' is r/alpha and the average dropout rate is s/beta.
#'
#' Ideally, the starting parameters for r and s represent your best guess
#' concerning the heterogeneity of customers in their buy and die rate.
#' If covariates are included into the model additionally parameters for the
Expand Down Expand Up @@ -67,14 +70,14 @@
#' @note
#' Fitting the Pareto/NBD model with dynamic covariates is for the most part implemented using \code{data.table} and to a smaller part further
#' parallelized with the \code{foreach} package. Registering a
#' parallel backend with \code{\link[doFuture]{doFuture}} or \code{\link[doParallel:doParallel-package]{doParallel}} before fitting the
#' parallel backend with \code{\link[doFuture]{doFuture}} or \code{\link[doParallel]{doParallel}} before fitting the
#' models allows to take advantage of this. If no parallel backend is set up, the \code{foreach} package gives a friendly reminder that
#' it is executed sequentially. In case this is desired but no warning should be given, a parallel backend in sequential mode
#' can be set up, for example package \code{doFuture} with \code{\link[future:plan]{plan("sequential")}}.
#'
#' The part executed with \code{foreach} also heavily relies on \code{data.table} which is natively parallelized already. When setting up
#' the parallel backend, great care should be taken to reduce the overhead from this nested parallelism as otherwise it can \emph{increase} runtime.
#' See \code{\link[data.table:openmp-utils]{setDTthreads}}, \code{\link[data.table:openmp-utils]{getDTthreads}},
#' See \code{\link[data.table]{setDTthreads}}, \code{\link[data.table]{getDTthreads}},
#' and \code{\link[future]{plan}} for information on how to do this.
#'
#' The Pareto/NBD model with dynamic covariates can currently not be fit with data that has a temporal resolution
Expand All @@ -88,7 +91,7 @@
#' @template template_clvfittedtransactions_seealso
#' @seealso \code{\link[CLVTools:SetDynamicCovariates]{SetDynamicCovariates}} to add dynamic covariates on which the \code{pnbd} model can be fit.
#'
#' @seealso \code{\link[data.table:openmp-utils]{setDTthreads}}, \code{\link[data.table:openmp-utils]{getDTthreads}},\code{\link[doParallel:registerDoParallel]{registerDoParallel}},\code{\link[doFuture]{registerDoFuture}} for setting up parallel execution.
#' @seealso \code{\link[data.table]{setDTthreads}}, \code{\link[data.table]{getDTthreads}},\code{\link[doParallel]{registerDoParallel}},\code{\link[doFuture]{registerDoFuture}} for setting up parallel execution.
#'
#' @template template_references_pnbd
#'
Expand Down
2 changes: 1 addition & 1 deletion R/f_interface_predict_clvfittedtransactions.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
#' # Predict future transactions but not spending and CLV
#' predict(apparel.pnbd, predict.spending = FALSE)
#'
#' # Predict spending by fitting a GammaGamma model
#' # Predict spending by fitting a Gamma-Gamma model
#' predict(apparel.pnbd, predict.spending = gg)
#'
#' # Fit a spending model separately and use it to predict spending
Expand Down
2 changes: 1 addition & 1 deletion R/f_s3generics_clvfitted.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ coef.clv.fitted <- function(object, ...){
#' @description
#' Returns the variance-covariance matrix of the parameters of the fitted model object.
#' The variance-covariance matrix is derived from the Hessian that results from the optimization procedure.
#' First, the MoorePenrose generalized inverse of the Hessian is used to obtain an estimate of the
#' First, the Moore-Penrose generalized inverse of the Hessian is used to obtain an estimate of the
#' variance-covariance matrix.
#' Next, because some parameters may be transformed for the purpose of restricting their value during
#' the log-likelihood estimation, the variance estimates are adapted to
Expand Down
4 changes: 3 additions & 1 deletion R/f_s3generics_clvfittedtransactions_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#'
#' @description
#' Plot the actual repeat transactions and overlay it with the repeat transaction as predicted
#' by the fitted model (unconditional expectation).
#' by the fitted model. Currently, following previous literature, the in-sample unconditional
#' expectation is plotted in the holdout period. In the future, we might add the option to also
#' plot the summed CET for the holdout period as an alternative evaluation metric.
#'
#' @template template_details_predictionend
#'
Expand Down
Loading

0 comments on commit 57628d2

Please sign in to comment.