for different prevlance rates
ZBeta<0.84 # Assuming 80% power
ZAlphaHalf<1.96 #Assuming Signifcance Level Alpha =0.05
r<1 # Assuming equal number of cases and controls ( r is the ratio of control to cases)
pExposedControl<c(.20, .30,0.50,0.60,0.70) # 20% exposed in control group, say
OR<2.0 # you want ot detect an odds ratio of 2.0 or more
# To get proportion of cases exposed
pExposedCase<(OR*pExposedControl)/((pExposedControl)*(OR1)+1)
pbar<(pExposedControl+pExposedCase)/2 # Average proportion exposed
n<((r+1)/r)*((pbar*(1pbar))*((ZBeta+ZAlphaHalf)^2))/((pExposedCasepExposedControl)^2)
EffectSize<pExposedCasepExposedControl
round(n)
## [1] 172 142 137 153 186
# therefore total sample size is N= 2*n, n cases and n control
N<round (2*n)
N
## [1] 345 283 274 306 373
SampleSizes<rbind(round(pExposedControl,2),round(pExposedCase,2),round(EffectSize,2),N)
library(knitr)
library("kableExtra")
kable(SampleSizes, caption="Sample Sizes for Various Scenarios")
Sample Sizes for Various Scenarios

0.20

0.30

0.50

0.60

0.70


0.33

0.46

0.67

0.75

0.82


0.13

0.16

0.17

0.15

0.12

N

345.00

283.00

274.00

306.00

373.00
