示例#1
0
def main():

    all_births, first_births, later_births = descriptive.MakeTables()
    later_births.pmf.name = 'other babies'

    print " All births:   early   = {:.1%}".format(ProbEarly(all_births.pmf))
    print "               on-time = {:.1%}".format(ProbOnTime(all_births.pmf))
    print "               late    = {:.1%}".format(ProbLate(all_births.pmf))

    PrintRelativeRisks(first_births.pmf, later_births.pmf)
示例#2
0
    def testVar(self):
        pool, firsts, others = descriptive.MakeTables()
        descriptive.Process(pool, 'Live births')
        descriptive.Process(firsts, 'First babies')
        descriptive.Process(others, 'Others')

        self.assertAlmostEquals(firsts.var, 7.79294720207)
        self.assertAlmostEquals(others.var, 6.84123839078)

        self.assertAlmostEquals(pool.mu, 38.5605596852)
        self.assertAlmostEquals(pool.var, 7.3018637882)
示例#3
0
def main():
    """
    <39
    """
    pool, firsts, others = descriptive.MakeTables("res")
    pmf = pool.pmf
    print("before pro(39) = ", pmf.Prob(39))
    for v in range(0, 39):
        try:
            pmf.Remove(v)
        except Exception as e:
            continue
    pmf.Normalize()
    print("after pro(39) = ", pmf.Prob(39))
示例#4
0
import descriptive
import Pmf


def filtered_pmf(filter_function, pmf):
    filtered_items = filter(filter_function, pmf.Items())
    filtered_pmf = Pmf.MakePmfFromDict(dict(filtered_items))
    filtered_pmf.Normalize()
    return filtered_pmf


def prob_birth_in_next_week(week, pmf):
    new_pmf = filtered_pmf(lambda x: x[0] > week, pmf)
    return new_pmf.Prob(week + 1)


pool, firsts, others = descriptive.MakeTables()
later_first_births = prob_birth_in_next_week(38, firsts.pmf)
later_other_births = prob_birth_in_next_week(38, others.pmf)

print 'chance of first birth in week 39 %f' % later_first_births
print 'chance of other birth in week 39 %f' % later_other_births
示例#5
0
def main():
    pool, firsts, others = descriptive.MakeTables()

    ComputeRelativeRisk(firsts.pmf, others.pmf)
def main():
    # get the data
    pool, firsts, others = descriptive.MakeTables()
    Test(pool, firsts, others, num_trials=1000)
示例#7
0
def main():
    pool, firsts, others = descriptive.MakeTables(data_dir='./dataset')
    RelativeRisk(firsts, others)
    MakeFigure(firsts, others)
示例#8
0
def main():
    pool, firsts, others = descriptive.MakeTables(data_dir='./dataset')

    ComputeRelativeRisk(firsts.pmf, others.pmf)
示例#9
0
def main():
    pool, firsts, others = descriptive.MakeTables()
    RelativeRisk(firsts, others)
    MakeFigure(firsts, others)
示例#10
0
def main():
    pool, firsts, others = descriptive.MakeTables()
    first_cond, other_cond = RelativeRisk(firsts, others)
    MakeFigurePmf(first_cond, other_cond)
示例#11
0
def main():
    pool, firsts, others = descriptive.MakeTables()
    firsts.pmf.name = "first"
    print "Probabilty at 39 weeks for first baby: {:.1%}".format(CondPmf(firsts.pmf,39).Prob(39))
    print "Probabilty at 39 weeks for later babies: {:.1%}".format(CondPmf(others.pmf,39).Prob(39))
    ShowPlot(firsts, others)