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?
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.
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;
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].
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.