Procy0n

Cog409: Sarja 2, tehtävä 4

Mar 6th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # Sakari Vaelma
  3.  
  4.  
  5. from random import gauss
  6. from math import sqrt
  7. from scipy.stats import ttest_ind
  8.  
  9.  
  10. TESTS = 10000
  11. NUMBERS_IN_SAMPLE = 100
  12.  
  13. def random_normal_sample(count, mean, variance):
  14.     return [gauss(mean, sqrt(variance))
  15.             for n in range(count)]
  16.  
  17. print "Percentage of p < 0.05: %.2f" %\
  18.     (len([p for t, p
  19.           in [ttest_ind(random_normal_sample(NUMBERS_IN_SAMPLE, 0, 1),
  20.                         random_normal_sample(NUMBERS_IN_SAMPLE, 0, 1))
  21.               for n in range(TESTS)]
  22.           if p < 0.05]) / float(TESTS) * 100)
Advertisement
Add Comment
Please, Sign In to add comment