#Biostatistics 130 #POWER & SAMPLE SIZE CALCULATIONS #FOR ONE SAMPLE #ESTIMATING SAMPLE SIZE FOR CI #ZAR EXAMPLE 7.3 ZAR=read.table("ZarEX7.3.txt") ZAR attach(ZAR) X=wtchg s=sqrt(var(X)) #sample variance #SET THE FOLLOWING VALUES AS DESIRED: d=0.25 N0=40 alpha=0.05 #ITERATE THE FOLLOWING UNTIL N IS STABILIZED: N1=(s^2*(qt(alpha/2,N0-1))^2)/d^2 N1 N2=(s^2*(qt(alpha/2,N1-1))^2)/d^2 N2 N3=(s^2*(qt(alpha/2,N2-1))^2)/d^2 N3 N4=(s^2*(qt(alpha/2,N3-1))^2)/d^2 N4 N5=(s^2*(qt(alpha/2,N4-1))^2)/d^2 N5 #ESTIMATING SAMPLE SIZE FOR ONE SAMPLE T-TEST #ZAR EXAMPLE 7.2 ZAR=read.table("ZarEX7.2.txt") ZAR attach(ZAR) X=RATwtchg s=sqrt(var(X)) #SET THE FOLLOWING VALUES AS DESIRED: delta=1.0 alpha=0.05 beta=0.10 N0=20 #ITERATE THE FOLLOWING UNTIL N IS STABILIZED: N1=(s^2/delta^2)*(qt(alpha/2,N0-1)+qt(beta,N0-1))^2 N1 N2=(s^2/delta^2)*(qt(alpha/2,N1-1)+qt(beta,N1-1))^2 N2 N3=(s^2/delta^2)*(qt(alpha/2,N2-1)+qt(beta,N2-1))^2 N3 N4=(s^2/delta^2)*(qt(alpha/2,N3-1)+qt(beta,N3-1))^2 N4 N5=(s^2/delta^2)*(qt(alpha/2,N4-1)+qt(beta,N4-1))^2 N5 #ESTIMATING DETECTABLE DIFFERENCE GIVEN N #FOR ONE SAMPLE t-TEST #SET THE FOLLOWING VALUES AS DESIRED: N=25 alpha=0.05 beta=0.10 delta=sqrt(s^2/N)*(qt(alpha/2,N-1)+qt(beta,N-1)) delta #ESTIMATING POWER OF ONE SAMPLE t-TEST #SET THE FOLLOWING VALUES AS DESIRED: N=12 delta=1.0 alpha=0.05 B=(delta/sqrt(s^2/N))-abs(qt(alpha/2,N-1)) B POWER=pt(B,N-1) POWER POWERN=pnorm(B,0,1) POWERN