BookmarkSubscribeRSS Feed
Peaw
Fluorite | Level 6

I use this following code to fit poisson and negative binomial distribution

but, I am not sure Is it correct??

please let me know.

 

data ec.no;

input y freq;

datalines;

0 3475

1 229

2 28

3 6

5 1

;

proc countreg data=ec.no;

model y = / dist=poisson;

output out=exp_poi prob=prob_poi;

freq freq;

run;

proc print;

id y;

var prob_poi;

run;

proc format;

value yfmt 3-high = "3+";

run;

 

proc means sum nway data=exp_poi;

class y;

var prob_poi;

format y yfmt.;

output out=exp_poi sum=_testp_;

run;

proc freq data=ec.no;

table y / chisq(testp=exp_poi df=-1 lrchisq);

format y yfmt.;

weight freq;

run;

 

/*fit nagative binomial*/

proc countreg data=ec.no;

model y = / dist=negbin;

output out=exp_nb prob=prob_nb;

freq freq;

run;

proc format;

value yfmt

3-high = ">=3";

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=3 then _testp_ = 1 - sumtolast;

run;

proc freq data=ec.no;

table y / chisq(testp=exp_nb df=-2 lrchisq);

format y yfmt.;

weight freq;

run;

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

You can use PROC COUNTREG to fit models to count distributions as the negative binomial or poisson, the documentation and examples are here

 

http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_countreg_sect0...

 

However, I recommend that you use PROC GENMOD, as described with examples here

 

https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#genmod_toc.htm

 

 

Rick_SAS
SAS Super FREQ

I think you are on the right track. I use PROC GENMOD, but the ideas are the same.  You can see a complete worked-out example at 

http://blogs.sas.com/content/iml/2012/04/04/fitting-a-poisson-distribution-to-data-in-sas.html

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 ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1548 views
  • 1 like
  • 3 in conversation