将泊松分布拟合到MATLAB中的一组数据

时间:2016-02-22 23:57:59

标签: matlab poisson

我有以下数据集我试图在MATLAB上拟合泊松分布,但我得到的所有输出都是零,我几乎被卡住

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

还有更多,但我不会粘贴所有内容。我执行以下操作并成功构建了泊松分布:

 PD = fitdist(data,'Poisson');

我的问题在于:我有以下一组x,我试图绘制泊松分布:

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)

y的输出全为零,我不知道为什么会发生这种情况。任何提示都会令人惊讶。

编辑:

我的情节应该被标准化,然后泊松过程应该适合它,所以这就是我所做的:

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;

如果我将词干(xout,pdf)更改为新的x,则图表不会重叠,这是我需要做的。

1 个答案:

答案 0 :(得分:2)

有两个原因可以获得值(接近)零。

  • 首先,泊松分布为discrete probability distribution,意味着所有非零值的PDF均为零。
  • 此外,您的样本的值介于7和20之间。您要求的概率低于0.1。无论您选择哪种离散分布,您都会要求远远超出样本范围的值。

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

enter image description here

以下是我修改代码的方法:

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;
相关问题