All problems
Population Attributable Fraction
Problem
Return the population attributable fraction p_e*(RR - 1)/(1 + p_e*(RR - 1)), where p_e = (a+b)/n is the exposure prevalence and RR is the risk ratio. Return 0.0 when the table is empty or the unexposed risk is zero.
Hint
PAF combines the exposure prevalence with the strength of the risk ratio.
Test cases
case 1
in: [30,70,10,90]
expected: 0.49999999999999994
case 2
in: [20,80,20,80]
expected: 0
case 3
in: [50,50,10,90]
expected: 0.6666666666666666
case 4
in: [10,90,20,80]
expected: -0.3333333333333333
case 5
in: [0,10,5,5]
expected: -1
Starter codePython
def population_attributable_fraction(a, b, c, d):
# Your code here
pass5 test cases · run your code against them in the editor