Reputation: 101
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
Reputation: 36710
There are two reasons why you get values (close to) zero.
.
x=1:30
y = pdf(PD,x)
stem(x,y) %replaced plot with stem because it is discrete.
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