Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-285

Mediation Proportion

Problem

Compute the proportion of the total effect that is mediated: (a*b) / (a*b + c_prime).

Return 0.0 when the denominator is 0.

Hint

The indirect effect a*b shares the total effect with the direct path c_prime.

Test cases

case 1
in: [0.5,0.8,0.1]
expected: 0.8
case 2
in: [0.2,-0.1,-0.02]
expected: 0.5
case 3
in: [0,0,0]
expected: 0
case 4
in: [1,2,-2]
expected: 0
Starter codePython
def mediation_proportion(a, b, c_prime):
    # Your code here
    pass

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