# Sample size calculation for test size alph, power pow, odds # ratio odd, and probability of success at xbar P. If size # or power are input as percentages, they are converted to # proportions lregss=function(alph,pow,odd,P){ if(alph>1) alph=alph/100 if(pow>1) pow=pow/100 tauhat=log(odd) za=qnorm(1-alph) zb=qnorm(pow) n1=(za+zb*exp(-tauhat^2/4))^2/(P*tauhat^2) delt=(1+(1+tauhat^2)*exp(5*tauhat^2/4))/(1+exp(-tauhat^2/4)) n2=n1*(1+2*P*delt) out=list("Odds Ratio"=odd,"P"=P,"Sample Size"=n2) out }