Ghazal
Ghazal

Reputation: 101

Fitting a poisson distribution to a set of data in MATLAB

I have the following set of data i'm trying to fit a poisson distribution to on MATLAB but all the outputs i get are zero and I'm pretty much stuck

data = [16  13  23  18  17  7   16  16  18  20 ...] 

there's more but i'm not going to paste all of it. I do the following and the poisson distribution is built successfully:

 PD = fitdist(data,'Poisson');

my problem is here: I have the following set of x, and i'm trying to plot the poisson distribution:

x = [ 0.042 0.048   0.053   0.059   0.065   0.070   0.076   0.082   0.087   0.093   0.099   0.10 ... etc ]

y = pdf(PD,x)
plot(x,y)

The output of y is all zeros and I have no idea why this is happening. Any hints would be amazing.

EDIT:

My plot is supposed to be normalized and then a poisson process should be fit over it, so here's what i've done:

numbins = 20;
[frequecy, xout] = hist(data/norm(data), numbins);
binsize = xout(2)-xout(1);
bar(xout, frequecy/binsize/sum(frequecy));
hold on;
PD = fitdist(data,'Poisson');
stem(xout, pdf(PD,xout), 'r');
hold off;

if i change stem(xout,pdf) to the new x, then the plots won't overlap which is what I need to do.

Upvotes: 1

Views: 2305

Answers (1)

Daniel
Daniel

Reputation: 36710

There are two reasons why you get values (close to) zero.

  • First of all the Poisson distribution is a discrete probability distribution, meaning the PDF is zero for all nonzero-values.
  • Further your sample has values between 7 and 20. You are asking for the probability for something below 0.1 to happen. Regardless of the discrete distribution you choose, you are asking for values far outside your sample range.

.

x=1:30
y = pdf(PD,x)
stem(x,y) %replaced plot with stem because it is discrete.

enter image description here

Here is how I would modify your code:

numbins = 20;
%Bin integers. You know your distribution only contains integers
%Hist with original scaling
[frequecy, xout2] = hist(data, min(data):max(data));
%scale later
xout=xout2/norm(data);
binsize = xout(2)-xout(1);
bar(xout, frequecy/binsize/sum(frequecy));
hold on;
PD = fitdist(data,'Poisson');
%sample your distribution using the unscaled x-values but plot scaled.
%multiply with numel(data) to get expected value instead of probability
stem(xout, pdf(PD,xout2)*numel(data), 'r');
hold off;

Upvotes: 2

Related Questions