Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-040

Odds Ratio and Risk Ratio 2x2

Problem

Given a 2x2 table (a exposed cases, b exposed non-cases, c unexposed cases, d unexposed non-cases), return [odds_ratio, risk_ratio] where OR = a*d / (b*c) and RR = (a/(a+b)) / (c/(c+d)). Return 0.0 for a component whose denominator is zero.

Hint

Compute the two ratios independently and return them in a list.

Test cases

case 1
in: [20,80,10,90]
expected: [2.25,2]
case 2
in: [30,70,15,85]
expected: [2.4285714285714284,2]
case 3
in: [10,10,10,10]
expected: [1,1]
case 4
in: [0,10,5,5]
expected: [0,0]
case 5
in: [1,0,0,1]
expected: [0,0]
Starter codePython
def odds_risk_ratios(a, b, c, d):
    # Your code here
    pass

5 test cases · run your code against them in the editor