0

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

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.

blowbuh
  • 37
  • 6
  • Is the rate changing at all? I see you're calculating the probability of a number of events with rate and multiplying it with another similar probability. What I don't understand is why the rates (values in `A` and `B`) are themselves changing. This may be contradicting the assumptions of the [Poisson distribution](https://en.wikipedia.org/wiki/Poisson_distribution). I think this is answerable though, with a little more context. – SecretAgentMan Nov 20 '19 at 13:16
  • Reposted as: [How to calculate a Poisson-Matrix in Matlab analogous to Excel or R and sum up certain parts?](https://stackoverflow.com/q/58998743/8239061) – SecretAgentMan Nov 23 '19 at 04:01

1 Answers1

0

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.

rvimieiro
  • 1,043
  • 1
  • 10
  • 17
  • Thank you for your help. I probably haven't expressed myself properly. I've edited the original question to show what I have done in Excel. The Poisson Matrix above should be created fore each record of A and B (following your example zA and zB are increasing from 0:20). – blowbuh Nov 19 '19 at 16:52
  • I've changed the lines where it performs the calculation. Now it is using the function repmat. Let me know if it is what you were expecting. – rvimieiro Nov 19 '19 at 18:18
  • when I try it this way Matlab tells me the following: Error using poisspdf (line 29) Requires non-scalar arguments to match in size. – blowbuh Nov 19 '19 at 19:56
  • This [answer](https://stackoverflow.com/a/44763756/8682939) might help you. You may have to change your input to single or double. – rvimieiro Nov 19 '19 at 20:02
  • My version is 2019b, so it should actually work? I’ve checked the linked answer but all my variables are already data type ‚double‘ – blowbuh Nov 20 '19 at 08:05
  • Why generate Poisson random variates? – SecretAgentMan Nov 22 '19 at 22:58