Premium problem128. Permutation Test

Medium Locked

Given two samples, return a two-sided permutation-test p-value for the difference in their means.

  • compute the observed difference
  • pool both samples, reshuffle, and split them back into the original sizes
  • count how often the shuffled difference is at least as extreme as the observed one
  • the p-value is (count+1)/(permutations+1)(\text{count} + 1) / (\text{permutations} + 1)

The +1+1 on both sides keeps the p-value from ever being exactly zero, which no finite number of shuffles can justify claiming.

Seed np.random.seed(seed) inside solve, immediately before shuffling.

Input

a = [1.0, 2.0, 3.0, 4.0]
b = [3.0, 4.0, 5.0, 6.0]
permutations = 500
seed = 0

Output

0.13972055888223553

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)