Skip to content
DeepForgeby svx
All problems
HardStatisticsst-047

Permutation p-Value from Difference of Means

Problem

Run a two-sided permutation test on the difference of means between x and y using n_perm label shuffles. Use a self-contained Lehmer RNG seeded with seed (state = seed % 2147483647, next = state * 48271 % 2147483647) so results are deterministic. Return (count + 1) / (n_perm + 1), where count is the number of permuted absolute differences greater than or equal to the observed absolute difference; return 1.0 for empty input or n_perm <= 0.

Hint

Shuffle with Fisher-Yates driven by the seeded generator, then recompute the difference.

Test cases

case 1
in: [[1,2,3,4,5],[6,7,8,9,10],100,42]
expected: 0.009900990099009901
case 2
in: [[1,2,3,4,5],[6,7,8,9,10],200,7]
expected: 0.014925373134328358
case 3
in: [[1,2,3,4,5],[5,4,3,2,1],100,3]
expected: 1
case 4
in: [[],[1,2],50,1]
expected: 1
case 5
in: [[1,2],[3,4],0,1]
expected: 1
Starter codePython
def permutation_p_value(x, y, n_perm, seed):
    # Your code here
    pass

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