Skip to content

Commit 2e82c02

Browse files
authored
added sales.x to elog2cbs output (#54)
fixes #54
1 parent 6b4a175 commit 2e82c02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+34
-70
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: BTYDplus
22
Type: Package
33
Title: Probabilistic Models for Assessing and Predicting your Customer Base
4-
Version: 1.1.0
4+
Version: 1.1.1
55
Authors@R: person("Michael", "Platzer", email = "[email protected]", role = c("aut", "cre"))
66
Description: Provides advanced statistical methods to describe and predict customers'
77
purchase behavior in a non-contractual setting. It uses historic transaction records to fit a
@@ -32,6 +32,6 @@ Suggests:
3232
rmarkdown,
3333
lintr (>= 1.0.0)
3434
Roxygen: list(wrap = FALSE)
35-
RoxygenNote: 5.0.1
35+
RoxygenNote: 6.0.1
3636
LazyData: true
3737
VignetteBuilder: knitr

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
1.1.1
2+
- added `sales.x` to `elog2cbs` output, which sums over sales in calibration, but excludes initial transaction (thanks to msinjin for the suggestion)
3+
14
1.1.0
25
- added `(m)bgcnbd.PlotFreqVsConditionalExpectedFrequency` methods
36
- added `(m)bgcnbd.PlotRecVsConditionalExpectedFrequency` methods

R/helpers.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ plotTimingPatterns <- function(elog, n = 40, T.cal = NULL, T.tot = NULL,
262262
#' \item{\code{x}}{Number of recurring events in calibration period.}
263263
#' \item{\code{t.x}}{Time between first and last event in calibration period.}
264264
#' \item{\code{litt}}{Sum of logarithmic intertransaction timings during calibration period.}
265-
#' \item{\code{sales}}{Sum of sales in calibration period. Only if \code{elog$sales} is provided.}
265+
#' \item{\code{sales}}{Sum of sales in calibration period, incl. initial transaction. Only if \code{elog$sales} is provided.}
266+
#' \item{\code{sales.x}}{Sum of sales in calibration period, excl. initial transaction. Only if \code{elog$sales} is provided.}
266267
#' \item{\code{first}}{Date of first transaction in calibration period.}
267268
#' \item{\code{T.cal}}{Time between first event and end of calibration period.}
268269
#' \item{\code{T.star}}{Length of holdout period. Only if \code{T.cal} is provided.}
@@ -274,7 +275,7 @@ plotTimingPatterns <- function(elog, n = 40, T.cal = NULL, T.tot = NULL,
274275
#' cbs <- elog2cbs(groceryElog, T.cal = "2006-12-31", T.tot = "2007-12-30")
275276
#' head(cbs)
276277
elog2cbs <- function(elog, units = "week", T.cal = NULL, T.tot = NULL) {
277-
cust <- first <- itt <- T.star <- x.star <- sales <- sales.star <- NULL # suppress checkUsage warnings
278+
cust <- first <- itt <- T.star <- x.star <- sales <- sales.star <- sales.x <- NULL # suppress checkUsage warnings
278279
stopifnot(inherits(elog, "data.frame"))
279280
if (!all(c("cust", "date") %in% names(elog))) stop("`elog` must have fields `cust` and `date`")
280281
if (!any(c("Date", "POSIXt") %in% class(elog$date))) stop("`date` field must be of class `Date` or `POSIXt`")
@@ -311,7 +312,8 @@ elog2cbs <- function(elog, units = "week", T.cal = NULL, T.tot = NULL) {
311312
list(x = .N - 1,
312313
t.x = max(t),
313314
litt = sum(log(itt[itt > 0])),
314-
sales = sum(sales)),
315+
sales = sum(sales),
316+
sales.x = sum(sales[t > 0])),
315317
by = "cust,first"]
316318
cbs[, `:=`(T.cal, as.numeric(difftime(T.cal, first, units = units)))]
317319
setkey(cbs, cust)
@@ -322,14 +324,16 @@ elog2cbs <- function(elog, units = "week", T.cal = NULL, T.tot = NULL) {
322324
cbs <- merge(cbs, val, all.x = TRUE, by = "cust")
323325
cbs[is.na(x.star), `:=`(x.star, 0)]
324326
cbs[is.na(sales.star), `:=`(sales.star, 0)]
325-
setcolorder(cbs, c("cust", "x", "t.x", "litt", "sales", "first", "T.cal", "T.star", "x.star", "sales.star"))
327+
setcolorder(cbs, c("cust", "x", "t.x", "litt", "sales", "sales.x", "first", "T.cal",
328+
"T.star", "x.star", "sales.star"))
326329
} else {
327-
setcolorder(cbs, c("cust", "x", "t.x", "litt", "sales", "first", "T.cal"))
330+
setcolorder(cbs, c("cust", "x", "t.x", "litt", "sales", "sales.x", "first", "T.cal"))
328331
}
329332
# return same object type as was passed
330333
if (!has.sales) {
331334
elog_dt[, `:=`(sales, NULL)]
332335
cbs[, `:=`(sales, NULL)]
336+
cbs[, `:=`(sales.x, NULL)]
333337
if (has.holdout) cbs[, `:=`(sales.star, NULL)]
334338
}
335339
if (!is.dt) {

man/abe.GenerateData.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/abe.mcmc.DrawParameters.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dc.PlotFreqVsConditionalExpectedFrequency.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dc.PlotRecVsConditionalExpectedFrequency.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dc.PlotTracking.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dc.check.model.params.safe.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/elog2cbs.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)