Created
April 11, 2019 17:17
-
-
Save dharasim/7cdc1eca2e35c2c22a14ae18d80ef66c to your computer and use it in GitHub Desktop.
2-sample bootstrap test in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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