def _class_sizes(): # start with the actual distribution of class sizes from the book d = { 7: 8, 12: 8, 17: 14, 22: 4, 27: 6, 32: 12, 37: 8, 42: 3, 47: 2, } # form the pmf pmf = _04_Pmf._make_pmf_from_dict(d, 'actual') print('mean', pmf._mean()) print('var', pmf._var()) # compute the biased pmf biased_pmf = _bias_pmf(pmf, 'observed') print('mean', biased_pmf._mean()) print('var', biased_pmf._var()) # unbias the biased pmf unbiased_pmf = _unbias_pmf(biased_pmf, 'unbiased') print('mean', unbiased_pmf._mean()) print('var', unbiased_pmf._var()) # plot the Pmfs _05_myplot._pmfs([pmf, biased_pmf]) _05_myplot._show(xlabel='Class size', ylabel='PMF')
def _plot_ages(resp): """Plot the distribution of ages.""" ages = [r.age for r in resp.records] cdf = _13_Cdf._make_cdf_from_list(ages) _05_myplot._clf() _05_myplot._cdf(cdf) _05_myplot._show()
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 _check_cdf2(): """Compare chi2 values from the simulation with a chi-squared dist.""" df = 3 t = [_simulate_chi2() for i in range(1000)] t2 = [scipy.stats.chi2.cdf(x, df) for x in t] cdf = _13_Cdf._make_cdf_from_list(t2) _05_myplot._cdf(cdf) _05_myplot._show()
def main(): suite = _make_uniform_suite(0.0, 1.0, 1001) evidence = 140, 110 _update(suite, evidence) suite.name = 'posterior' # plot the posterior distributions _05_myplot._pmf(suite) _05_myplot._show(title='Biased coin', xlabel='P(heads)', ylabel='Posterior probability')