All problems
Power of a Two-Sided Eval
Problem
Return the power Phi(shift - z) + Phi(-shift - z) of a two-sided test, where shift = |delta| * sqrt(n / variance) and z is the 1 - alpha/2 normal quantile. Phi is the standard normal CDF computed with math.erf. Return 0.0 when n <= 0, variance <= 0, or alpha lies outside (0, 1), and clamp the result to [0, 1].
Hint
At delta = 0 the two-sided power equals alpha.
Test cases
case 1
in: [0.05,400,0.25,0.05]
expected: 0.5160052739761751
case 2
in: [0.1,100,1,0.05]
expected: 0.17007504575308774
case 3
in: [0,100,1,0.05]
expected: 0.050000000000000155
case 4
in: [0.05,0,1,0.05]
expected: 0
Starter codePython
import math
def eval_power(delta, n, variance, alpha):
# Your code here
pass4 test cases · run your code against them in the editor