Compound Poisson Distribution Model

Illustration
Yasmin Tamimi - 2022-06-11T13:25:23+00:00
Question: Compound Poisson Distribution Model

Hey Everyone,   I have the probability density function of a Negative-binomial Distribution (Compound Poisson Distribution) and I would like to generate random numbers based on probability similar to how binornd function works. The following is the compound model written in matlab:   fun = @(lambda) (lambda.^k).*(exp(-1.*lambda)).* gampdf(lambda,alpha,beta)./factorial(k);   P(k)= integral(fun,0,Inf);   I assume the number of trials (k) from 0:7 and the output is the probability of each point P(k). So now I only need to choose random numbers from this distribution based on their probability values.

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

f I understand your question correctly. I guess once you get P, then you would like to choose its elements randomly, right? If so, you can use the following code:

 

alpha = 1; beta = 1; % replace by your desired values
for k = 0:7
    fun = @(lambda) (lambda.^k).*(exp(-1.*lambda)).* gampdf(lambda,alpha,beta)./factorial(k);
    P(k+1) = integral(fun,0,Inf);
end
out = datasample(P,1) % 1 observation, replace 1 by higher value for more observations

This will be uniformly random. If you are interested then you may use:

out = P(randperm(numel(P),1))

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!