-1

So I have a table of values

v=0 1 2 3 4 5 6 7 8 9
#times obs.: 5 19 23 21 14 12 3 2 1 0

I am supposed to calculate chi squared assuming the data fits a poisson dist. with mean u=3. I have to group values >=6 all in one bin.

I am unsure of how to plot the poisson dist., and most of all how to control what goes into what bin, if that makes sense.

I have plotted a histogram using histc before..but it was with random numbers that I normalized. The amount in each bin was set for me. I am super new...sorry if this question sucks.

4

1 回答 1

0

您用于bar在 matlab 中绘制条形图。

所以这就是你要做的:

v=0:9;
f=[5 19 23 21 14 12 3 2 1 0];
fc=f(find(v<6));      % copy elements where v<=6 into a new array
fc(end+1)=sum(f(v=>6)); % append the sum of elements where v=>6 to that array
figure
bar(v(v<=6), fc);

这应该够了吧...

现在您实际上并没有询问卡方计算。我敦促您不要将 v>6 的值全部放入一个 bin 进行计算,因为它会给您带来非常糟糕的结果。

还有另一种技巧:如果你使用这个hist函数,你可以选择垃圾箱——Matlab 会自动将超出限制的东西放入最后一个垃圾箱。因此,如果您的观察结果在数组Obs中,您可以执行以下操作:

h = hist(Obs, 0:6);
figure
bar(0:6, h)

优点是您可以使用数组h(频率)进行其他计算。

如果你这样做

hist(Obs, 0:6)

Matlab 将在单个语句中为您绘制图形(但您没有值...)

于 2013-02-17T01:03:32.107 回答