Hello everyone,
This is my first post as an SE ... pardon me if the answer seems trivial!
A customer would like to be able to generate random data according to several statistical laws, one of them is the ZIP law. In the formula editor, it is possible to have Random Poisson() ... but not Random Zero Inflated Poisson().
Is there a way to generate such a random distribution (with Pi: % of zero and µ parameter of the Poisson distribution)?
Thanks in advance, Stéphane
Hi,
First: boringly but importantly, a ZIP( lambda, p ) typically is modeled as the mixture of a poisson (lambda) distribution and a 0 distribution, in proportions (1-p) and p, respectively.
Because a Poisson distribution is capable of generating zeros all by itself, the actual proportion of zeros (long term) from the ZIP will be greater than p, and equal p + (1-p)*e^( - lambda).
So the first thing the customer must do is decide: do they wish to use p to stand for the probability that the data comes from the zero distribution (the standard), or do they wish to specify the TOTAL proportion of zeros generated by the ZIP process?
If the former, use p as I have used it below. If the latter, then after solving p = p` + (1 - p`) * e^(-lambda) for p`, we see that the customer must instead substitute p` for the p below, where p` = ( p - e^(-lambda)) / ( 1 - e^(-lambda) ).
Once this has been decided, actually generating the data is pretty straightforward, thanks to the built-in Random Poisson ( lambda ) function.
The code below shows results for each case, assuming lambda = 5 and p = 0.10
names default to here (1);
lambda = 5;
p = 0.1;
nObs = 1e7; // number of observations
// generate a ZIP, under the standard assumptions. 10% of the time, generate a 0. 90% of the time, generate a poisson ( 5 )
sample1 = J ( nObs, 1, if ( randomuniform () < p, 0, randomPoisson ( lambda ) ) );
// generate a ZIP with TOTAL long-run proportion of zeros == 0.10
p2 = (p - exp(-lambda))/(1 - exp( -lambda));
sample2 = J ( nObs, 1, if ( randomuniform () < p2, 0, randomPoisson ( lambda ) ) );
// check proportion of zeros in each sample
propZero1 = mean ( sample1 == 0 );
propZero2 = mean ( sample2 == 0 );
// report results
print(evalinsert("Poportion of zeros in sample from standard ZIP ( 5, 0.10 :(</img> ^propZero1^."));
print(evalinsert("Poportion of zeros in sample from unconventionally-defined ZIP ( 5, 0.10 :(</img> ^propZero2^."));

While this is JSL, either of these can be placed into the formula editor if the user wants to do this in a data table. I've illustrated the first case below.
