Skip to content

Instantly share code, notes, and snippets.

@dharasim
Created April 11, 2019 17:17
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/7cdc1eca2e35c2c22a14ae18d80ef66c to your computer and use it in GitHub Desktop.
Save dharasim/7cdc1eca2e35c2c22a14ae18d80ef66c to your computer and use it in GitHub Desktop.
2-sample bootstrap test in python
def bootstrap_test(higher, lower, n=100000):
xs = higher
ys = lower
m = np.mean(xs) - np.mean(ys)
zs = np.concatenate((xs,ys))
boots = np.random.choice(ys, size=(n,len(zs)))
return np.sum(np.mean(boots[:,0:len(xs)], 1) - np.mean(boots[:,len(xs)+1:], 1) > m)
# test whether the mean of the array `higher` is higher than the mean of the array `lower`
def bootstrap_pvalue(higher, lower, n=100000):
return bootstrap_test(higher, lower, n=100000) / n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment