import statsmodels.api as sm
class binarybinaryrct :
def __init__(self, NT, NU, NYT, NYU):
self.NT=NT
self.NU=NU
self.NYT=NYT
self.NYU=NYU
def ATE(self):
return (self.NYT/self.NT - self.NYU/self.NU)
def table(self):
return("| | Infection Rate per 1000|\n"+
"|---|---|\n"
f"|Treated| {self.NYT/self.NT*1000:.2}|\n" +
f"|Control| {self.NYU/self.NU*1000:.2}|\n" +
f"|Difference| {self.ATE()*1000:.2}|\n")
def VE(self):
tb = sm.stats.Table2x2([[self.NYT, self.NT - self.NYT], [self.NYU, self.NU - self.NYU]])
ve=1-tb.riskratio
ci = tb.riskratio_confint()
ci = [1-ci[1],1-ci[0]]
return(ve,ci)
pfizerall = binarybinaryrct(19965, 20172, 9, 169)
pfizer65 = binarybinaryrct(4044, 4067, 1, 19)
print("\n- All\n\n" + pfizerall.table() + "\n - 65+\n\n" + pfizer65.table())
- All
| | Infection Rate per 1000|
|---|---|
|Treated| 0.45|
|Control| 8.4|
|Difference| -7.9|
- 65+
| | Infection Rate per 1000|
|---|---|
|Treated| 0.25|
|Control| 4.7|
|Difference| -4.4|