All problems
Propensity Match Pair Count
Problem
Form matched pairs greedily in input order: each treated unit takes the nearest unused control within caliper of its propensity score, and that control is then removed. Ties keep the earliest control. Return the number of pairs formed, or 0 when there are no controls.
Hint
Greedy nearest neighbor matching within the caliper.
Test cases
case 1
in: [[1,1,0,0,0],[0.9,0.4,0.85,0.5,0.2],0.1]
expected: 2
case 2
in: [[1,1,0],[0.3,0.7,0.5],0.05]
expected: 0
case 3
in: [[1,0,1,0],[0.2,0.25,0.8,0.75],0.1]
expected: 2
case 4
in: [[1,1],[0.5,0.6],0.5]
expected: 0
case 5
in: [[1,0],[0.5,0.5],0]
expected: 1
Starter codePython
def propensity_match_count(treatment, propensity, caliper):
# Your code here
pass5 test cases · run your code against them in the editor