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
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
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
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)
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
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])
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'
def PearsonSkewness(t): return 3.0 * (thinkstats.Mean(t) - Median(t)) / math.sqrt( thinkstats.Var(t))