LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2001, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 24 Jan 2001 15:27:25 -0500
Reply-To:     ahutson@BIOSTAT.UFL.EDU
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Alan Hutson <ahutson@BIOSTAT.UFL.EDU>
Organization: University of Florida, Dept. of Statistics
Subject:      Re: Confidence Intervals For Proportions
Comments: To: John Jones <jonesj@PHARMARESEARCH.COM>
Comments: cc: kamensky@AECOM.YU.EDU
Content-Type: text/plain; charset=us-ascii

I would suggest reading

Agresti, A and Coull, B Approximate is better than "exact" for interval estimation of binomial proportions. Amer. Statist. 52 (1998), no. 2, 119--126.

A simple modification of the approximate interval will provide much more accurate confidence intervals than the "exact" method

Best Alan

John Jones wrote: > > This macro will calculate the exact confidence interval not the normal > approximation. > > jj > > /************************************************************************* > * %CI_Prop(Alpha=, N=, M=, ds=) where, > * > * Alpha = Area outside the confidence region > * N = Denominator; number at risk (variable) > * M = Numerator; number of events (variable) > * ds = Dataset to calculate confidence intervals > * > * Example: %CI_Prop(Alpha=.05, N=N, M=M, ds=ds) > * > * Reference: Handbook of Tables for Probability and > * Statistics, 2nd Edition, pages 219-237 > * William H. Beyer > ******************************************************************************/ > %Macro ci_prop(alpha=, N=, M=,ds=); > > *--{UPPER LIMIT: estimation}--; > data Upper; > retain cntr 0; > set &ds ; > cntr+1; > *--{2 SIDED: confidence interval}--; > cutoff=input(symget('alpha'),8.)/2; > *--{INTERATE: over the parameter space}--; > do ul=0 to 1 by .0001; > if (ul<=1) then alpha=ProbBnml(ul,&N,&M); > *--{ALL: alpha estimates that are less than equal to the limit}--; > if (alpha<=cutoff) then output; > end; > run; > proc sort; by cntr cutoff alpha; run; > > *--{UPPER LIMIT: that closest estimates the cutoff}--; > data Upper; > set Upper; > by cntr cutoff alpha; > if (last.cutoff=1); > drop alpha; > run; > > *--{LOWER LIMIT: estimation}--; > data Lower; > retain cntr 0; > set &ds ; > cntr+1; > *--{2 SIDED: confidence interval}--; > cutoff=input(symget('alpha'),8.)/2; > *--{INTERATE: over the parameter space}--; > do ll=0 to 1 by .0001; > if (ll<=1) then alpha=ProbBnml(ll,&N,&N)-ProbBnml(ll,&N,(&M-1)); > if (alpha<=cutoff) then output; > end; > run; > proc sort; by cntr cutoff alpha; run; > > *--{LOWER LIMIT: that closest estimates the limit}--; > data Lower; > set Lower; > by cntr cutoff alpha; > if (last.cutoff=1); > drop alpha; > run; > > *--{FINAL DATASET: label and confidence interval}--; > data CI_Prop; > merge lower upper; > by cntr cutoff; > length _label_ $6 CI_Prop $14 CI_pct $12; > _label_=trim(left(put(100*(1-&alpha),8.)))||'% CI'; > CI_Prop='('||trim(left(put(ll,8.3)))||', '||trim(left(put(ul,8.3)))||')'; > CI_Pct ='('||trim(left(put(round(100*ll),3.)))||'%, > '||trim(left(put(round(100*ul),3.)))||'%)'; > drop cntr; > label _label_='Description of CI_Prot and CI_Pct' > CI_Prop='Confidence Interval for Proportions' > CI_Pct ='Confidence Interval for Percentages'; > > put '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$>'; > put '$$$'; > put "$$$ Alpha=&alpha., N=&N., M=&M"; > put '$$$'; > put '$$$ ' _label_ '= ' CI_Prop; > put '$$$ ' _label_ '= ' CI_Pct; > put '$$$'; > put '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$>'; > > run; > > *--{CLEANUP:}--; > proc datasets nolist; > delete upper lower /memtype=data; > run; > quit; > > %Mend ci_prop; > > At 03:14 PM 1/24/01 -0500, Victor Kamensky wrote: > >Hi,SAS-L-ers! > >I am looking for the way(s) to calculate > >confidence intervals for proportions, > >(i.e. percents in contingency tables). > >PROC FREQ is most probable place for it, > >but looks like it is not in the documentation > >(did I miss it in ONLINE DOCS and books?). > >(As much as I know, the formula is > > the following:p+(-) 1.96*sqrt(p*(1-p)/n)). > >I think it could be implemented as a macro > >(based on PROC FREQ output data sets). > >Did someone do it already? > >Victor Kamensky > >Programmer > >Albert Einstein College of Medicine


Back to: Top of message | Previous page | Main SAS-L page