Created
July 13, 2021 11:48
-
-
Save dBenedek/c1881b34b433c5f1feefa13669064974 to your computer and use it in GitHub Desktop.
[Parametric statistical hypothesis tests in Python] #python #parametric #hypothesis #tests #statistics
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
# Example of the Student's t-test | |
from scipy.stats import ttest_ind | |
data1 = [0.873, 2.817, 0.121, -0.945, -0.055, -1.436, 0.360, -1.478, -1.637, -1.869] | |
data2 = [1.142, -0.432, -0.938, -0.729, -0.846, -0.157, 0.500, 1.183, -1.075, -0.169] | |
stat, p = ttest_ind(data1, data2) | |
print('stat=%.3f, p=%.3f' % (stat, p)) | |
if p > 0.05: | |
print('Probably the same distribution') | |
else: | |
print('Probably different distributions') | |
# Example of the Paired Student's t-test | |
from scipy.stats import ttest_rel | |
data1 = [0.873, 2.817, 0.121, -0.945, -0.055, -1.436, 0.360, -1.478, -1.637, -1.869] | |
data2 = [1.142, -0.432, -0.938, -0.729, -0.846, -0.157, 0.500, 1.183, -1.075, -0.169] | |
stat, p = ttest_rel(data1, data2) | |
print('stat=%.3f, p=%.3f' % (stat, p)) | |
if p > 0.05: | |
print('Probably the same distribution') | |
else: | |
print('Probably different distributions') | |
# Example of the Analysis of Variance Test | |
from scipy.stats import f_oneway | |
data1 = [0.873, 2.817, 0.121, -0.945, -0.055, -1.436, 0.360, -1.478, -1.637, -1.869] | |
data2 = [1.142, -0.432, -0.938, -0.729, -0.846, -0.157, 0.500, 1.183, -1.075, -0.169] | |
data3 = [-0.208, 0.696, 0.928, -1.148, -0.213, 0.229, 0.137, 0.269, -0.870, -1.204] | |
stat, p = f_oneway(data1, data2, data3) | |
print('stat=%.3f, p=%.3f' % (stat, p)) | |
if p > 0.05: | |
print('Probably the same distribution') | |
else: | |
print('Probably different distributions') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment