Calcite | Level 5

## Poisson Distribution

Hi, I am not sure how to get started on this question:

1. Generate 2000 samples of size 40000 random numbers from a Poisson distribution with lambda = 8. For each of these 2000 samples calculate the mean.

so far I have

data poisson;
call streaminit (0);
psamples = 2000;
psizesamp = 40000;
lambda = 8;
do psample = 1 to psamples;

do n2 = 1 to psizesamp;

end;

end;

I understand that I will need to use a nested loop, but I do not know how to set up poisson distribution. I imagine it is somewhat similar to uniform distribution. Anyone know how I would do that or any resources to look at! Thank you

2 REPLIES 2
Opal | Level 21

## Re: Poisson Distribution

Get a random Poisson value with:

x = rand("Poisson", lambda);

PG
Rhodochrosite | Level 12

## Re: Poisson Distribution

As indicated by @PGStats  try the following:

``````data poisson;
call streaminit (0);
retain sumy meantotal;
psamples = 20; *2000;
psizesamp = 40000;
lambda = 8;
do psample = 1 to psamples;
sumy = 0;
do n2 = 0 to psizesamp;
y = rand("Poisson", lambda);
sumy + y;
end;
mean = sumy / psizesamp;
meantotal + mean;
*output;
end;
mom = meantotal / psamples;
put 'Mean of the Means ' mom;
run;``````

See the commented statements for lesser / no output. A better way is to keep out the initial values as macro variables for not to load them into PDV as:

%let lambda = 8;
%let psamples = 2000;
%let psizesamp = 40000;

and inserting them into the code.

Discussion stats
• 2 replies
• 511 views
• 0 likes
• 3 in conversation