All problems
Moderated Mediation Index
Problem
Compute the index of moderated mediation: (a_high - a_low) * b, where a_low and a_high are the treatment-to-mediator effects at two moderator levels and b is the mediator-to-outcome effect.
Hint
A nonzero index means the indirect effect depends on the moderator.
Test cases
case 1
in: [0.3,0.5,0.8]
expected: 0.16000000000000003
case 2
in: [0.5,0.2,0.4]
expected: -0.12
case 3
in: [0.4,0.4,1]
expected: 0
Starter codePython
def moderated_mediation_index(a_low, a_high, b):
# Your code here
pass3 test cases · run your code against them in the editor