Пример #1
0
def draw_hist(d):
    table = survey.Pregnancies()
    table.ReadRecords(d)
    first, other = ch1.partition_births(table)
    first_preg = [rec.prglength for rec in first.records]
    other_preg = [rec.prglength for rec in other.records]
    l1 = sns.distplot(first_preg, kde=False)
    l2 = sns.distplot(other_preg, kde=False)
    plt.legend(['first', 'other'], loc=2)
    plt.show()
Пример #2
0
def draw_hist(d):
    table = survey.Pregnancies()
    table.ReadRecords(d)
    first, other = ch1.partition_births(table)
    first_preg = np.array([rec.prglength for rec in first.records])
    other_preg = np.array([rec.prglength for rec in other.records])
    pmf_first = Pmf.MakePmfFromList(first_preg)
    pmf_other = Pmf.MakePmfFromList(other_preg)
    x = [i for i in range(34, 47)]
    y1 = [cond_born(pmf_first, i) for i in range(34, 47)]
    y2 = [cond_born(pmf_other, i) for i in range(34, 47)]
    l1 = plt.plot(x, y1)
    l2 = plt.plot(x, y2)
    plt.legend(['first', 'other'], loc=2)
    plt.show()
Пример #3
0
    first_pmf: Pmf object
    other_pmf: Pmf object
    """
    print "Risks:"
    funcs = [probEarly, probOnTime, probLate]
    risks = {}
    for func in funcs:
        for pmf in [first_pmf, other_pmf]:
            prob = func(pmf)
            risks[func.__name__, pmf.name] = prob
            print func.__name__, pmf.name, prob

    print
    print "Risk ratios (first babies / others):"
    for func in funcs:
        try:
            ratio = risks[func.__name__, "first babies"] / risks[func.__name__, "others"]
            print func.__name__, ratio
        except ZeroDivisionError:
            pass


if __name__ == "__main__":
    table = survey.Pregnancies()
    table.ReadRecords(sys.argv[1])
    first, other = ch1.partition_births(table)
    pmf_first = Pmf.MakePmfFromList((rec.prglength for rec in first.records), "first babies")
    pmf_other = Pmf.MakePmfFromList((rec.prglength for rec in other.records), "others")
    ComputeRelativeRisk(pmf_first, pmf_other)