/* Purpose: This program provides the conditional distribution of Z1|T for a 2-stage analog of Fisher's Exact Test. The interim analysis requires that X1/n11 > X0/n01. The definitions of the variables are provided in the Tech Report by Sill and Rubinstein. To reiterate: n01 = Control Sample Size in Stage 1 n02 = Control Sample Size in Stage 2 n11 = Experimental Sample Size in Stage 1 n12 = Experimental Sample Size in Stage 2 X0 = Number of responses in the control arm in stage 1 X1 = Number of responses in the experimental arm in stage 1 Y0 = Number of responses in the control arm in stage 2 Y1 = Number of responses in the experimental arm in stage 2 Z1 = X1 + Y1 Z0 = X0 + Y0 T = Z1 + Z0 Pz1 = P(Z1=z1|T=t) Cz1 = P(Z1<=z1|T=t) Sz1 = P(Z1>=z1|T=t) theta1 = ln (P1/(1-P1) theta0 = ln(P0/(1-P0)) Delta = theta1 - theta0 */ %let n01=27; %let n11=25; %let n02=23; %let n12=24; %let t=31; %let Delta=0; *****************************************************************************************; *****************************************************************************************; *****************************************************************************************; *****************************************************************************************; data stat; retain z1 Pz1 cN 0; Delta=Δ n01=&n01; n02=&n02; n11=&n11; n12=&n12; t=&t; do z1=max(1,t-(n01-1+n02),int((t-n02+1)/2+0.5)) to min(n11+n12,t); sm=0; do x0i=max(0,t-z1-n02) to min(t-z1,n01-1); a0i=int(x0i*n11/n01+1); sx1=0; do x1i=max(a0i,z1-n12) to min(n11, z1); sx1+comb(n11,x1i)*comb(n12,z1-x1i); put z1 x0i x1i sx1; end; sm=sm+sx1*comb(n01,x0i)*comb(n02,t-z1-x0i); *put sm; end; cN+exp(z1*Delta)*sm; end; ************************************************************; do z1=max(1,t-(n01-1+n02),int((t-n02+1)/2+0.5)) to min(n11+n12,t); sm=0; do x0i=max(0,t-z1-n02) to min(t-z1,n01-1); a0i=int(x0i*n11/n01+1); sx1=0; do x1i=max(a0i,z1-n12) to min(n11, z1); sx1+comb(n11,x1i)*comb(n12,z1-x1i); end; sm=sm+sx1*comb(n01,x0i)*comb(n02,t-z1-x0i); end; Pz1=exp(z1*Delta)*sm/cN; Cz1+Pz1; Sz1=1-Cz1+Pz1; output; end; run; data stat2 ; set stat; label Pz1 = 'P(Z1=z1|T=t)' Cz1 = 'F(z1|T=t)' Sz1 = 'S(z1|T=t)'; run; proc print data=stat2 split='*' noobs; title "Conditional Distribution of Z1 when X1>=[a0] and T=&t"; var z1 Pz1 Cz1 Sz1; run;