def main(): results = _10_relay._read_results() speeds = _10_relay._get_speeds(results) # plot the distribution of actual speeds pmf = _04_Pmf._make_pmf_from_list(speeds, 'actual speeds') # myplot.Clf() # myplot.Hist(pmf) # myplot.Save(root='observed_speeds', # title='PMF of running speed', # xlabel='speed (mph)', # ylabel='probability') # plot the biased distribution seen by the observer biased = _bias_pmf(pmf, 7.5, name='observed speeds') _05_myplot._clf() _05_myplot._hist(biased) _05_myplot._save(root='observed_speeds', title='PMF of running speed', xlabel='speed (mph)', ylabel='probability') cdf = _13_Cdf._make_cdf_from_pmf(biased) _05_myplot._clf() _05_myplot._cdf(cdf) _05_myplot._save(root='observed_speeds_cdf', title='CDF of running speed', xlabel='speed (mph)', ylabel='cumulative probability')
def testRender(self): t = [1, 2, 2, 3, 5] pmf = _04_Pmf._make_pmf_from_list(t) xs, ps = pmf._render() d = dict(zip(xs, ps)) new_pmf = _04_Pmf._make_pmf_from_dict(d) self.checkPmf(new_pmf)
def testMakePmfFromCdf(self): t = [1, 2, 2, 3, 5] pmf = _04_Pmf._make_pmf_from_list(t) self.checkPmf(pmf) cdf = _13_Cdf._make_cdf_from_pmf(pmf) pmf2 = _04_Pmf._make_pmf_from_cdf(cdf) self.checkPmf(pmf2)
def main(): results = _read_results() speeds = _get_speeds(results) pmf = _04_Pmf._make_pmf_from_list(speeds, 'speeds') _05_myplot._pmf(pmf) _05_myplot._show(title='PMF of running speed', xlabel='speed (mph)', ylabel='probability')
def _make_pmfs(lens): """Computes the PMF of the given list and the biased PMF.""" pmf = _04_Pmf._make_pmf_from_list(lens, 'slashdot') print('unbiased mean', pmf._mean()) biased_pmf = _bias_pmf(pmf, 'biased') print('biased mean', biased_pmf._mean()) return pmf, biased_pmf
def _log_cdf_time_interval(): timeInterval = _calc_time_interval() pmf = _04_Pmf._make_pmf_from_list(timeInterval, "baby birth interval") cdf = _13_Cdf._make_cdf_from_pmf(pmf, "baby birth interval") _05_myplot._clf() _05_myplot._cdf(cdf, complement=True, xscale="linear", yscale="log") _05_myplot._save( root="baby_birth_interval_logccdf", title="LogCCDF of baby birth interval", xlabel="interval(minutes)", ylabel="LogCCdf", )
def testMeanAndVar(self): t = [1, 2, 2, 3, 5] mu = _03_thinkstats._mean(t) var = _03_thinkstats._var(t, mu) pmf = _04_Pmf._make_pmf_from_list(t) mu2 = pmf._mean() var2 = pmf._var() var3 = pmf._var(mu2) self.assertAlmostEquals(mu, mu2) self.assertAlmostEquals(var, var2) self.assertAlmostEquals(var, var3)
def _make_uniform_suite(low, high, steps): """ Makes a PMF that represents a suite of hypotheses with equal p. Args: low: low end of range high: high end of range steps: number of values Returns: Pmf object """ hypos = [low + (high - low) * i / (steps - 1.0) for i in range(steps)] pmf = _04_Pmf._make_pmf_from_list(hypos) return pmf
def _process(table, name): """ Runs various analyses on this table. Creates instance variables: weights: sequence of int total weights in ounces weight_pmf: Pmf object weight_cdf: Cdf object oz_pmf: Pmf of just the ounce field """ _06_descriptive._process(table, name) table.weights = [p.totalwgt_oz for p in table.records if p.totalwgt_oz != 'NA'] table.weight_pmf = _04_Pmf._make_pmf_from_list(table.weights, table.name) table.weight_cdf = _13_Cdf._make_cdf_from_list(table.weights, table.name)
def testMakePmf(self): t = [1, 2, 2, 3, 5] pmf = _04_Pmf._make_pmf_from_list(t) self.checkPmf(pmf) d = pmf._get_dict() self.assertAlmostEquals(d[2], 0.4) vals = pmf._values() self.assertEquals(sorted(vals), [1, 2, 3, 5]) items = pmf._items() d = dict(items) new_pmf = _04_Pmf._make_pmf_from_dict(d) self.checkPmf(new_pmf)
def _process(table, name): """ Runs various analyses on this table. Creates instance variables: ages: sequence of int ages in years age_pmf: Pmf object age_cdf: Cdf object weights: sequence of total weight in ounces weight_cdf: Cdf object """ cumulative._process(table, name) table.ages = [p.agepreg for p in table.records if p.agepreg != 'NA'] table.age_pmf = _04_Pmf._make_pmf_from_list(table.ages, table.name) table.age_cdf = _13_Cdf._make_cdf_from_list(table.ages, table.name) table.weights = [p.totalwgt_oz for p in table.records if p.totalwgt_oz != 'NA'] table.weight_cdf = _13_Cdf._make_cdf_from_list(table.weights, table.name)
def _cdf_time_interval(): timeInterval = _calc_time_interval() pmf = _04_Pmf._make_pmf_from_list(timeInterval, "baby birth interval") _05_myplot._clf() _05_myplot._hist(pmf) _05_myplot._save( root="baby_birth_interval_pmf", title="PMF of baby birth interval", xlabel="interval(minutes)", ylabel="probability", ) cdf = _13_Cdf._make_cdf_from_pmf(pmf) _05_myplot._clf() _05_myplot._cdf(cdf) _05_myplot._save( root="baby_birth_interval_cdf", title="CDF of baby birth interval", xlabel="interval(minutes)", ylabel="cumulative probability", )
def testMultAndNormalize(self): t = [1, 2, 3, 5] pmf = _04_Pmf._make_pmf_from_list(t) pmf._mult(2, 2) pmf._normalize() self.checkPmf(pmf)