********************************************************************************************************************** mid-P test for single sample proportion Developed by Minn M. Soe, MBBS,MPH, Health Scientist, DHQP, CDC Updated June 2015 Input values: x=numerator, n=denominator, p=hypothesized/nomimal proportion (range= 0-1) Output values: Calculate p-value (one-sided and two-sided) for testing the null hypothesis of observed propportion similar to a known proportion Calculate 95%CI of single proportion. Reference: 1. Bernard Rosner. Fundamentals of biostatistics,5th edition. Pacific Grove, CA, 2000 (page 251-3). Validation: for mid-P test: WINPEPI: http://www.brixtonhealth.com/pepi4windows.html http://www.quantitativeskills.com/sisa/distributions/binomial.htm **********************************************************************************************************************; options mprint mlogic symbolgen; ***************************************One sample test with 2-sided p-value****************************************; %macro oneSAMPLE_Prop(p=,n=,x=); if &n>=&x and &n ne . and int(&n)=&n and &x ne . and int(&x)=&x then do; prop=&x/&n; *------------------------------------------------ 2 sided mid P-----------------------------------------------------; If 0<=&p<=1 then do; if prop=0 then twosided_midP=probbnml(&p,&n,&x); else if 0=&x1 and k<=&x2) then s=s+v ; if(tot>10**30) then do; s=s/10**30; tot=tot/10**30; v=v/10**30; end; k=k+1; v=v*q*(&n+1-k)/k; end; binP=s/tot; %mend; %macro BinP2(x1=,x2=); q=p2/(1-p2); k=0; v = 1; s=0; tot=0; do while(k<=&n) ; tot=tot+v; if(k>=&x1 and k<=&x2) then s=s+v ; if(tot>10**30) then do; s=s/10**30; tot=tot/10**30; v=v/10**30; end; k=k+1; v=v*q*(&n+1-k)/k; end; binP2=(s/tot)*0.5; %mend; vP=&x/&n; if (&x=0) then LL = .; *<--------new update; else do; p2=vP/2; vsL=0; vsH=vP; p=2.5/100; do while((vsH-vsL)>10**-5); %BinP(x1=&x+1, x2=&n); %BinP2(x1=&x, x2=&x); if (BinP+BinP2) >p then do; vsH=p2; p2=(vsL+p2)/2 ;end; else do; vsL=p2; p2=(vsH+p2)/2 ;end; end; LL = p2; end; if (&x=&n) then UL = 1; else do; p2=(1+vP)/2; vsL=vP; vsH=1; p=2.5/100; do while((vsH-vsL)>10**-5); %BinP(x1=0, x2=&x-1); %BinP2(x1=&x, x2=&x); if (BinP+BinP2)