Skip to content

Instantly share code, notes, and snippets.

@dharasim
Created January 25, 2022 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dharasim/69b361731ec87a3d6602e559549c2778 to your computer and use it in GitHub Desktop.
Save dharasim/69b361731ec87a3d6602e559549c2778 to your computer and use it in GitHub Desktop.
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