# Contour plot for sample size for test size of .05 and 80% power p=c(seq(.01,.10,by=.01),seq(.12,.20,by=.02),seq(.25,.50,by=.05)) tauhat=log(c(seq(1.1,2.0,by=.1),2.5,3.0)) za=qnorm(.95) zb=qnorm(.80) np=length(p) nt=length(tauhat) onep=rep(1,np) onet=rep(1,nt) p.m=p%*%t(onet) t.m=onep%*%t(tauhat) n1=(za+zb*exp(-t.m^2/4))^2/(p.m*t.m^2) delt=(1+(1+t.m^2)*exp(5*t.m^2/4))/(1+exp(-t.m^2/4)) n2=n1*(1+2*p.m*delt) n2=as.table(n2) dimnames(n2)[[1]]=p dimnames(n2)[[2]]=round(tauhat,2) contour(p,tauhat,n2,ylab="Odds for one sd increase in X",xlab="P(Y=1) at mean of X",levels=c(100,200,300,500,750,1000,2000,3000,4000,6000,10000)) title("Sample Size for 80% power (test size .05)")