Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from numpy.random import seed
  4. from numpy.random import randn
  5. from numpy import mean
  6. from numpy import std
  7. from scipy.stats import ttest_ind
  8. from scipy.stats import ttest_rel
  9. from scipy.stats import f_oneway
  10.  
  11. seed(1)
  12.  
  13. # generate two sets of univariate observations
  14. data1 = 5 * randn(100) + 50
  15. data2 = 5 * randn(100) + 51
  16.  
  17. # summarize
  18. print('data1: mean=%.3f std=%.3f' % (mean(data1), std(data1)))
  19. print('data2: mean=%.3f std=%.3f' % (mean(data2), std(data2)))
  20.  
  21. # Student's t-test
  22. stat, p = ttest_ind(data1, data2)
  23.  
  24. print('Statistics=%.3f, p=%.3f' % (stat, p))
  25.  
  26. # interpret
  27. alpha = 0.05
  28.  
  29. if p > alpha:
  30. print('Same distributions (fail to reject H0)')
  31. else:
  32. print('Different distributions (reject H0)')
  33.  
  34.  
  35. # Paired Student's t-test
  36.  
  37. seed(1)
  38. data1 = 5 * randn(100) + 50
  39. data2 = 5 * randn(100) + 51
  40.  
  41. # compare samples
  42. stat, p = ttest_rel(data1, data2)
  43.  
  44. print('Statistics=%.3f, p=%.3f' % (stat, p))
  45.  
  46. # interpret
  47. alpha = 0.05
  48.  
  49. if p > alpha:
  50. print('Same distributions (fail to reject H0)')
  51. else:
  52. print('Different distributions (reject H0)')
  53.  
  54. # Paired Student's t-test
  55.  
  56. seed(1)
  57. data1 = 5 * randn(100) + 50
  58. data2 = 5 * randn(100) + 51
  59.  
  60. # compare samples
  61. stat, p = ttest_rel(data1, data2)
  62. print('Statistics=%.3f, p=%.3f' % (stat, p))
  63. # interpret
  64. alpha = 0.05
  65. if p > alpha:
  66. print('Same distributions (fail to reject H0)')
  67. else:
  68. print('Different distributions (reject H0)')
  69.  
  70. # Analysis of Variance test
  71.  
  72. seed(1)
  73. data1 = 5 * randn(100) + 50
  74. data2 = 5 * randn(100) + 50
  75. data3 = 5 * randn(100) + 52
  76.  
  77. # compare samples
  78. stat, p = f_oneway(data1, data2, data3)
  79.  
  80. print('Statistics=%.3f, p=%.3f' % (stat, p))
  81.  
  82. # interpret
  83. alpha = 0.05
  84.  
  85. if p > alpha:
  86. print('Same distributions (fail to reject H0)')
  87. else:
  88. print('Different distributions (reject H0)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement