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 .

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 4470 views
  • 7 likes
  • 3 in conversation