Skip to main content
Think Bayes
Bayesian Statistics in Python
Allen B. Downey
Contents
Search Book
close
Search Results:
No results.
Dark Mode
Prev
Up
Next
\(\newcommand{\N}{\mathbb N} \newcommand{\Z}{\mathbb Z} \newcommand{\Q}{\mathbb Q} \newcommand{\R}{\mathbb R} \newcommand{\lt}{<} \newcommand{\gt}{>} \newcommand{\amp}{&} \definecolor{fillinmathshade}{gray}{0.9} \newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}} \)
Front Matter
Colophon
Preface
Note on This PreTeXt Edition
1
Probability
1.1
Linda the Banker
1.2
Probability
1.3
Fraction of Bankers
1.4
The Probability Function
1.5
Political Views and Parties
1.6
Conjunction
1.7
Conditional Probability
1.8
Conditional Probability Is Not Commutative
1.9
Condition and Conjunction
1.10
Laws of Probability
1.10.1
Theorem 1
1.10.2
Theorem 2
1.10.3
Theorem 3
1.11
The Law of Total Probability
1.12
Summary
1.13
Exercises
2
Bayes’s Theorem
2.1
The Cookie Problem
2.2
Diachronic Bayes
2.3
Bayes Tables
2.4
The Dice Problem
2.5
The Monty Hall Problem
2.6
Summary
2.7
Exercises
3
Distributions
3.1
Distributions
3.2
Probability Mass Functions
3.3
The Cookie Problem Revisited
3.4
101 Bowls
3.5
The Dice Problem
3.6
Updating Dice
3.7
Summary
3.8
Exercises
4
Estimating Proportions
4.1
The Euro Problem
4.2
The Binomial Distribution
4.3
Bayesian Estimation
4.4
Triangle Prior
4.5
The Binomial Likelihood Function
4.6
Bayesian Statistics
4.7
Summary
4.8
Exercises
5
Estimating Counts
5.1
The Train Problem
5.2
Sensitivity to the Prior
5.3
Power Law Prior
5.4
Credible Intervals
5.5
The German Tank Problem
5.6
Informative Priors
5.7
Summary
5.8
Exercises
6
Odds and Addends
6.1
Odds
6.2
Bayes’s Rule
6.3
Oliver’s Blood
6.4
Addends
6.5
Gluten Sensitivity
6.6
The Forward Problem
6.7
The Inverse Problem
6.8
Summary
6.9
Exercises
7
Minimum, Maximum, and Mixture
7.1
Cumulative Distribution Functions
7.2
Best Three of Four
7.3
Maximum
7.4
Minimum
7.5
Mixture
7.6
General Mixtures
7.7
Summary
7.8
Exercises
8
Poisson Processes
8.1
The World Cup Problem
8.2
The Poisson Distribution
8.3
The Gamma Distribution
8.4
The Update
8.5
Probability of Superiority
8.6
Predicting the Rematch
8.7
The Exponential Distribution
8.8
Summary
8.9
Exercises
9
Decision Analysis
9.1
The Price Is Right Problem
9.2
The Prior
9.3
Kernel Density Estimation
9.4
Distribution of Error
9.5
Update
9.6
Probability of Winning
9.7
Decision Analysis
9.8
Maximizing Expected Gain
9.9
Summary
9.10
Discussion
9.11
Exercises
10
Testing
10.1
Estimation
10.2
Evidence
10.3
Uniformly Distributed Bias
10.4
Bayesian Hypothesis Testing
10.5
Bayesian Bandits
10.6
Prior Beliefs
10.7
The Update
10.8
Multiple Bandits
10.9
Explore and Exploit
10.10
The Strategy
10.11
Summary
10.12
Exercises
10.13
Simulating the Test
10.14
The Prior
10.15
The Update
10.16
Adaptation
10.17
Quantifying Precision
10.18
Discriminatory Power
11
Comparison
11.1
Outer Operations
11.2
How Tall Is A?
11.3
Joint Distribution
11.4
Visualizing the Joint Distribution
11.5
Likelihood
11.6
The Update
11.7
Marginal Distributions
11.8
Conditional Posteriors
11.9
Dependence and Independence
11.10
Summary
11.11
Exercises
12
Classification
12.1
Penguin Data
12.2
Normal Models
12.3
The Update
12.4
Naive Bayesian Classification
12.5
Joint Distributions
12.6
Multivariate Normal Distribution
12.7
Visualizing a Multivariate Normal Distribution
12.8
A Less Naive Classifier
12.9
Summary
12.10
Exercises
13
Inference
13.1
Improving Reading Ability
13.2
Estimating Parameters
13.3
Likelihood
13.4
Posterior Marginal Distributions
13.5
Distribution of Differences
13.6
Using Summary Statistics
13.7
Update with Summary Statistics
13.8
Comparing Marginals
13.9
Proof By Simulation
13.10
Checking Standard Deviation
13.11
Summary
13.12
Exercises
14
Survival Analysis
14.1
The Weibull Distribution
14.2
Marginal Distributions
14.3
Incomplete Data
14.4
Using Incomplete Data
14.5
Light Bulbs
14.6
Posterior Means
14.7
Incomplete Information
14.8
Posterior Predictive Distribution
14.9
Summary
14.10
Exercises
15
Mark and Recapture
15.1
The Grizzly Bear Problem
15.2
The Update
15.3
Two-Parameter Model
15.4
The Prior
15.5
The Update
15.6
Joint and Marginal Distributions
15.7
The Lincoln Index Problem
15.8
Three-Parameter Model
15.9
Summary
15.10
Exercises
16
Logistic Regression
16.1
Log Odds
16.2
The Space Shuttle Problem
16.3
Prior Distribution
16.4
Likelihood
16.5
The Update
16.6
Marginal Distributions
16.7
Transforming Distributions
16.8
Predictive Distributions
16.9
Empirical Bayes
16.10
Summary
16.11
Exercises
17
Regression
17.1
More Snow?
17.2
Regression Model
17.3
Least Squares Regression
17.4
Priors
17.5
Likelihood
17.6
The Update
17.7
Optimization
17.8
Marathon World Record
17.9
The Priors
17.10
Prediction
17.11
Summary
17.12
Exercises
18
Conjugate Priors
18.1
The World Cup Problem Revisited
18.2
The Conjugate Prior
18.3
What the Actual?
18.4
Binomial Likelihood
18.5
Lions and Tigers and Bears
18.6
The Dirichlet Distribution
18.7
Summary
18.8
Exercises
19
MCMC
19.1
The World Cup Problem
19.2
Grid Approximation
19.3
Prior Predictive Distribution
19.4
Introducing PyMC3
19.5
Sampling the Prior
19.6
When Do We Get to Inference?
19.7
Posterior Predictive Distribution
19.8
Happiness
19.9
Simple Regression
19.10
Multiple Regression
19.11
Summary
19.12
Exercises
20
Approximate Bayesian Computation
20.1
The Kidney Tumor Problem
20.2
A Simple Growth Model
20.3
A More General Model
20.4
Simulation
20.5
Approximate Bayesian Calculation
20.6
Counting Cells
20.7
Cell Counting with ABC
20.8
When Do We Get to the Approximate Part?
20.9
Summary
20.10
Exercises
Examples
A
The Red Line Problem
A.1
The Update
A.2
Elapsed time
A.3
Counting passengers
A.4
Wait time
A.5
Decision analysis
B
The Red Line Problem: A PyMC Approach
B.1
Length-Biased Sampling
B.2
Model 1: KDE Prior of Gap Times
B.3
Model 2: Normal Prior of Gap Times
B.4
Model 3: Lognormal Prior of Gap Times
B.5
Model 4: Gamma Prior of Rates
B.6
Model 5: Log-t Prior of Gap Times
B.7
Run the Model
B.8
Correlations
B.9
Run with a Range of
\(n\)
B.10
Plot Results
B.11
All Models
C
Estimating vaccine efficacy
C.1
The Data
C.2
The Beta Distribution
C.3
Computing Efficacy
D
Flipping USB Connectors
D.1
Continuous Updates
D.2
Generalization
D.3
Strategy
D.4
Simulation
D.5
Optimization
D.6
How many flips?
D.7
Summary
E
The Left Handed Sister Problem
E.1
Constructing the prior
E.2
The first update
E.3
The second update
E.4
Probability of a left-handed sister
E.5
The Bayes factor
F
Bayesian Dice
F.1
Computing likelihoods
F.2
The Update
G
The Emitter-Detector Problem
G.1
First update
G.2
Jeffreys prior
G.3
Robot A
G.4
Robot B
G.5
Going the other way
H
Grid Algorithms for Hierarchical Models
H.1
Heart Attack Data
H.2
Solution with PyMC
H.3
The grid priors
H.4
The joint distribution of hyperparameters
H.5
Joint prior of hyperparameters and x
H.6
The Update
H.7
Serial updates
H.8
Parallel updates
H.9
Compute all marginals
I
Comparing Birth Rates
J
How Many Typos?
J.1
A Warm-up Problem
J.2
The Prior
J.3
The Update (Simple Version)
J.4
Three-Parameter Model
J.5
The Joint Prior
J.6
The Update (Three-Parameter Version)
K
How Many Books?
K.1
Priors
K.2
The update
K.3
Optimization
L
The All-Knowing Cube of Probability
L.1
Making the cube
L.2
The binomial distribution
L.3
The negative binomial distribution
L.4
The beta distribution
L.5
Conjugate priors
L.6
Update with nbinom
L.7
Posterior predictive distributions
L.8
The other posterior predictive
M
What’s a Chartist?
M.1
Word Frequencies
M.2
Zipf’s Law
M.3
Tail Distribution
M.4
Fitting a Model
M.5
The Update
N
The Poincaré Problem
N.1
Ask a Bayesian
O
Cancer Survival Rates Are Misleading
O.1
Particularization
O.2
Is More Screening Better?
O.3
Data
O.4
Markov Model
O.5
Simulation
O.6
Counterfactuals
O.7
Comparing Survival Rates
O.8
Summary
O.9
Markov Analysis with PyMC
P
The Raven Paradox
P.1
The Problem
P.2
The Setup
P.3
The Math
P.4
Scenario 1
P.5
Scenario 2
P.6
Scenario 3
P.7
Scenario 4
P.8
Successive Updates
P.9
Varying
\(M\)
P.10
Conclusion
P.11
Symmetry and Asymmetry
P.12
Related Reading
P.13
Objections
Q
The Frog Puzzle
Q.1
Only Male Frogs Croak
Q.2
Poisson (not Poison) Frogs
Q.3
Female Frogs Croak, Too
Q.4
Assortative Mating
Q.5
Discussion
Colophon
Colophon
Colophon
Website
Think Bayes 2
©2021–2026 Allen B. Downey
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit
CreativeCommons.org
🔗