# Generate zero-inflated random vector

I want to randomly generate a vector of size n - that represents hypothetical revenues per users in a webshop.

Typically I would imagine this distribution to have:

• a disproportionate amount of 0 (users that do not buy, let's say around 95%)
• a lower bound at 0 (users can't buy for less than zero dollars)
• unbounded above (users are unlimited in their potential expenditure)

The distribution will hence be right-skewed.

In R, I tried with:

pois_data <-rpois(100,lambda=0.01)
lambda_est <- mean(pois_data)
p0_tilde <- exp(-lambda_est)
# number of observtions 'expected' to be zero
n*p0_tilde
97.0445533548508


In this Poisson I have a 97% of 0s, but instead of the observation valued 1, I want continuous values that might reflect an hypothetical distrubution of revenues (I read that typically would be drawn from a lognormal).

How can I do that in R?

• Zero-inflated data is the result of a two-step process: The first step decides if the data is zero or not (buy or don't buy), the second step decides the value for non-zero data (how much did the users pay). Your simulation therefore should include two calls to RNG functions. – Roland Apr 12 '18 at 11:19

isZero = rbinom(n = 100, size = 1, prob = 0.97)