BookmarkSubscribeRSS Feed
vdfdd
Fluorite | Level 6

Please, I want to simulate a dataset with 4 blocks and 4 treatments and counts following a Poisson and negative binomial distribution. Is it possible is SAS?

6 REPLIES 6
PGStats
Opal | Level 21

Sure,

 

function RAND generates pseudo random numbers from many distributions

 

Pois = rand("Poisson", m); /* Generates a Poisson variate */

NegBin = rand("NegBinomial", p, k); /* Genarates a negative binomial variate */

 

Check the documentation for the precise parameterisation.

PG
vdfdd
Fluorite | Level 6
Thank you for your response.
Rick_SAS
SAS Super FREQ

Here is an example. Your model will determine the definitions of mu, r, and p. I just invented a few values to demonstrate the basic idea.

 

data SimBlock;
call streaminit(123);
do Block = 1 to 4;
   do Treatment = 1 to 4;
      /* invent a formula for the expected count */
      mu = ( Block + (Treatment-2.5)**2 );
      PoisCount = rand("Poisson", mu);
      /* invent a probability and number of trials */
      r = mu / 8; /* prob of success */
      k = 1;        /* number of successes */
      NBCount = rand("NegBin", r, k); /* number of failures before k successes */
      output;
   end;
end;
drop mu k r;
run;

proc means data=SimBlock;
run;

vdfdd
Fluorite | Level 6
Thank you for your response. Please I have 2 questions:
1. In defining the mu (mu = ( Block + (Treatment-2.5)**2 )), you added 2.5. Why?
2. You defined r = mu / 8; Why the value 8?
Rick_SAS
SAS Super FREQ

No reason. I just invented some numbers because you did not provide any information about the design of the simulation. The number 2.5 represents the average treatment effect. I used 8 to make sure r is a probability in [0, 1].

vdfdd
Fluorite | Level 6

Thank you for your prompt response. Here is the description of the experiment :
i. block - 4
ii. treatments = 4
iii. repetition = 8
iv. counts = containing some zeros

 

Question: Simulate the count as coming from 
i. a NegBin distribution
ii. a Poisson distribution

 

Thank you, again, in anticipation.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2014 views
  • 2 likes
  • 3 in conversation