All problems
Bayesian Shrinkage Rate
Problem
Return the Gamma-Poisson posterior mean rate (events + prior_strength*prior_mean)/(person_time + prior_strength), which shrinks the raw rate toward the prior. Return 0.0 when the denominator is not positive or an input is negative.
Hint
prior_strength acts like extra person-time borrowed from the prior.
Test cases
case 1
in: [10,100,0.05,200]
expected: 0.06666666666666667
case 2
in: [0,100,0.1,100]
expected: 0.05
case 3
in: [50,100,0.02,100]
expected: 0.26
case 4
in: [10,100,0.05,0]
expected: 0.1
case 5
in: [0,0,0.1,0]
expected: 0
Starter codePython
def bayesian_shrinkage_rate(events, person_time, prior_mean, prior_strength):
# Your code here
pass5 test cases · run your code against them in the editor