How to calculate with the Poisson-Distribution in Matlab?

狂风中的少年 提交于 2020-01-05 06:57:04

问题


I’ve used Excel in the past but the calculations including the Poisson-Distribution took a while, that’s why I switched to SQL. Soon I’ve recognized that SQL might not be a proper solution to deal with statistical issues. Finally I’ve decided to switch to Matlab but I’m not used to it at all, my problem Is the following:

I’ve imported a .csv-table and have two columns with values, let’s say A and B (110 x 1 double) These values both are the input values for my Poisson-calculations. Since I wanna calculate for at least the first 20 events, I’ve created a variable z=1:20.

When I now calculated let’s say New = Poisspdf(z,A), it says something like non-scalar arguments must match in size. Z only has 20 records but A and l both have 110 records. So I’ve expanded Z= 1:110 and transposed it: Znew = Z.

When I now try to execute the actual calculation:

Results = Poisspdf(Znew,A).*Poisspdf(Znew,B)

I always get only a 100x1 Vector but what I want is a matrix that is 20x20 for each record of A and B (based on my actual choice of z=1:20, I only changed to z=1:110 because Matlab told that they need to match in size). So in this 20x20 Matrix there should always be in each cell the result of a slightly different calculation (Poisspdf(Znew,A).*Poisspdf(Znew,B)). For example in the first cell (1,1) I want to have the result of Poisspdf(0,value of A).*Poisspdf(0,value of B), in cell(1,2): Poisspdf(0,value of A).*Poisspdf(1,value of B), in cell(2,1): Poisspdf(1,value of A).*Poisspdf(0,value of B), and so on...assuming that it’s in the Format cell(row, column)

Finally I want to sum up certain parts of each 20x20 matrix and show the result of the summed up parts in new columns.

Is there anybody able to help? Many thanks!

EDIT:

Poisson Matrix in Excel

In Excel there is Poisson-function: POISSON(x, μ, FALSE) = probability density function value f(x) at the value x for the Poisson distribution with mean μ.

In e.g. cell AD313 in the table above there is the following calculation:

=POISSON(0;first value of A;FALSE)*POISSON(0;first value of B;FALSE)

, in cell AD314 =POISSON(1;first value of A;FALSE)*POISSON(0;first value of B;FALSE)

, in cell AE313

=POISSON(0;first value of A;FALSE)*POISSON(1;first value of B;FALSE)

, and so on.


回答1:


I am not sure if I completely understand your question. I wrote this code that might help you:

clear; clc

% These are the lambdas parameters for the Poisson distribution
lambdaA = 100;
lambdaB = 200;

% Generating Poisson data here
A = poissrnd(lambdaA,110,1);
B = poissrnd(lambdaB,110,1);

% Get the first 20 samples
zA = A(1:20);
zB = B(1:20);

% Perform the calculation
results = repmat(poisspdf(zA,lambdaA),1,20) .* repmat(poisspdf(zB,lambdaB)',20,1);

% Sum
sumFinal = sum(results,2);

Let me know if this is what you were trying to do.



来源:https://stackoverflow.com/questions/58932515/how-to-calculate-with-the-poisson-distribution-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!