1 R - confidence intervals for risk ratio, odds ratio, attributable risk (resp. absolute risk reduction), cond. MLE odds ratio

• generate the data, and table them

obese <- sample(c(T,F),size=1000,replace=T)
mi <- factor((obese + sample(c(-1,0,1),prob = c(0.3,0.35,0.35),size=1000,replace=T)) > 0,labels=c("myocardinfarct","non"))
obese <- factor(obese,labels=c("obese","non-obese"))

table(obese,mi)


mi
obese       myocardinfarct non
obese                326 187
non-obese            144 343


• use the twoby2 function to get the ratios incl. the confidence intervals
• the risk difference (resp. attributable risk (AR), absolute risk reduction (ARR)) is also calculated

require(Epi)
twoby2(obese,mi)


2 by 2 table analysis:
------------------------------------------------------
Outcome   : myocardinfarct
Comparing : obese vs. non-obese

myocardinfarct non    P(myocardinfarct) 95% conf. interval
obese                326 187               0.6355    0.5929   0.6760
non-obese            144 343               0.2957    0.2568   0.3378

95% conf. interval
Relative Risk: 2.1491    1.8462   2.5018
Sample Odds Ratio: 4.1525    3.1859   5.4122
Conditional MLE Odds Ratio: 4.1462    3.1584   5.4617
Probability difference: 0.3398    0.2800   0.3959

Exact P-value: 0
Asymptotic P-value: 0
------------------------------------------------------


• so we got a risk of myocard. infarction of 0.6507 for obese and 0.3006 for non-obese
• dividing the first by the second (0.6507/0.3006) gives the risk ratio
• the odds are not given for the groups, calculated by hand it would be

(326/187)/(144/343)


[1] 4.152481


• which you see in the output of twoby2() (in addition you find the conditional MLE odds)
• the probability difference (as stated above also known as attributable risk (AR) and absolute risk reduction (ARR)) is simply the difference between the two risks
confidence-intervals-for-odds-ratio paired case