Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math,random
- def testStatistic(x,n,p):
- q = 1-p
- return(x/n - p)/(math.sqrt(p*q/n))
- max = 10000
- sampleSize = 1000
- #the right way
- count = 0
- for i in range(max):
- x = 0
- for j in range(sampleSize):
- x+=random.randint(0,1)
- if testStatistic(x,sampleSize,.5) > 1.2816: count += 1
- print('good: '+str(count/max))
- #the wrong way
- count = 0
- for i in range(max):
- x= 0
- trials = 0
- while (trials < sampleSize):
- x, trials = x+random.randint(0,1),trials + 1
- if x > 15 and trials - x > 15:
- if testStatistic(x,trials,.5)>1.2816:
- count +=1
- trials = sampleSize
- print('bad: '+str(count/max))
Add Comment
Please, Sign In to add comment