Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/thinkbayes2
Path: blob/master/scripts/effect.py
1901 views
1
"""This file contains code used in "Think Bayes",
2
by Allen B. Downey, available from greenteapress.com
3
4
Copyright 2014 Allen B. Downey
5
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
6
"""
7
8
from __future__ import print_function, division
9
10
from variability import *
11
12
import thinkplot
13
import thinkbayes2
14
15
16
def RunEstimate(update_func, num_points=31, median_flag=False):
17
"""Runs the whole analysis.
18
19
update_func: which of the update functions to use
20
num_points: number of points in the Suite (in each dimension)
21
"""
22
d = ReadHeights(nrows=None)
23
labels = {1:'male', 2:'female'}
24
25
suites = {}
26
for key, xs in d.items():
27
label = labels[key]
28
print(label, len(xs))
29
Summarize(xs)
30
31
xs = thinkbayes2.Jitter(xs, 1.3)
32
33
mus, sigmas = FindPriorRanges(xs, num_points, median_flag=median_flag)
34
suite = Height(mus, sigmas, label)
35
suites[label] = suite
36
update_func(suite, xs)
37
print('MAP', suite.MaximumLikelihood())
38
39
# joint distributions of mu and sigma for men and women
40
suite1 = suites['male']
41
suite2 = suites['female']
42
43
# TODO: compute and plot the distribution of d
44
45
46
def main():
47
random.seed(17)
48
49
func = UpdateSuite5
50
median_flag = (func == UpdateSuite5)
51
RunEstimate(func, median_flag=median_flag)
52
53
54
if __name__ == '__main__':
55
main()
56
57
58
59