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 thinkbayes
11
import thinkplot
12
13
14
"""This file contains a partial solution to a problem from
15
MacKay, "Information Theory, Inference, and Learning Algorithms."
16
17
Exercise 3.15 (page 50): A statistical statement appeared in
18
"The Guardian" on Friday January 4, 2002:
19
20
When spun on edge 250 times, a Belgian one-euro coin came
21
up heads 140 times and tails 110. 'It looks very suspicious
22
to me,' said Barry Blight, a statistics lecturer at the London
23
School of Economics. 'If the coin weere unbiased, the chance of
24
getting a result as extreme as that would be less than 7%.'
25
26
MacKay asks, "But do these data give evidence that the coin is biased
27
rather than fair?"
28
29
"""
30
31
class Euro(thinkbayes.Suite):
32
33
def Likelihood(self, data, hypo):
34
"""Computes the likelihood of the data under the hypothesis.
35
36
hypo: integer value of x, the probability of heads (0-100)
37
data: string 'H' or 'T'
38
"""
39
x = hypo / 100.0
40
if data == 'H':
41
return x
42
else:
43
return 1-x
44
45
46
def main():
47
suite = Euro(range(0, 101))
48
49
suite.Update('H')
50
51
thinkplot.Pdf(suite)
52
thinkplot.Show(xlabel='x',
53
ylabel='Probability',
54
legend=False)
55
56
57
if __name__ == '__main__':
58
main()
59
60