Created
August 28, 2011 11:38
-
-
Save samrat/1176568 to your computer and use it in GitHub Desktop.
Verifying Central Limit Theorem computationally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
from matplotlib import pyplot | |
def gen_mean(sample_size): | |
sum = 0 | |
for i in range(sample_size): | |
sum += randint(1, 100) | |
mean = ( float(sum) / sample_size ) | |
return mean | |
sample_means = [] | |
sample_size = 100 | |
no_of_samples = 100000 | |
for c in range(no_of_samples): | |
sample_means.append( int(gen_mean(sample_size)) ) | |
min_mean = int( min(sample_means) ) | |
max_mean = int( max(sample_means) +1 ) | |
# Create graph | |
X = range(min_mean, max_mean) | |
Y = [ sample_means.count(i) for i in X ] | |
print X | |
print Y | |
pyplot.plot( X, Y, '-') | |
pyplot.xlabel( 'Sample Mean') | |
pyplot.ylabel( 'No of occurences of sample mean' ) | |
pyplot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment