Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-120

IPW Mean

Problem

Return the inverse probability weighted mean of the treated outcomes, (1/n) * sum(t_i*y_i/e_i) over all n units, where e_i is the propensity score. Return 0.0 when input lengths differ, any treated unit has e_i <= 0, or the input is empty.

Hint

Treated units stand in for themselves and similar untreated units.

Test cases

case 1
in: [[1,0,1,0],[10,5,8,4],[0.5,0.5,0.4,0.6]]
expected: 10
case 2
in: [[0,0],[1,2],[0.2,0.3]]
expected: 0
case 3
in: [[1],[7],[0.7]]
expected: 10
case 4
in: [[],[],[]]
expected: 0
case 5
in: [[1,1],[2,3],[0,0.5]]
expected: 0
Starter codePython
def ipw_mean(treatment, outcome, propensity):
    # Your code here
    pass

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