Table of Contents
Acknowledgments xv
Introduction XVII
Why Learn Statistics? xviii
What Is "Bayesian" Statistics? xix
What's in This Book xix
Part I Introduction to Probability xix
Part II Bayesian Probability and Prior Probabilities xx
Part III Parameter Estimation xxi
Part IV Hypothesis Testing: The Heart of Statistics xxi
Background for Reading the Book xxii
Now Off on Your Adventure! xxii
Part I Introduction to Probability
1 Bayesian Thinking and Everyday Reasoning 3
Reasoning About Strange Experiences 4
Observing Data 4
Holding Prior Beliefs and Conditioning Probabilities 5
Forming a Hypothesis 6
Spotting Hypotheses in Everyday Speech 8
Gathering More Evidence and Updating Your Beliefs 8
Comparing Hypotheses 9
Data Informs Belief; Belief Should Not Inform Data 10
Wrapping Up 11
Exercises 11
2 Measuring Uncertainty 13
What is a Probability? 14
Calculating Probabilities by Counting Outcomes of Events 15
Calculating Probabilities as Ratios of Beliefs 16
Using Odds to Determine Probability 17
Solving for the Probabilities 17
Measuring Beliefs in a Coin Toss 18
Wrapping Up 19
Exercises 20
3 The Logic of Uncertainty 21
Combining Probabilities with AND 22
Solving a Combination of Two Probabilities 22
Applying the Product Rule of Probability 24
Example: Calculating the Probability of Being Late 25
Combining Probabilities with OR 26
Calculating OR for Mutually Exclusive Events 26
Using the Sum Rule for Non-Mutually Exclusive Events 28
Example: Calculating the Probability of Getting a Hefty Fine 29
Wrapping Up 30
Exercises 31
4 Creating a Binomial Probability Distribution 33
Structure of a Binomial Distribution 34
Understanding and Abstracting Out the Details of Our Problem 35
Counting Our Outcomes with the Binomial Coefficient 36
Combinatorics: Advanced Counting with the Binomial Coefficient 37
Calculating the Probability of the Desired Outcome 38
Example: Gacha Games 41
Wrapping Up 43
Exercises 43
5 The Beta Distribution 45
A Strange Scenario: Getting the Data 46
Distinguishing Probability, Statistics, and Inference 46
Collecting Data 46
Calculating the Probability of Probabilities 47
The Beta Distribution 50
Breaking Down the Probability Density Function 50
Applying the Probability Density Function to Our Problem 51
Quantifying Continuous Distributions with Integration 52
Reverse-Engineering the Gacha Game 53
Wrapping Up 55
Exercises 55
Part II Bayesian Probability and Prior Probabilities
6 Conditional Probability 59
Introducing Conditional Probability 60
Why Conditional Probabilities Are Important 60
Dependence and the Revised Rules of Probability 61
Conditional Probabilities in Reverse and Bayes' Theorem 62
Introducing Bayes' Theorem 64
Wrapping Up 65
Exercises 66
7 Bayes' Theorem with Lego 67
Working Out Conditional Probabilities Visually 70
Working Through the Math 71
Wrapping Up 72
Exercises 72
8 The Prior, Likelihood, and Posterior Of Bayes' Theorem 73
The Three Parts 74
Investigating the Scene of a Crime 74
Solving for the Likelihood 75
Calculating the Prior 75
Normalizing the Data 76
Considering Alternative Hypotheses 78
The Likelihood for Our Alternative Hypothesis 78
The Prior for Our Alternative Hypothesis 78
The Posterior for Our Alternative Hypothesis 79
Comparing Our Unnormalized Posteriors 80
Wrapping Up 81
Exercises 81
9 Bayesian Priors and Working with Probability Distributions 83
C-3PO's Asteroid Field Doubts 84
Determining C-3PO's Beliefs 84
Accounting for Han's Badassery 85
Creating Suspense with a Posterior 87
Wrapping Up 88
Exercises 89
Part III Parameter Estimation
10 Introduction to Averaging and Parameter Estimation 93
Estimating Snowfall 94
Averaging Measurements to Minimize Error 94
Solving a Simplified Version of Our Problem 95
Solving a More Extreme Case 97
Estimating the True Value with Weighted Probabilities 98
Defining Expectation, Mean, and Averaging 99
Means for Measurement vs. Means for Summary 100
Wrapping Up 101
Exercises 101
11 Measuring the Spread of Our Data 103
Dropping Coins in a Well 104
Finding the Mean Absolute Deviation 104
Finding the Variance 106
Finding the Standard Deviation 107
Wrapping Up 109
Exercises 109
12 The Normal Distribution 111
Measuring Fuses for Dastardly Deeds 112
The Normal Distribution 114
Solving the Fuse Problem 116
Some Tricks and Intuitions 118
"N Sigma" Events 120
The Beta Distribution and the Normal Distribution 121
Wrapping Up 122
Exercises 122
13 Tools of Parameter Estimation: The PDF, CDF, and Quantile Function 123
Estimating the Conversion Rate for an Email Signup List 124
The Probability Density Function 124
Visualizing and Interpreting the PDF 125
Working with the PDF in R 126
Introducing the Cumulative Distribution Function 127
Visualizing and Interpreting the CDF 130
Finding the Median 130
Approximating Integrals Visually 131
Estimating Confidence Intervais 132
Using the CDF in R 133
The Quantile Function 133
Visualizing and Understanding the Quantile Function 134
Calculating Quantiles in R 135
Wrapping Up 135
Exercises 136
14 Parameter Estimation with Prior Probabilities 137
Predicting Email Conversion Rates 138
Taking in Wider Context with Priors 139
Prior as a Means of Quantifying Experience 143
Is There a Fair Prior to Use When We Know Nothing? 144
Wrapping Up 146
Exercises 146
Part IV Hypothesis Testing: The Heart of Statistics
15 From Parameter Estimation to Hypothesis Testing: Building a Bayesian A/B Test 149
Setting Up a Bayesian A/B Test 150
Finding Our Prior Probability 150
Collecting Data 151
Monte Carlo Simulations 152
In How Many Worlds Is ? the Better Variant? 153
How Much Better Is Each Variant ? Than Each Variant A? 154
Wrapping Up 156
Exercises 156
16 Introduction to the Bayes Factor and Posterior Odds: The Competition Of Ideas 157
Revisiting Bayes' Theorem 158
Building a Hypothesis Test Using the Ratio of Posteriors 159
The Bayes Factor 159
Prior Odds 159
Posterior Odds 160
Wrapping Up 164
Exercises 165
17 Bayesian Reasoning in the Twilight Zone 167
Bayesian Reasoning in the Twilight Zone 168
Using the Bayes Factor to Understand the Mystic Seer 168
Measuring the Bayes Factor 169
Accounting for Prior Beliefs 170
Developing Our Own Psychic Powers 171
Wrapping Up 173
Exercises 173
18 When Data Doesn't Convince You 175
A Psychic Friend Rolling Dice 176
Comparing Likelihoods 176
Incorporating Prior Odds 177
Considering Alternative Hypotheses 178
Arguing with Relatives and Conspiracy Theorists 179
Wrapping Up 181
Exercises 181
19 From Hypothesis Testing to Parameter Estimation 183
Is the Carnival Game Really Fair? 184
Considering Multiple Hypotheses 186
Searching for More Hypotheses with R 186
Adding Priors to Our Likelihood Ratios 188
Building a Probability Distribution 190
From the Bayes Factor to Parameter Estimation 191
Wrapping Up 194
Exercises 194
A A Quick Introduction to R 195
R and RStudio 196
Creating an R Script 197
Basic Concepts in R 197
Data Types 197
Missing Values 200
Vectors 200
Functions 201
Basic Functions 202
Random Sampling 206
The runif() Function 206
The rnorm() Function 207
The sample() Function 207
Using set.seed() for Predictable Random Results 208
Defining Your Own Functions 209
Creating Basic Plots 210
Exercise: Simulating a Stock Price 213
Summary 214
B Enough Calculus to Get By 215
Functions 216
Determining How Far You've Run 217
Measuring the Area Under the Curve: The Integral 219
Measuring the Rate of Change: The Derivative 223
The Fundamental Theorem of Calculus 227
Index 229