Programming the statistical procedures from SAS

poisson and negative binomial distribution

Reply
Occasional Contributor
Posts: 11

poisson and negative binomial distribution

[ Edited ]

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;

PROC Star
Posts: 633

Re: poisson and negative binomial distribution

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

 

 

SAS Super FREQ
Posts: 3,538

Re: poisson and negative binomial distribution

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

Ask a Question
Discussion stats
  • 2 replies
  • 148 views
  • 1 like
  • 3 in conversation