Skip to content
DeepForgeby svx
All problems
EasyStatisticsst-100

Horvitz-Thompson Estimator

Problem

Return the Horvitz-Thompson estimate of a population total: sum(y_i / pi_i) for inclusion probabilities pi_i. Return 0.0 when the lists are empty, lengths differ, or any pi_i is not positive.

Hint

Each sampled unit represents 1/pi units in the population.

Test cases

case 1
in: [[1,2,3],[0.1,0.2,0.3]]
expected: 30
case 2
in: [[10],[0.5]]
expected: 20
case 3
in: [[],[]]
expected: 0
case 4
in: [[1,2],[0,0.5]]
expected: 0
case 5
in: [[5,5],[1,1]]
expected: 10
Starter codePython
def horvitz_thompson(y, inclusion_probs):
    # Your code here
    pass

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