Skip to content

Instantly share code, notes, and snippets.

@dharasim
Created January 25, 2022 15:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
def permutation_simulation(higher, lower, n=100_000):
xs = higher
ys = lower
m = np.mean(xs) - np.mean(ys)
zs = np.concatenate((xs, ys))
z_perms = np.random.choice(ys, size=(n, len(zs)))
x_perms = z_perms[:, 0:len(xs)]
y_perms = z_perms[:, len(xs)+1:]
x_perm_means = np.mean(x_perms, 1)
y_perm_means = np.mean(y_perms, 1)
return np.sum(x_perm_means - y_perm_means > m)
def permutation_pvalue(higher, lower, n=100_000):
return permutation_simulation(higher, lower, n) / n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment