Created
August 31, 2011 07:26
-
-
Save samrat/1182998 to your computer and use it in GitHub Desktop.
Verifies the Central Limit Theorem for a given Probability Mass Function(PMF)
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
'''Verifies the Central Limit Theorem for a given Probability Mass Function(PMF) | |
''' | |
import Cdf #http://greenteapress.com/thinkstats/Pmf.html | |
import Pmf #http://greenteapress.com/thinkstats/Cdf.html | |
from thinkstats import Mean #http://greenteapress.com/thinkstats/thinkstats.html | |
from matplotlib import pyplot | |
pmf = Pmf.MakePmfFromDict( {1:3, 3:7, 6:9, 10:4, 5:9, 10:4, 11:5, 12:8} ) | |
cdf = Cdf.MakeCdfFromPmf(pmf) | |
no_of_samples = 1000000 | |
sample_size = 5 | |
sample_means = [] | |
for i in range(no_of_samples): | |
sample_means.append( Mean(cdf.Sample(sample_size)) ) | |
vars, freqs = Pmf.MakePmfFromList(sample_means).Render() | |
graph = pyplot.plot(vars, freqs) | |
pyplot.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment