Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from numpy.random import seed
- from numpy.random import randn
- from numpy import mean
- from numpy import std
- from scipy.stats import ttest_ind
- from scipy.stats import ttest_rel
- from scipy.stats import f_oneway
- seed(1)
- # generate two sets of univariate observations
- data1 = 5 * randn(100) + 50
- data2 = 5 * randn(100) + 51
- # summarize
- print('data1: mean=%.3f std=%.3f' % (mean(data1), std(data1)))
- print('data2: mean=%.3f std=%.3f' % (mean(data2), std(data2)))
- # Student's t-test
- stat, p = ttest_ind(data1, data2)
- print('Statistics=%.3f, p=%.3f' % (stat, p))
- # interpret
- alpha = 0.05
- if p > alpha:
- print('Same distributions (fail to reject H0)')
- else:
- print('Different distributions (reject H0)')
- # Paired Student's t-test
- seed(1)
- data1 = 5 * randn(100) + 50
- data2 = 5 * randn(100) + 51
- # compare samples
- stat, p = ttest_rel(data1, data2)
- print('Statistics=%.3f, p=%.3f' % (stat, p))
- # interpret
- alpha = 0.05
- if p > alpha:
- print('Same distributions (fail to reject H0)')
- else:
- print('Different distributions (reject H0)')
- # Paired Student's t-test
- seed(1)
- data1 = 5 * randn(100) + 50
- data2 = 5 * randn(100) + 51
- # compare samples
- stat, p = ttest_rel(data1, data2)
- print('Statistics=%.3f, p=%.3f' % (stat, p))
- # interpret
- alpha = 0.05
- if p > alpha:
- print('Same distributions (fail to reject H0)')
- else:
- print('Different distributions (reject H0)')
- # Analysis of Variance test
- seed(1)
- data1 = 5 * randn(100) + 50
- data2 = 5 * randn(100) + 50
- data3 = 5 * randn(100) + 52
- # compare samples
- stat, p = f_oneway(data1, data2, data3)
- print('Statistics=%.3f, p=%.3f' % (stat, p))
- # interpret
- alpha = 0.05
- if p > alpha:
- print('Same distributions (fail to reject H0)')
- else:
- print('Different distributions (reject H0)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement