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

I am using base sas 9.4. Now I am working on Simulating data.

After I fitted data to negative binomial distribution using the following code ;

 

proc countreg data=claim;
         model y = / dist=negbin;
         output out=exp_nb prob=prob_nb;
         freq freq;
         run;

     proc format;
         value yfmt     
           7-high = ">=7";
         run;
      
      proc means sum nway data=exp_nb;
         class y;
         var prob_nb;
         format y yfmt.;
         output out=exp_nb sum=_testp_;
         run;

      data exp_nb;
         set exp_nb;
         sumexp + _testp_;
         sumtolast = lag(sumexp);
         if y=7 then _testp_ = 1 - sumtolast;
         run;

      proc freq data=claims;
         table y / chisq(testp=exp_nb df=-2 lrchisq);
         format y yfmt.;
         weight freq;
         run;

 

Then I got only p-value from fitting this data.

Now I want to simulate data from negative binomial distribution.

How can I do that ? please help

(version of sas program do not have Proc iml procedure)

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

You can simulate data from a negative binomial distribution using the RAND function like this

 

data negbin;
	do x = 1 to 1000;
		y = rand('negbinomial', 0.5, 2);
		output;
	end;
run;

title 'Plot the Simulated Data';
proc sgplot data = negbin;
	histogram y;
run;
title;

Adjust p and k to your liking. The documentation is here

 

 

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001466748.htm

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

You can simulate data from a negative binomial distribution using the RAND function like this

 

data negbin;
	do x = 1 to 1000;
		y = rand('negbinomial', 0.5, 2);
		output;
	end;
run;

title 'Plot the Simulated Data';
proc sgplot data = negbin;
	histogram y;
run;
title;

Adjust p and k to your liking. The documentation is here

 

 

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001466748.htm

Peaw
Fluorite | Level 6

could you please tell me that how can I know p of this data from fitting the distribution.

because when I fitted this distribution I fitted from raw data of frequency of claim of each auto policy. That's why I do not know P of this data.

Peaw
Fluorite | Level 6

I am sorry to bother you. But after following your suggestion I got the attached output.

How can I know this model fits the data or not.

 


Capture.JPG
Ksharp
Super User
 It looks good.  
Value/DF is near  1 .

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 5771 views
  • 7 likes
  • 3 in conversation