BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jonathanch
Calcite | Level 5

Hello,

I would like to generate a random sample (= 30 obervations) following a negative binomial distribution with expectation = 3 and a coefficient of dispersion (expectation / variance) = 1.2.

sample data;

do i = 1 to 30;

nb_asif = 3 + RAND ('NEGBINOMIAL', ?,?);

output;

end;

run;

How determine my coefficient of dispersion into data step?

Thanks for help.

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

data sample;

do i = 1 to 30;

nb_asif = 3 + RAND ('NEGBINOMIAL', 0.8333,15);

output;

end;

run;

View solution in original post

5 REPLIES 5
stat_sas
Ammonite | Level 13

data sample;

do i = 1 to 30;

nb_asif = 3 + RAND ('NEGBINOMIAL', 0.8333,15);

output;

end;

run;

jonathanch
Calcite | Level 5

I was wrong! it's variance/expectation to calculate coefficient of dispersion.

With your code it doesn't work, it's not equal to 1.2

data echantillon;

do i=1 to 30;

nb_asif=3+RAND('NEGBINOMIAL',0.8333,15) ;

output;

end;

run;

proc univariate data=echantillon;

var nb_asif;

output out=dispersion std=volatite var=variance mean=moyenne skewness=skewness kurtosis=kurtosis;

run;

data dispersion1;

set dispersion;

DI=variance/moyenne;

run;

stat_sas
Ammonite | Level 13

Yes, as per formulation p was going to be greater than one. After making a correction found p=0.8333 and k=15. If you exclude 3 from your equation then you will get a close approximation as sample size increases.

nb_asif=RAND('NEGBINOMIAL',0.8333,15) ;

jonathanch
Calcite | Level 5

Sorry for my ignorance but I don't understand...:smileyconfused:

How did you make a correction? p=1/1.2?

And I don't manage how you found the dispersion coefficient = 1.2 after generate.

Thanks.

stat_sas
Ammonite | Level 13

Please consult properties of negative binomial distribution to understand this in a better way.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1072 views
  • 3 likes
  • 2 in conversation