-
-
Save indiejoseph/77ac90c1e635f4d7e501 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from math import sqrt | |
def ttest(x1, x2): | |
"Student's t-test for unpaired, equal variance, equal size samples." | |
if len(x1) != len(x2): | |
raise ValueError('unequal sample sizes') | |
mx1 = sum(x1) / len(x1) | |
mx2 = sum(x2) / len(x2) | |
s2x1 = sum((xi - mx1)**2 for xi in x1) / (len(x1) - 1) | |
s2x2 = sum((xi - mx2)**2 for xi in x2) / (len(x2) - 1) | |
sx1x2 = sqrt((s2x1 + s2x2) / 2) | |
return (mx1 - mx2) / (sx1x2 * sqrt(float(2) / len(x1))) | |
# Time to run MoveToFront encoding->decoding on different branches on mobydick.txt | |
ll = [.238, .233, .238, .218, .223, .224, .243] | |
array = [.266, .258, .247, .256, .250, .257, .248] | |
print('t-value: %s' % ttest(ll, array)) | |
print('degrees of freedom: %s' % (2 * len(ll) - 2)) | |
# t-value: -5.401857486891129 | |
# degrees of freedom: 12 | |
# This means a 99% probability that ll is faster than array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment