Exemplo n.º 1
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()
Exemplo n.º 2
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')
Exemplo n.º 3
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()
Exemplo n.º 4
0
def PlotCdf(root, cdf, delta):
    """Draws a Cdf with vertical lines at the observed delta.

    Args:
       root: string used to generate filenames
       cdf: Cdf object
       delta: float observed difference in means    
    """
    def VertLine(x):
        """Draws a vertical line at x."""
        xs = [x, x]
        ys = [0, 1]
        pyplot.plot(xs, ys, linewidth=2, color='0.7')

    VertLine(-delta)
    VertLine(delta)

    xs, ys = cdf.Render()
    pyplot.subplots_adjust(bottom=0.11)
    pyplot.plot(xs, ys, linewidth=2, color='blue')

    myplot.Save(root,
                title='Resampled differences',
                xlabel='difference in means',
                ylabel='CDF(x)',
                legend=False)

    myplot.Close()
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
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()
Exemplo n.º 8
0
from thinkstats import rankit
from thinkstats import myplot
import random

sample = [random.normalvariate(0.0, 1.0) for i in range(100)]

means = rankit.EstimateRankits(len(sample))
myplot.Plot(means, sorted(sample), 'b.', markersize=3)
myplot.Save('rankit_npp', xlabel='rankits')

rankit.MakeNormalPlot(sample, 'dirty_npp')

myplot.Close()