コード例 #1
0
def Var3(t, mu=None):
    if mu is None:
        mu = thinkstats.Mean(t)

    # compute the squared deviations and return their mean.
    dev2 = [(x - mu)**3 for x in t]
    var = thinkstats.Mean(dev2)
    return var
コード例 #2
0
def Sample():
    exp = randvar.Exponential(p_lam)
    sample = sorted([exp.generate() for x in range(6)])

    mean = ts.Mean(sample)
    median = ts.Mean(sample[2:4])

    return 1.0/mean, math.log(2)/median
コード例 #3
0
def Sample():
    normal = randvar.Normal(0, 1)
    sample = [normal.generate() for x in range(6)]

    mean = ts.Mean(sample)
    dev2 = [(x - mean)**2 for x in sample]
    sn = sum(dev2) / float(len(dev2))
    sn_1 = sum(dev2) / float(len(dev2) - 1)

    return sn, sn_1
コード例 #4
0
def runtest(name, actual1, actual2):
    print name

    # observed delta
    mu1, mu2 = thinkstats.Mean(actual1), thinkstats.Mean(actual2)
    delta = abs(mu1 - mu2)
    n, m = len(actual1), len(actual2)

    model = actual1 + actual2

    cdf, pvalue = PValue(model, model, n, m, delta)
    print 'n:', n
    print 'm:', m
    print 'mu1', mu1
    print 'mu2', mu2
    print 'delta', delta
    print 'p-value', pvalue

    PlotCdf(name, cdf, delta)
コード例 #5
0
def Resample(t1, t2, n, m):
    sample1 = [random.choice(t1) for i in range(n)]
    sample2 = [random.choice(t2) for i in range(m)]
    delta = thinkstats.Mean(sample1) - thinkstats.Mean(sample2)
    return delta
コード例 #6
0
def Sample():
    normal = randvar.Normal(0, 1)
    sample = sorted([normal.generate() for x in range(6)])

    return ts.Mean(sample), ts.Mean(sample[2:4])
コード例 #7
0
import thinkstats.thinkstats as ts
import math

pumpkins = [200, 250, 500, 550, 2000, 2500]
print 'Mean of pumpkins:', ts.Mean(pumpkins), 'g'
print 'Variance of pumpkins:', ts.Var(pumpkins), 'g^2'
print 'Standard Dev. of pumpkins:', math.sqrt(ts.Var(pumpkins)), 'g'
コード例 #8
0
def PearsonSkewness(t):
    return 3.0 * (thinkstats.Mean(t) - Median(t)) / math.sqrt(
        thinkstats.Var(t))