-
Notifications
You must be signed in to change notification settings - Fork 0
/
17_5.py
28 lines (26 loc) · 937 Bytes
/
17_5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import random
import pylab
def testSamples(numTrials, sampleSize):
tightMeans, wideMeans = [], []
for t in range(numTrials):
sampleTight, sampleWide = [], []
for i in range(sampleSize):
sampleTight.append(random.gauss(0,1))
sampleWide.append(random.gauss(0,100))
tightMeans.append(sum(sampleTight)/len(sampleTight))
wideMeans.append(sum(sampleWide)/len(sampleWide))
return tightMeans, wideMeans
tightMeans, wideMeans = testSamples(1000, 40)
pylab.plot(wideMeans, 'y*', label = ' SD = 100')
pylab.plot(tightMeans, 'bo', label = 'SD = 1')
pylab.xlabel('Sample Number')
pylab.ylabel('Sample Mean')
pylab.title('Means of Samples of Size ' + str(40))
pylab.legend()
pylab.figure()
pylab.hist(wideMeans, bins=20, label = 'SD = 100')
pylab.title('Distribution of Sample Means')
pylab.xlabel('Sample Means')
pylab.ylabel('Frequency of Occurrence')
pylab.legend()
pylab.show()