1
$\begingroup$

I have a dataset each with a line for different products, a count of sales and a number of days on sale. I estimated a Poisson regression to predict sales with an offset term of number of days on sale, but it was over-dispersed and I'm considering using a zero-inflated model. I used the DHARMa package's testZeroInflation function - my model failed the test and clearly has too many zeros.

However, I would like to verify this for myself manually. This Q&A sets out how to do that for a simple dataset with counts only, and I tried something similar:

length(myData$sales[myData$sales==0]))   # number of zero sales
P0 <- ppois(0, mean(myData$sales / myData$daysOnSale))
P0 * length(myData$sales) # expected number of zeros given Poisson distribution

This test showed I had far fewer zeros than expected. My interpretation is that this would be correct if the exposure term - daysOnSale - were 1 in all cases, but actually it varies widely: from 1 to several hundred.

Is there a (straightforward) way to account for exposure when calculating the expected number of zeros?

$\endgroup$
2
  • $\begingroup$ Could you post a full account of your data and results. $\endgroup$ Oct 9, 2018 at 14:34
  • $\begingroup$ You can add up the expected zeros for each case, with its individual exposure. $\endgroup$
    – Glen_b
    Oct 10, 2018 at 5:04

1 Answer 1

1
$\begingroup$

Well, yes. With $\lambda=\text{expected number of sales in one day}$ and $n=\text{exposure}$, $X$ the total number of sales, then $X$ is distributed poisson with expectation $n\cdot\lambda$, so $$ \mathbb{P}(X=0) = e^{-n\cdot \lambda} $$

$\endgroup$
2
  • $\begingroup$ Thanks @kjetilbhalvorsen, so would the final answer be to calculate this probability of observing zero for each row and then sum across the rows? As in, myData$probZeroSales <- exp(-1 * myData$daysOnSale * mean(myData$sales / myData$daysOnSale)), sum(myData$probZeroSales) $\endgroup$ Oct 9, 2018 at 15:40
  • $\begingroup$ That looks ok... $\endgroup$ Oct 9, 2018 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.