Sample Size Calcuations for a case control study with the following inputs

Statistical Power is the probability of finding an effect if its real.

Factors Affecting Power

Size of the effect ( larger the effect size easier it is to detect it, thus leading to larger power, if all other variables are fixed)

Standard Deviaion of the characteristic under study ( larger variance leads to smaller power)

Bigger sample size ( larger sample size leads to larger power)

Desired Significance level ( probability of type 1 error, inverse relationship with power, which is 1-probability of type 2 error)

Based on these elements, we can come up with a mathematical equation, which relates all the above elements. We will use difference in proportions as the effect size in the formula, which can be found at the url

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<-.20 # 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)*(OR-1)+1)
pbar<-(pExposedControl+pExposedCase)/2 # Average proportion exposed
n<-((r+1)/r)*((pbar*(1-pbar))*((ZBeta+ZAlphaHalf)^2))/((pExposedCase-pExposedControl)^2)
n
## [1] 172.48
# therefore total sample size is 2*n, n cases and n control 
N<-round (2*n)
N
## [1] 345

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)*(OR-1)+1)
pbar<-(pExposedControl+pExposedCase)/2 # Average proportion exposed
n<-((r+1)/r)*((pbar*(1-pbar))*((ZBeta+ZAlphaHalf)^2))/((pExposedCase-pExposedControl)^2)

EffectSize<-pExposedCase-pExposedControl
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