All problems
Randomization Sign-Flip p-Value
Problem
Run a two-sided sign-flip randomization test on paired differences using n_perm sign vectors drawn from the seeded Lehmer RNG (an even draw keeps the sign, an odd draw flips it). Return (count + 1)/(n_perm + 1), where count counts permuted absolute means at least as large as the observed absolute mean; return 1.0 for empty input or n_perm <= 0.
Hint
Under the null each pair's sign is exchangeable.
Test cases
case 1
in: [[1,2,3,4,5],100,42]
expected: 0.0594059405940594
case 2
in: [[1,-1,1,-1],100,7]
expected: 1
case 3
in: [[2,2,2],50,1]
expected: 0.2549019607843137
case 4
in: [[],10,1]
expected: 1
case 5
in: [[1],0,1]
expected: 1
Starter codePython
def sign_flip_p_value(diffs, n_perm, seed):
# Your code here
pass5 test cases · run your code against them in the editor