[prev in list] [next in list] [prev in thread] [next in thread]
List: sas-l
Subject: Re: Exact binomial confidence limits
From: vanbuski () ECLIPSE ! NET
Date: 2000-09-29 13:04:12
[Download RAW message or body]
This also works.
Mark Van Buskirk
** APPLY EXACT BINOMIAL 95% CONFIDENCE INTERVAL
**;
* NOTE: INCOMING DATASET HAS VARIABLES X,N;
DATA ALL;
INPUT X N @@;
CARDS;
25 74 32 76
;
DATA ALL;
SET ALL;
ALPHA=0.05;
C_LO=0.5*ALPHA;
C_HI=1-C_LO;
PCT=100*X/N;
**.. 2-SIDED EXACT BINOMIAL 95% CONFIDENCE INTERVAL;
D_HI=N-X;
D_LO=D_HI+1;
LO=100*(1/(1+D_LO/(X*FINV(C_LO,X+X,D_LO+D_LO))));
HI=100*(1/(1+D_HI/((X+1)*FINV(C_HI,X+X+2,D_HI+D_HI))));
**.. 1-SIDED C.I. IF PCT IS 0 OR 100;
IF PCT=0 THEN
DO;
LO=0;
HI=100*(1/(1+D_HI/((X+1)*FINV(1-ALPHA,X+X+2,D_HI+D_HI))));
FLAG=1;
END;
IF PCT=100 THEN
DO;
LO=100*(1/(1+D_LO/(X*FINV(ALPHA,X+X,D_LO+D_LO))));
HI=100;
FLAG=1;
END;
DROP D_HI D_LO ALPHA C_LO C_HI FLAG;
FORMAT LO HI 5.1;
PROC PRINT DATA=ALL; RUN;
Tim CHURCHES <TCHUR@DOH.HEALTH.NSW.GOV.AU> wrote in message
news:s9d0b23d.078@doh.health.nsw.gov.au...
> Dr John Whittington writes:
> > However, given that such an approach is at best an approximation, and
> will
> > only be a reasonable approximation over a certain limited range of
> values
> > of p, it would make much more sense to me to actually utilise an
> algorithm
> > which is calculates 'exact' CIs for any value of p. This can be
> achieved
> > very easily in SAS, and if anyone is interested, I'll post the macro I
> > routinely use to do this.
>
> Herewith my take on this. I wrote this code a long time ago and looking at
it
> now makes me realise how SAS macros are no substitute for proper
> user-defined functions. Still, it does work.
>
> Tim Churches
> Sydney, Australia
>
> %macro BINCL(NUMVAR,DENVAR,CLEVEL,RATEVAR,LRATEVAR,URATEVAR) ;
> %* Macro BINCL written by Tim Churches in an idle moment at New England
Region
> Public Health Unit, Tamworth, New South Wales, Australia. 1 June,
1992. ;
> %* BINCL calculates exact confidence limits for a proportion using the
> inverse of the F distribution. See Armitage P and Berry G, Statistical
> Methods in Medical Research, 2nd Ed. p119. Blackwell Scientific
Publications,
> Oxford, 1987. ;
> %* NUMVAR is the name of the variable which contains the numerator of the
> proportion. ;
> %* DENVAR is the name of the variable which contains the denominator of
the
> proportion. ;
> %* CLEVEL is the confidence level as a percentage ie to get 95% CIs,
> use 95. ;
> %* RATEVAR is the name of the variable to which you want the rate
(proportion)
> to be assigned. ;
> %* LRATEVAR and URATEVAR are the names of the variables to which you want
the
> lower and upper limits of the rate (proportion) assigned. ;
> drop onesidep ;
> onesidep = (100 - &clevel)/200 ;
> &ratevar = &numvar / &denvar ;
> &lratevar = &numvar /
> (&numvar + (&denvar - &numvar +
1)*finv((1-onesidep),(2*&denvar - 2*&numvar + 2),(2*&numvar))) ;
> &uratevar = (&numvar + 1) /
> (&numvar + 1 + (&denvar -
&numvar)/finv((1-onesidep),(2*&numvar + 2),(2*&denvar - 2*&numvar))) ;
> %mend BINCL ;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic