File Exchange

image thumbnail


version 1.3 (3.48 KB) by

Compute odds and risk ratio on 2x2 matrix



View License

This function calculates the Risk Ratio and the Odds Ratio (OR) on a 2x2 input matrix. Both ratios are computed with confidence intervals. If confidence interval of OR doesn't encompass the value OR=1, then the function computes the Bayesian Credibility Assessment of the test. If the test is credible, the function calculates the Association Parameter Phi. The association parameter Phi=sqrt(chisquare/N). The routine coumputes the Power and, if necessary, the sample sizes needed to achieve a power=0.80 using a modified asymptotic normal method with continuity correction as described by Hardeo Sahai and Anwer Khurshid in Statistics in Medicine, 1996, Vol. 15, Issue 1: 1-21.

You can visit my profile on LinkedIN

Comments and Ratings (4)

Bruce Raine

Hi Giuseppe,

Thanks for your answer.

I do admit I messed up the arithmetic bit of my example and should have said:
so RR = (17/1707)/(7/1786) but my numeric answer was correct to 4d.p. I had 1779 instead of 1707.

But from the WIKI def of Risk Ratio (RR):

RR = [a/(a+b)]/[c/(c+d)]

then given RR, and using our data,
e.g. a=17,b=1690,c=7,d=1779
where a+b= 17+1690=1707
and c+d=7+1779=1886 input matrix must be
x1 = [ 17, 7;
      1707, 1786];

which corresponds to:

I don't understand, and please forgive me , why I use this
matrix >> x=[17 1690;
              7 1779];

It does not fit your ODDS header input example and does not fit the WIKI def. either.

Also is it possible to add P-values to the ODDS function?



Giuseppe Cardillo

Look well the matrix you gave to odds!
you wrote x1 = [17, 7; 1707 1786];
so a=17, b=7, c=1707 and d=1786.
If you use the correct matrix of your example
>> x=[17 1690;7 1779];
>> odds(x)
Significance level: 95%
Risk Ratio: 1.0564<2.5410<6.1119
Absolute risk reduction: 0.6%
Relative risk reduction: 60.6%
Odds Ratio: 1.0575<2.5565<6.1801
Phi: 0.0331
Weak positive association (risk factor)
Bayesian Credibility Assessment
Critical Odds Ratio: 11.4919
OR<=COR. Test isn't credible at the 95%
alpha = 0.0500 n1 = 1707 n2 = 1786
Z1-b = 0.1982 Power (2-tails) = 0.5786
To achieve a recommended Power=0.80
n1 = 3203 (add 1496 subjects to exposed row)
n2 = 3351 (add 1565 subjects to not exposed row)

Bruce Raine

Hello Giuseppe,
I ran your ODDS function for a microbiologist's data set and we both feel after a little research that ODDS is producing an Odds Ratio rather than a Risk Ratio. Our definitions of Risk ratio and Odds ratio are backed up by WIKI as well and I include the links as well.

>> x1 = [17, 7; 1707 1786];
>> odds(x1)
Significance level: 95%
Risk Ratio: 1.1188<1.4494<1.8779
Absolute risk reduction: 22.0%
Relative risk reduction: 31.0%
Odds Ratio: 1.0511<2.5410<6.1425
Phi: 0.0327
Weak positive association (risk factor)

You can see that 2.5410 is the Odds ratio according to the data but in fact this should be the Risk Ratio not the value
1.4494 as printed above from ODDS.

We base these assertions on some simple arithmetic backed up by WIKI defs:
i.e. Risk Ratio (RR) is defined as:

RR = [a/(a+b)]/[c/(c+d)]

So given this, using our data,
let a=17,b=1690,c=7,d=1779
so RR = (17/1779)/(7/1786) = 0.00996/0.00392 = 2.5410
This is what you have for Odds Ratio but but your Risk Ratio shows 1.4494, a quite different result to 2.5410

Also the Odds Ratio is defined here:


Using the same data as before:

17/1690 0.0100591
------- = --------- = 2.5565
7/1779 0.0039347

Again this is quite different to your ODDS function output for the Odds ratio which has 2.5410.

Are you able to please explain these discrepancies?



Qi An

Qi An (view profile)



bug fixed in Relative Risk Standard Error computation


Changes in description


Changes in help section

NORMINV and NORMCDF was replaced by ERFCINV and ERFC so Statistics Toolbox is no more needed.

I fixed a bug in standard error of log(RR) as suggested by Torsten Heyer

updating power and sample sizes calculation

Added power calculation

Fix bug in confidence interval computation

MATLAB Release
MATLAB 7.3 (R2006b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video