/******************* Category_II_redesign.sas The two-stage procedure is testing H0: p<=p0 vs. p>=p1, where p0=b then the drug is claimed as promisssion and the trial is stopped at the first stage. If a=b|p0,n1)+P(ac|n1,n2,p0). The power is: P(y1>=b|p1,n1)+P(ac|n1,n2,p1). The average sample size is: aven=P(a1-epsilon then p=1-epsilon; if x<0 then y=0; else if x>n then y=1; else do; u=floor(x); y=cdf('binomial',u,p,n); end; return (y); finish cd; start pd(x,p,n) global(epsilon); /****** Compute P(Y=x|n,p), where Y~Bin(n,p). ******/ if p1-epsilon then p=1-epsilon; if x<0 then y=0; else if x>n then y=0; else if x ^= floor(x) then y=0; else y=pdf('binomial',x,p,n); return (y); finish pd; start a_up(p1,n1) global(beta); /*************** Find the largest integer uu such that P(Y1<=uu|p1,n1)<=beta ***************/ flag=0; m=-1; do while((flag=0) & (m< n1+1)); y=cd(m,p1,n1); if y<=beta then m=m+1; else do; flag=1; uu=m-1; end; end; return (uu); finish a_up; start b_low(p0,n1) global(alpha); /*************** Find the smallest integer uu such that P(Y1>=uu|p0,n1)<=alpha ***************/ flag=0; m=n1+1; do while((flag=0) & (m>0)); y=1-cd(m-1,p0,n1); if y<=alpha then m=m-1; else do; flag=1; uu=m+1; end; end; return (uu); finish b_low; start power(a,b,c,n1,n,p); /*********** Compute the power of the given design a,b,c,n1,n) under response rate p: P(Y1>=b|p,n1)+P(ac|p,n1,n) ***********/ y=1-cd(b-1,p,n1); n2=n-n1; do i=a+1 to b-1; y=y+pd(i,p,n1)*(1-cd(c-i,p,n2)); end; return (y); finish power; start search(p0,p1) global(alpha,beta); /************* Find design (a,b,c,n1,n) such that P(Y1>=b|p0,n1)+P(ac|p0,n1,n)<=alpha and P(Y1>=b|p1,n1)+P(ac|p1,n1,n)>=1-beta and minimize the average sample size. The found design is a Type II, optimal design with equal sample sizes. Since we search n from 10 to m, and try to find the satisfactory design with minimum average sample size. Thus, the generated design is a optimal design (minimizing average sample size). ****************/ m=100; ave=100; do n=10 to m while (ave>n/2);/*search for n*/ ll=floor(n/2); if (2*ll=1-beta) & (al<=alpha)) then do; ave=aa; flag=1; ff=0; aaa=i; bbb=j; ccc=cc; nnn1=n1; nnn=n; aal=al; ppw=pw; aave=ave; beta_spt=cd(aaa,p1,nnn1); alpha_spt=1-cd(bbb-1,p0,nnn1); end; else if (pw<1-beta) then cc=n+1; end; end; end; end; end; vv=j(11,1,0); vv[1]=flag; if flag=1 then do; vv[2]=aaa; vv[3]=bbb; vv[4]=ccc; vv[5]=nnn1; vv[6]=nnn; vv[7]=aal; vv[8]=ppw; vv[9]=aave; vv[10]=beta_spt; vv[11]=alpha_spt; end; return (vv); finish search; start print_out(vv); a=vv[2]; b=vv[3]; c=vv[4]; n1=vv[5]; n=vv[6]; al=vv[7]; pw=vv[8]; ave_n=vv[9]; beta_spt=vv[10]; alpha_spt=vv[11]; print a b c n1 n al pw ave_n beta_spt alpha_spt; finish print_out; start aa(beta_spt,n1,n,n1_star,p1,ind)global(beta); /************************* Given the planned sample sizes of n1 and n, the planned beta spent (beta_spt) at the first stage, and the actual sample size of n1_star at the first stage, this subroutine finds the largest integer uu such that P(Y1<=uu | p1,n1_star) is closest to btspt, where btspt is the beta spent at the first stage according to the sample size n1_star. ind=1 means the proposed method. ind=2 means Green's method with fixed spending. ****************************/ if ind=1 then do; n2=n-n1; if n1_star<=n1 then btspt=beta_spt*n1_star/n1; else btspt=beta_spt+(beta-beta_spt)*(n1_star-n1)/n2; end; else if ind=2 then do; btspt=beta_spt; end; m=-1; flag=0; do while ((flag=0) & (m(btspt-z) | (y>beta)) then uu[1]=m-1; else uu[1]=m; uu[2]=btspt; return (uu); finish aa; start bb(alpha_spt,n1,n,n1_star,p0,ind) global(alpha); /************************* Given the planned sample sizes of n1 and n, the planned alpha spent (alpha_spt) at the first stage, and the actual sample size of n1_star at the first stage, this subroutine finds the smallest integer uu such that P(Y1>=uu | p1,n1_star) is closest to alspt, where alspt is the alpha spent at the first stage according to the sample size n1_star. ind=1 means the proposed method. ind=2 means Green's method with fixed spending. ****************************/ if ind=1 then do; n2=n-n1; if n1_star<=n1 then alspt=alpha_spt*n1_star/n1; else alspt=alpha_spt+(alpha-alpha_spt)*(n1_star-n1)/n2; end; else if ind=2 then do; alspt=alpha_spt; end; m=n1_star+1; flag=0; do while ((flag=0) & (m>-1)); y=1-cd(m-1,p0,n1_star); if y<=alspt then m=m-1; else flag=1; end; uu=j(2,1,0); z=1-cd(m,p0,n1_star); if ((y-alspt)>(alspt-z) | (y>alpha)) then uu[1]=m+1; else uu[1]=m; uu[2]=alspt; return (uu); finish bb; start gen(beta_spt,alpha_spt,n1,n,n1_star,n_star,ind) global(alpha,beta,p0,p1); /*************** For the planned design n1, n, beta_spt, and alpha_spt at the first stage, and for the attaned sample sizes n1_star and n_star, this subroutine finds the design according to the actual sample sizes n1_star and n_star using type I and type II error probability spending functions. ind=1 means the proposed method. ind=2 means Green's method with fixed spending. ***************/ uu=aa(beta_spt,n1,n,n1_star,p1,ind); ww=bb(alpha_spt,n1,n,n1_star,p0,ind); a=uu[1]; b=ww[1]; n2_star=n_star-n1_star; flag=0; c=a-1; do while ((flag=0) & (c=b_star|p0,n1_star)+P(a_starc_star|p0,n1_star,n_star)<=alpha and P(Y1>=b_star|p0,n1_star)+P(a_starc_star|p0,n1_star,n_star)>=1-beta and minimizing the average sample size. ****************/ flag=0; ave=100; n1=n1_star; m=100; do n=n1+1 to m;/*search for n*/ n2=n-n1; u=a_up(p1,n1); v=b_low(p0,n1); do i=0 to u;/*search for a*/ do j=v to n1;/*search for b*/ aa=(cd(j-1,p0,n1)-cd(i,p0,n1))*n2+n1; if (aa=1-beta) & (al<=alpha)) then do; ave=aa; ff=1; flag=1; aaa=i; bbb=j; ccc=cc; nnn1=n1; nnn=n; aal=al; ppw=pw; aave=ave; beta_spt=cd(aaa,p1,nnn1); alpha_spt=1-cd(bbb-1,p0,nnn1); end; else if (pw<1-beta) then cc=n+1; end; end; end; end; end; vv=j(11,1,0); vv[1]=flag; if flag=1 then do; vv[2]=aaa; vv[3]=bbb; vv[4]=ccc; vv[5]=nnn1; vv[6]=nnn; vv[7]=aal; vv[8]=ppw; vv[9]=aave; vv[10]=beta_spt; vv[11]=alpha_spt; end; a_star=aaa; b_star=bbb; c_star=ccc; n_star=nnn; pw_star=ppw; al_star=aal; ave_star=aave; print "**********************Modified Design given n1_star**************************"; print a_star b_star c_star n1_star n_star al_star pw_star ave_star; return (vv); finish modify; start c_double_star(p0,p1,a_star,b_star,n1_star,n_star_star) global(alpha,beta); /************* Find c_star_star given a_star, b_star n1_star, and n_star_star such that P(Y1>=b_star|p0,n1_star)+P(a_starc_star_star|p0,n1_star,n_star_star)<=alpha. ****************/ n1=n1_star; n=n_star_star; a=a_star; b=b_star; flag=0; ff=0; cc=a-2; do while ((ff=0) & (cc