예제 #1
0
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()
예제 #2
0
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')
예제 #3
0
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()
예제 #4
0
def main():
    results = _10_relay._read_results()
    speeds = _10_relay._get_speeds(results)

    # plot the distribution of actual speeds
    cdf = _13_Cdf._make_cdf_from_list(speeds, 'speeds')

    _05_myplot._cdf(cdf)
    _05_myplot._save(root='relay_cdf',
                     title='CDF of running speed',
                     xlabel='speed (mph)',
                     ylabel='probability')
예제 #5
0
def _make_example():
    """Make a simple example CDF."""
    t = [2, 1, 3, 2, 5]
    cdf = _13_Cdf._make_cdf_from_list(t)
    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(root='example_cdf',
                     title='CDF',
                     xlabel='x',
                     ylabel='CDF(x)',
                     axis=[0, 6, 0, 1],
                     legend=False)
예제 #6
0
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",
    )
예제 #7
0
def _check_cdf():
    """Compare chi2 values from simulation with chi2 distributions."""
    for df in [1, 2, 3]:
        xs, ys = _chi2_cdf(df=df, high=15)
        pyplot.plot(xs, ys, label=df)

    t = [_simulate_chi2() for i in range(1000)]
    cdf = _13_Cdf._make_cdf_from_list(t)

    _05_myplot._cdf(cdf)
    _05_myplot._save(root='khan3',
                     xlabel='chi2 value',
                     ylabel="CDF",
                     formats=['png'])
예제 #8
0
def _make_cdfs(lens):
    cdf = _13_Cdf._make_cdf_from_list(lens, 'slashdot')

    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(root='slashdot.logx',
                     xlabel='Number of friends/foes',
                     ylabel='CDF',
                     xscale='log')

    _05_myplot._clf()
    _05_myplot._cdf(cdf, complement=True)
    _05_myplot._save(root='slashdot.loglog',
                     xlabel='Number of friends/foes',
                     ylabel='CDF',
                     xscale='log',
                     yscale='log')
예제 #9
0
def _make_figures(pool, firsts, others):
    """Creates several figures for the book."""

    # CDF of all ages
    _05_myplot._clf()
    _05_myplot._cdf(pool.age_cdf)
    _05_myplot._save(root='agemodel_age_cdf',
                     title="Distribution of mother's age",
                     xlabel='age (years)',
                     ylabel='CDF',
                     legend=False)

    # CDF of all weights
    _05_myplot._clf()
    _05_myplot._cdf(pool.weight_cdf)
    _05_myplot._save(root='agemodel_weight_cdf',
                     title="Distribution of birth weight",
                     xlabel='birth weight (oz)',
                     ylabel='CDF',
                     legend=False)

    # plot CDFs of birth ages for first babies and others
    _05_myplot._clf()
    _05_myplot._cdfs([firsts.age_cdf, others.age_cdf])
    _05_myplot._save(root='agemodel_age_cdfs',
                     title="Distribution of mother's age",
                     xlabel='age (years)',
                     ylabel='CDF')

    _05_myplot._clf()
    _05_myplot._cdfs([firsts.weight_cdf, others.weight_cdf])
    _05_myplot._save(root='agemodel_weight_cdfs',
                     title="Distribution of birth weight",
                     xlabel='birth weight (oz)',
                     ylabel='CDF')

    # make a scatterplot of ages and weights
    ages, weights = _get_age_weight(pool)
    pyplot.clf()
    # pyplot.scatter(ages, weights, alpha=0.2)
    pyplot.hexbin(ages, weights, cmap=matplotlib.cm.gray_r)
    _05_myplot._save(root='agemodel_scatter',
                     xlabel='Age (years)',
                     ylabel='Birth weight (oz)',
                     legend=False)
