Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-201

Empirical Bayes Mean

Problem

Return the empirical Bayes shrunk mean grand + (tau2/(tau2 + within_var/n))*(group_mean - grand), where tau2 is the between-group variance. Return 0.0 when n <= 0, a variance is negative, or the denominator is zero.

Hint

Groups with less data are pulled further toward the grand mean.

Test cases

case 1
in: [12,10,4,1,10]
expected: 11.428571428571429
case 2
in: [12,10,4,1,1]
expected: 10.4
case 3
in: [8,10,4,1,10]
expected: 8.571428571428571
case 4
in: [10,10,1,1,5]
expected: 10
case 5
in: [12,10,4,0,10]
expected: 10
Starter codePython
def empirical_bayes_mean(group_mean, grand_mean, within_var, between_var, n):
    # Your code here
    pass

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