BTYDplus icon indicating copy to clipboard operation
BTYDplus copied to clipboard

Use of table in xbgcnbd.PlotFrequencyInCalibration (and mcmc.PlotFrequencyInCalibration)

Open SebDub opened this issue 6 years ago • 0 comments

Hi!

First, thanks a lot for the package. Really useful stuff here.

I noticed what I think is a bug in xbgcnbd.PlotFrequencyInCalibration (and potentially in mcmc.PlotFrequencyInCalibration, but I didn't use it directly). The behavior at the line x_act <- table(x_act) is not correct, to me, when a member of the series 0:censor is missing in the table, e.g. if our censor is at 52 and nobody made 20,35, or 45 repeat transactions. It will not fill with 0 this frequency values and hence x_act will be smaller than x_ect and due to the way R handle this, the matrix will be ... strange (got a warning in Rstudio, didn't in Visual Studio) It can be fixed by using: x_act <- table(factor(x_act, levels=c(0:censor)))

See this toy example to understand what i mean:

censor=25

x_act <- c(1:10, 20:30)
x_act[x_act > censor] <- censor
x_act <- table(x_act)
x_est <- 0:censor
mat <- matrix(c(x_act, x_est), nrow = 2, ncol = censor + 1, byrow = TRUE)
mat

x_act2 <- c(1:10, 20:30)
x_act2[x_act2 > censor] <- censor
x_act2 <- table(factor(x_act2,levels=c(0:censor)))
x_est <- 0:censor
mat2 <- matrix(c(x_act2, x_est), nrow = 2, ncol = censor + 1, byrow = TRUE)
mat2

I know this is a limit case. But I encountered it analysing some 'small' data subset and thought it would be worth rising it up here. I'd gladly submit a pull request if you want.

Cheers, Sébastien

Ps: first post actually on github... please don't hate me if I'm too long...

SebDub avatar Jan 17 '19 18:01 SebDub