예제 #10
0
def _plot_marginals(suite):
    """Plot the marginal distributions for a 2-D joint distribution."""
    pmf_m, pmf_s = _compute_marginals(suite)

    pyplot.clf()
    pyplot.figure(1, figsize=(7, 4))

    pyplot.subplot(1, 2, 1)
    cdf_m = _13_Cdf._make_cdf_from_pmf(pmf_m, 'mu')
    _05_myplot._cdf(cdf_m)
    pyplot.xlabel('Mean height (cm)')
    pyplot.ylabel('CDF')

    pyplot.subplot(1, 2, 2)
    cdf_s = _13_Cdf._make_cdf_from_pmf(pmf_s, 'sigma')
    _05_myplot._cdf(cdf_s)
    pyplot.xlabel('Std Dev height (cm)')
    pyplot.ylabel('CDF')

    _05_myplot._save(root='bayes_height_marginals_%s' % suite.name)
예제 #11
0
def _make_figures(pool, firsts, others):
    """Creates several figures for the book."""

    # plot PMFs of birth weights for first babies and others
    _05_myplot._clf()
    _05_myplot._hist(firsts.weight_pmf, linewidth=0, color='blue')
    _05_myplot._hist(others.weight_pmf, linewidth=0, color='orange')
    _05_myplot._save(root='nsfg_birthwgt_pmf',
                     title='Birth weight PMF',
                     xlabel='weight (ounces)',
                     ylabel='probability')

    # plot CDFs of birth weights for first babies and others
    _05_myplot._clf()
    _05_myplot._cdf(firsts.weight_cdf, linewidth=2, color='blue')
    _05_myplot._cdf(others.weight_cdf, linewidth=2, color='orange')
    _05_myplot._save(root='nsfg_birthwgt_cdf',
                     title='Birth weight CDF',
                     xlabel='weight (ounces)',
                     ylabel='probability',
                     axis=[0, 200, 0, 1])
예제 #12
0
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",
    )
예제 #13
0
def _plot_coef_variation(suites):
    """
    Plot the posterior distributions for CV.

    Args:
        suites: map from label to Pmf of CVs.
    """
    pyplot.clf()

    pmfs = {}
    for label, suite in suites.iteritems():
        pmf = _compute_coef_variation(suite)
        cdf = _13_Cdf._make_cdf_from_pmf(pmf, label)
        _05_myplot._cdf(cdf)

        pmfs[label] = pmf

    _05_myplot._save(root='bayes_height_cv',
                     title='Coefficient of variation',
                     xlabel='cv',
                     ylabel='CDF')

    print('female bigger', _prob_bigger(pmfs['female'], pmfs['male']))
    print('male bigger', _prob_bigger(pmfs['male'], pmfs['female']))
예제 #14
0
def main(script):
    # read 'em and sort 'em
    birthdays = _read_birthdays()
    birthdays.sort()

    # compute the intervals in days
    deltas = _diff(birthdays)
    days = [inter.days for inter in deltas]

    # make and plot the CCDF on a log scale.
    cdf = _13_Cdf._make_cdf_from_list(days, name='intervals')
    scale = _05_myplot._cdf(cdf, transform='exponential')
    _05_myplot._save(root='intervals',
                     xlabel='days',
                     ylabel='ccdf',
                     **scale)
예제 #15
0
def _make_figures():
    pops = _21_populations._read_data()
    print(len(pops))

    cdf = _13_Cdf._make_cdf_from_list(pops, 'populations')

    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(root='populations',
                     title='City/Town Populations',
                     xlabel='population',
                     ylabel='CDF',
                     legend=False)

    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(root='populations_logx',
                     title='City/Town Populations',
                     xlabel='population',
                     ylabel='CDF',
                     xscale='log',
                     legend=False)

    _05_myplot._clf()
    _05_myplot._cdf(cdf, complement=True)
    _05_myplot._save(root='populations_loglog',
                     title='City/Town Populations',
                     xlabel='population',
                     ylabel='Complementary CDF',
                     yscale='log',
                     xscale='log',
                     legend=False)

    t = [math.log(x) for x in pops]
    t.sort()
    _17_rankit._make_normal_plot(t, 'populations_rankit')