Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Repository for a workshop on Bayesian statistics

1430 views
1
"""This file contains code used in "Think Stats",
2
by Allen B. Downey, available from greenteapress.com
3
4
Copyright 2013 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
import math
11
import numpy
12
13
from matplotlib import pyplot
14
15
import thinkplot
16
import thinkbayes2
17
18
19
def RenderPdf(mu, sigma, n=101):
20
"""Makes xs and ys for a normal PDF with (mu, sigma).
21
22
n: number of places to evaluate the PDF
23
"""
24
xs = numpy.linspace(mu-4*sigma, mu+4*sigma, n)
25
ys = [thinkbayes2.EvalNormalPdf(x, mu, sigma) for x in xs]
26
return xs, ys
27
28
29
def main():
30
xs, ys = RenderPdf(100, 15)
31
32
n = 34
33
pyplot.fill_between(xs[-n:], ys[-n:], y2=0.0001, color='blue', alpha=0.2)
34
s = 'Congratulations!\nIf you got this far,\nyou must be here.'
35
d = dict(shrink=0.05)
36
pyplot.annotate(s, [127, 0.002], xytext=[80, 0.005], arrowprops=d)
37
38
thinkplot.Plot(xs, ys)
39
thinkplot.Show(title='Distribution of IQ',
40
xlabel='IQ',
41
ylabel='PDF',
42
legend=False)
43
44
45
if __name__ == "__main__":
46
main()
47
48