Exemplo n.º 1
0
def plotCoefVariation(suites):
    """Plot the posterior distributions for CV.

    suites: map from label to Pmf of CVs.
    """
    thinkplot.clf()
    thinkplot.prePlot(num=2)

    pmfs = {}
    for label, suite in suites.iteritems():
        pmf = coefVariation(suite)
        print('CV posterior mean', pmf.mean())
        cdf = thinkbayes.makeCdfFromPmf(pmf, label)
        thinkplot.cdf(cdf)

        pmfs[label] = pmf

    thinkplot.save(root='variability_cv',
                   xlabel='Coefficient of variation',
                   ylabel='Probability')

    print('female bigger',
          thinkbayes.pmfProbGreater(pmfs['female'], pmfs['male']))
    print('male bigger', thinkbayes.pmfProbGreater(pmfs['male'],
                                                   pmfs['female']))
Exemplo n.º 2
0
    def makePlot(self, root='redline4'):
        """Makes a plot showing the mixture."""
        thinkplot.clf()

        # plot the MetaPmf
        for pmf, prob in sorted(self.metaPmf.items()):
            cdf = pmf.makeCdf().scale(1.0 / 60)
            width = 2 / math.log(-math.log(prob))
            thinkplot.plot(cdf.xs,
                           cdf.ps,
                           alpha=0.2,
                           linewidth=width,
                           color='blue',
                           label='')

        # plot the mixture and the distribution based on a point estimate
        thinkplot.prePlot(2)
        #thinkplot.Cdf(self.point.MakeCdf(name='point').Scale(1.0/60))
        thinkplot.cdf(self.mixture.makeCdf(name='mix').scale(1.0 / 60))

        thinkplot.save(root=root,
                       xlabel='Wait time (min)',
                       ylabel='CDF',
                       formats=FORMATS,
                       axis=[0, 10, 0, 1])
def makePosteriorPlot(suite):
    """Plots the posterior marginal distributions for alpha and beta.

    suite: posterior joint distribution of location
    """
    marginal_alpha = suite.marginal(0)
    marginal_alpha.name = 'PMF(alpha)'
    marginal_beta = suite.marginal(1)
    marginal_beta.name = 'PMF(beta)'

    print("\n(ALPHA, BETA): Shooter locations: ")
    print('alpha CI', marginal_alpha.credibleInterval(50))
    print('beta CI', marginal_beta.credibleInterval(50))

    thinkplot.prePlot(num=2)

    #thinkplot.Pmf(marginal_alpha)
    #thinkplot.Pmf(marginal_beta)

    thinkplot.cdf(thinkbayes.makeCdfFromPmf(marginal_alpha))
    thinkplot.cdf(thinkbayes.makeCdfFromPmf(marginal_beta))

    thinkplot.save('paintball2_posteriorMarginalDist_for_alpha_and_beta',
                   xlabel='Distance',
                   ylabel='Prob',
                   loc=4,
                   formats=FORMATS)
Exemplo n.º 4
0
 def makePlot(self):
     """Plot the CDFs."""
     thinkplot.cdf(self.pmf_y.makeCdf())
     thinkplot.cdf(self.prior_zb.makeCdf())
     thinkplot.cdf(self.post_zb.makeCdf())
     thinkplot.cdf(self.pmf_mean_zb.makeCdf())
     thinkplot.show()
Exemplo n.º 5
0
def plotPriorDist(pmf):
    """Plot the prior distribution of p_correct.

    pmf: prior
    """
    thinkplot.clf()
    thinkplot.prePlot(num=1)

    cdf1 = thinkbayes.makeCdfFromPmf(pmf, 'prior')
    thinkplot.cdf(cdf1)
    thinkplot.save(root='sat_1_prior',
                   xlabel='p_correct',
                   ylabel='CDF',
                   formats=['pdf'])  # ['pdf', 'eps'])
Exemplo n.º 6
0
def plotCdfs(d, labels):
    """Plot CDFs for each sequence in a dictionary.

    Jitters the data and subtracts away the mean.

    d: map from key to sequence of values
    labels: map from key to string label
    """
    thinkplot.clf()
    for key, xs in d.iteritems():
        mu = thinkstats.mean(xs)
        xs = thinkstats.jitter(xs, 1.3)
        xs = [x - mu for x in xs]
        cdf = thinkbayes.makeCdfFromList(xs)
        thinkplot.cdf(cdf, label=labels[key])
    thinkplot.show()
Exemplo n.º 7
0
def MakeNormalModel(weights):
    """Plots a CDF with a Normal model.

    weights: sequence
    """
    cdf = thinkbayes2.Cdf(weights, label='weights')

    mean, var = thinkbayes2.TrimmedMeanVar(weights)
    std = math.sqrt(var)
    print('n, mean, std', len(weights), mean, std)

    xmin = mean - 4 * std
    xmax = mean + 4 * std

    xs, ps = thinkbayes2.RenderNormalCdf(mean, std, xmin, xmax)
    thinkplot.plot(xs, ps, label='model', linewidth=4, color='0.8')
    thinkplot.cdf(cdf)
Exemplo n.º 8
0
def plotMarginals(suite):
    """Plots marginal distributions from a joint distribution.

    suite: joint distribution of mu and sigma.
    """
    thinkplot.clf()

    pyplot.subplot(1, 2, 1)
    pmf_m = suite.marginal(0)
    cdf_m = thinkbayes.makeCdfFromPmf(pmf_m)
    thinkplot.cdf(cdf_m)

    pyplot.subplot(1, 2, 2)
    pmf_s = suite.marginal(1)
    cdf_s = thinkbayes.makeCdfFromPmf(pmf_s)
    thinkplot.cdf(cdf_s)

    thinkplot.show()
Exemplo n.º 9
0
    def calibrateDifficulty(self):
        """Make a plot showing the model distribution of raw scores."""
        thinkplot.clf()
        thinkplot.prePlot(num=2)

        cdf = thinkbayes.makeCdfFromPmf(self.raw, name='data')
        thinkplot.cdf(cdf)

        efficacies = thinkbayes.makeGaussianPmf(0, 1.5, 3)
        pmf = self.makeRawScoreDist(
            efficacies)  # mixture model of raw score, prob = p1 * p2
        cdf = thinkbayes.makeCdfFromPmf(pmf, name='model')
        thinkplot.cdf(cdf)

        thinkplot.save(root='sat_2_calibrate',
                       xlabel='raw score',
                       ylabel='CDF',
                       formats=['pdf'])