Esempio n. 1
0
def ex6_14(n, do_log=False, ns=1000):
    exp = randvar.Exponential(1)

    def prod_log(t):
        p = 1
        for x in t:
            p = p * x

        if do_log == True:
            return math.log(p)
        else:
            return p

    s = [prod_log([exp.generate() for x in range(n)]) for i in range(ns)]

    mu, var = thinkstats.MeanVar(s)
    print n, mu, var

    cdf = Cdf.MakeCdfFromList(s)
    myplot.Clf()
    myplot.Cdf(cdf)
    myplot.Save('clt14' + str(do_log) + str(n))

    rankit.MakeNormalPlot(s, 'clt14npp' + str(do_log) + str(n))

    myplot.Close()
Esempio n. 2
0
def main():
    results = ReadResults()
    print '# of samples:', len(results)

    results = CondFilter(results)
    print '# of samples(age=30s):', len(results)

    h_speed, h_rank, h_rank_age = FindProfHeo(results)
    speeds = GetSpeeds(results)
    pmf = Pmf.MakePmfFromList(speeds, 'speeds')
    cdf = Cdf.MakeCdfFromList(speeds, 'speeds')
    if h_speed:
        print '허준영s speed is ', h_speed
        print 'His percentile rank is ', cdf.Prob(h_speed) * 100

    myplot.Clf()
    myplot.Pmf(pmf)
    myplot.Save(root='mbc_marathon_pmf',
                title='PMF of running speed',
                xlabel='speed (kmh)',
                ylabel='probability')

    myplot.Clf()
    myplot.Cdf(cdf)
    myplot.Save(root='mbc_marathon_cdf',
                title='CDF of running speed',
                xlabel='speed (kmh)',
                ylabel='probability')

    myplot.Close()
Esempio n. 3
0
def ex6_12(n, ns=1000):
    exp = randvar.Exponential(1)

    s = [sum([exp.generate() for x in range(n)]) / float(n) for i in range(ns)]

    mu, var = thinkstats.MeanVar(s)
    print n, mu, var

    cdf = Cdf.MakeCdfFromList(s)
    myplot.Clf()
    myplot.Cdf(cdf)
    myplot.Save('clt' + str(n))
    myplot.Close()
Esempio n. 4
0
def MakeFigures(pool):
    myplot.Clf()
    myplot.Hist(pool.weight_pmf, linewidth=1, color='blue')
    myplot.Save(root='nsfg_birthwgt_pmf',
                title='Birth weight PMF',
                xlabel='weight (ounces)',
                ylabel='probability')

    myplot.Clf()
    myplot.Cdf(pool.lengths_pmf, linewidth=1, color='blue')
    myplot.Save(root='nsfg_weeks_pmf',
                title='Gestation PMF',
                xlabel='weeks',
                ylabel='probability')
Esempio n. 5
0
def ex6_13(n, ns=1000):
    exp = randvar.Exponential(1)

    s = [sum([exp.generate() for x in range(n)]) for i in range(ns)]

    mu, var = thinkstats.MeanVar(s)
    print n, mu, var

    cdf = Cdf.MakeCdfFromList(s)
    myplot.Clf()
    myplot.Cdf(cdf)
    myplot.Save('clt13' + str(n))

    rankit.MakeNormalPlot(s, 'clt13npp' + str(n))

    myplot.Close()
Esempio n. 6
0
26	,
23	,
14	,
101	,
125	,
0	,
53	,
10	,
56	,
165	,
46	,
5	,
0	,
38	,
29	,
4	,
30	,
89	,
14	,
                    ]

cdf = Cdf.MakeCdfFromList(birthday_arrival)
print 'Mean:', cdf.Mean()
myplot.Clf()
myplot.Cdf(cdf)
myplot.Save('birthday_cdf')
myplot.Clf()
myplot.Cdf(cdf, complement=True)
myplot.Save('birthday_ccdf', yscale='log')
myplot.Close()
Esempio n. 7
0
from thinkstats import Cdf
from thinkstats import myplot

t = [2, 1, 3, 2, 5]
cdf = Cdf.MakeCdfFromList(t)
cdf.name = 'Sample'

print 'cdf.Prob(2):', cdf.Prob(2)
print 'cdf.Prob(3):', cdf.Prob(3)
print 'cdf.Prob(6):', cdf.Prob(6)

print 'cdf.Value(0.5):', cdf.Value(0.5)
print 'cdf.Value(0.7):', cdf.Value(0.7)

myplot.Clf()
myplot.Cdf(cdf)
myplot.Show(title='CDF', xlabel='x', ylabel='CDF(x)', axis=[0, 6, 0, 1])