Example #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()
Example #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()
Example #3
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()
Example #4
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()
Example #5
0
def main(name, data_dir='thinkstats'):

    pool = MakeTables(data_dir)

    print 'Skewness of weights:', Skewness(pool.weights)
    print 'Skewness of gestations:', Skewness(pool.lengths)

    print "Pearson's Skewness of weights:", PearsonSkewness(pool.weights)
    print "Pearson's Skewness of gestations:", PearsonSkewness(pool.lengths)

    MakeFigures(pool)

    myplot.Close()
Example #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()
Example #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()