Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-190

Direct Standardization

Problem

Return the directly standardized (age-adjusted) rate sum(rate_h * weight_h)/sum(weight_h) using the standard population weights. Return 0.0 when either list is empty or the weights sum to zero.

Hint

Weight each stratum-specific rate by the standard population share.

Test cases

case 1
in: [[0.01,0.02],[0.5,0.5]]
expected: 0.015
case 2
in: [[0.1,0.2,0.3],[100,200,700]]
expected: 0.26
case 3
in: [[0.05],[1]]
expected: 0.05
case 4
in: [[],[]]
expected: 0
case 5
in: [[0.1,0.2],[0,0]]
expected: 0
Starter codePython
def direct_standardization(stratum_rates, standard_weights):
    # Your code here
    pass

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