Despite personal interests, I haven't had an opportunity to take coursework that approaches statistics from a specifically Bayesian perspective. I've been aware of Gelman et al.'s Bayesian Data Analysis (BDA) textbook, and have attempted to read it on my own, but its material is a bit steep.
With the intention of working my way up to reading BDA, I looked around for other options to get started. This led me to Bayes Rules! An Introduction to Applied Bayesian Modeling, by Alicia Johnson, Miles Ott, and Mine Dogucu. Unlike BDA, which is aimed at graduate students, Bayes Rules! is meant to be approachable for undergraduate students.
I've been gradually working through Bayes Rules! via its online website that the authors graciously provide to readers. I've found the textbook to be quite accessible and an enjoyable read, as far as textbooks go. For each chapter, I've been keeping notes and completing exercises to check my understanding of the material. At the time of writing, I've gone through chapters 1 through 8. This post is meant to summarize what I've learned up to this point, an attempt to write down what I think I can explain to others (in a condensed form).
Foundations: what is the task of "statistics"?
I'm going to follow the example of the authors of Bayes Rules!, and avoid spending time contrasting Bayesian and Frequentist approaches to statistics. Instead, I want to highlight the role that statistics serves within the tasks of scientific research, policy evaluation, forecasting, etc., and discuss how Bayesian methods fulfill goals within these domains.
At its deepest roots, statistics is a subdiscipline of applied mathematics that's historically tied to the work of governance and the analysis of economic production. Statistics is concerned with the task of counting and summary of events and processes (i.e., data analysis), in order to describe the state of our world and make qualified inferences about unknown quantities or events. Among its various tools, statistics is commonly associated with probability theory, the area of mathematics concerned with the study of randomness.
In the work of research or evaluation, statisticians are tasked with proposing and refining statistical models used to evaluate theoretical hypotheses, generate predictions, and explain (or simulate) real-world processes. For any Bayesian analysis, the starting point is the construction of a probability model.
What is a probability model?
We use probability models to mathematically represent a random process or experiment. An experiment can be something as simple as as a single throw of a die or coin flip, and as complicated as a voter's choice at the ballot box. Here we'll introduce a bit of notation. A probability model for an experiment consists of:
- a sample space, : the complete set of possible outcomes for an experiment,
- events, : subsets of outcomes in the sample space, and
- a probability measure, : a mathematical rule for assigning probability values to each event.
and must each satisfy a few crucial properties. First, must be what's called a -algebra. Unpacking this this definition is outside my current aims, so I'll greatly simplify it by saying it's a set of "non-pathological" or "nice" subsets of . Second, must behave in the following way:
- It can only return values between 0 and 1:
- The sample space itself has probability 1: .
- For any set of events that are pairwise disjoint, is countably additive:
Let's try to make this more concrete with an example. Let's assume we're assisting a teacher studying whether a particular pedagogy can help increase student reading rates. The teacher has started using the pedagogy in their classroom, and they plan to provide us with a dataset . Each records the number of books that student finished during September of the most recent school year. Using this information, let's construct a probability model for our study.
For each individual student, we're recording the count of books they report having finished reading. Thus, the possible outcomes that each could take (our sample space) is the set of positive integers, which we write as
The events in our sample space are subsets of , which we can often translate into natural language:
Lastly, to complete our probability model , we need a probability measure . One candidate is the Poisson distribution:
Adopting the Poisson distribution as our measure is equivalent to assuming that each is a draw from a Poisson distribution, which we write as In general, when we want to refer to a random variable being a draw from an arbitrary (possibly unnamed) distribution , we write .
Probability distributions have parameters that control their behavior, such as their center and spread. The Poisson distribution has a single parameter, which is customarily denoted by the greek letter (lambda). Here, is a rate (reflecting the average number of books completed in 30 days), and thus it's a real number that can take any value greater than 0. If we know or have a value for , we can compute the probabilities for different events. Say we knew that students finish an average of 3 books per month (which implies ). We could then calculate the probability of a student finishing 5 books:
We could also compute the probability of a student finishing less than 3 books:
The machine behind Bayesian inference: Bayes' Theorem
Everything in the preceding section is within the realm of probability theory. Probability theory gives us a notation for talking about outcomes and events, as well as a means to assign probability values to events in our sample space. However, in practice we're never handed the values of the parameters in our model. Instead, we collect (or receive) a dataset that has been sampled from the data generating process we're hoping to learn about:
It's from the collected data points that we produce estimates for . The process of producing estimates for unknown parameters using sample data falls within the general practice of statistical inference. For Bayesian inference, the machine that produces an estimate, which we refer to as a posterior distribution , is called Bayes' Theorem:
In natural language, you could read this expression as "the posterior distribution is equal to the product of the prior distribution and the data's likelihood, divided by the probability of the data." We'll see how we estimate a posterior distribution from our sample next, but it's worth noting a few aspects of this formula.
First, our estimate for is itself a probability distribution: . Translating this notation a bit, our posterior distribution is a function that produces values between 0 and 1 for each value of conditioning on collected data . This means that questions such as "what is the probability that is between 3 and 8?" can be calculated directly:
Second, Bayes' Theorem requires us to represent what we think we already know about , using a prior distribution . It's rare that we start from a state of pure ignorance about the processes we're interested in. We often have existing research or knowledge to draw upon, and this work can help us establish reasonable assumptions for the values we think could take. Philosophically, I don't think it's strictly necessary for a prior distribution to reflect one's absolute state of belief about the world. Instead, choices about prior distribuitions allow us to bring more/less informed (or skeptical) perspectives into our analyses in a way that's transparent.
Third, our understanding of is a reconciliation between our prior beliefs about and what is likely true about the world, given the data we have. At least for me, this is an appealing way of thinking about the task of inference. When we talk casually about learning, we usually have a notion of experience that's cumulative. Through study or practice, one might improve (or inadvertently, worsen) performance on a task or in their understanding of a topic. We're also used to assuming some level of rationality between different actors. That is, if people with different prior beliefs are presented with the same information, their understandings should eventually converge. Bayesian inference has the quality of embracing the sequential accumulation of data and convergence of beliefs. As we'll see, today's posterior distribution can just as easily be tomorrow's prior distribution.
Returning to our example: learning from collected data
Let's assume our colleague has provided us with the reading data for students in their classroom:
Previously, we established our probability model for this study, and adopted the Poisson distribution as our probability measure for our sample space. In observing the class, our colleague is confident that students are choosing books individually, and completing them on their own. That is, we can be reasonably sure that student 's habits are independent of those for any other student .
This assumption makes some of our computation much simpler. As part of our estimation, we need a joint likelihood function that measures how compatible values of are with our observations . If our sample data is independent, is simply the product of the Poisson probability mass function (p.m.f.) for each observation .
Let's write out what we know about our statistical model at this point:
All that's left is to choose a prior distribution, . In the above we have a stand-in, , but in order to find a posterior distribution we'll need to specify an actual probability density function to combine with our likelihood.
Picking a prior distribution: why we like conjugacy
In theory, we could pick any probability density function with a support of as our choice for . However, the Poisson distribution has a well-known relationship with the Gamma probability distribution. Specifically, the Gamma distribution is a conjugate distribution for the Poisson. In this context, conjugacy means that the posterior model is a member of the same model family as the prior.
In particular, we'll aim to show the following claim: .
As we can see, the kernel of has the same dependency on as that of the prior . After removing constants from the expression, they both take the form of , i.e., the form used by the Gamma distribution. Aside from the Gamma-Poisson model we're discussing, several well-known models have conjugate priors, including the Beta-Binomial, and the Normal-Normal models. A key part of their attractiveness is that they greatly simplify the computational work needed to derive the posterior distribution. In our case, we merely need to have values for and .
It might be that I need multiple descriptions in order to grasp a concept, but the way that prior/posterior conjugacy is explained in Bayes Rules! is done well. In chapters 3 and 5, for each conjugate family discussed, the authors carefully walk step through the product of the prior/likelihood (as I did above) to illustrate how the structure (kernel) of the prior is preserved. In practice, conjugacy gives us nice formulas for updating a prior distribution with data, but Bayes Rules! helped me understand where these mechanics come from.
Tuning our prior based on existing information
Based on our colleague's preliminary research about the pedagogy being implemented, they have some bounds for that can inform our analysis. In other classes that have implemented this pedagogy, students finish about 1.5 books in a monthly period. Further, only about 5% of studies in the literature show completion rates under 1. We can use this empirical information to specify the values for our prior distribution's hyperparameters: and .
Using the sliders below, you can adjust and to change the shape of of the curve. A specification that matches our example colleague's review of the literature, Gamma(22.25, 15), is rendered as a dashed line.
E(λ) = αâÎČ = 1.0, P(λ †1) = 0.56, P(1 †λ †2) = 0.41
Based on the needs or information provided by our colleague, various choices could be chosen for and to reflect a point of view before we observe data. For example, if our colleague believed that the literature was too optimistic and wanted to give it less weight, we could pick Gamma(7.5, 5) as a choice that keeps the same mean, but allows for more variability.
Summarizing the posterior distribution and hypothesis testing
Now that we have a (conjugate) prior in hand, we can combine it with our observed data to analyze our study's posterior distribution:
Plotting our (scaled) likelihood, prior, and posterior together as curves, we can see that the posterior distribution is a compromise between the sample data's likelihood and our prior. The likelihood function shows the values of that our data is most compatible with. However, our posterior combines our sample's information with what we knew prior to data collection. Our results indicate that students in this class are finishing close to 1.3 books in a month, a bit lower than what we'd expect from the literature.
We can also compute a range of plausible values for , called a credible interval. In our case, the 95% credible interval for is [0.98, 1.7]. This credible interval is a range of values that satisfies
In evaluating the pedagogy based on our (small) sample, we can compute a few additional summaries. First, our colleague is interested in knowing whether students learning under this approach are finishing more books than the district's average. Drawing from survey data, the district's best guess is that students at the same grade level in this school's district are completing around 1 book per month. Based on our posterior distribution, we have
Being able to answer our colleague's question in a straightforward fashion is an appealing aspect of Bayesian inference. We don't even need to evaluate the integral by hand, 1 - pgamma(1, 51.25, 39) in R is enough to answer our question. In light of the data we currently have, our teacher has directional evidence that the pedagogy is associated with their students finishing more books. The results would be more compelling if we had data from another class that wasn't using the pedagogy or data from the class before the new approach. Without a comparison, we can't rule out other factors that might explain the improved reading rates. For example, our colleague might simply be effective at motivating their students and the pedagogy's benefits are negligible. However, they could be encouraging if other teachers were interested in exploring its use.
Another way we could summarize this result is by using the prior and posterior odds. These summaries are probability ratios of an alternative hypothesis versus a null hypothesis , using the prior and posterior distributions, respectively. What we can see is that both our prior and posterior odds greatly favor the claim that , given that each of their values is above 1.0. In conversing with our colleague, we'd say that our data suggests that the alternative hypothesis is about 27 times more likely than the null. Finally, we can compute the Bayes factor, which is a ratio of the prior and posterior odds. This value summarizes how our understanding of has adjusted after observing the data. In our case, the value is less than 1.0, indicating the plausability of decreased slightly. Phrased differently, our choice for the prior was more optimistic about the plausability of , and our collected data makes this hypothesis less convincing.
Yesterday's posterior, today's prior
To conclude, we'll look at how sequentially arriving data can be smoothly incorporated into an updated analysis. Let's assume our colleague has collected another month of reading data from their students:
As with our initial analysis, each observation is a count of the books finished by student , so we can continue to use the Poisson likelihood. Additionally, rather than starting from scratch, we can use our posterior from September as our new prior distribution. Our updated posterior distribution is calculated via conjugacy:
Based on the posterior distribution, the expected value for is 1.35, slightly higher than what we saw in the first month of data. Our 95% credible interval is [1.1, 1.7], rounding to the first digit. Running our hypothesis tests again, our posterior odds are
with a corresponding Bayes factor of 8.24. Again, while we lack the ability to say whether the new pedagogy is responsible for changes in the students' reading habits, we have evidence that the averge number of books being completed is increasing and that our hypothesis that is more plausible with an additional month of data.
In summary
In writing this post, I've roughly followed the trajectory that the authors take in Bayes Rules!, with some small departures and a limitation to using one example across each section. Out of the many things I've gained from reading the textbook, I feel I've gained an appreciation for how helpful and important it is to mathematically specify the models that you're making use of. Once you've written the down names of your priors/likelihoods/posteriors, you're that much closer to visualizing and simulating them.
Additionally, having worked through a number of examples at this point, I've enjoyed the pragmatic feel of the Bayesian approach. We need ways to incorporate existing information we have before data is collected, and it's not uncommon for our analyses to be updated with future waves of data. In my experience, these problems don't have the most comfortable solutions within a Frequentist approach. It feels clean to write out a prior distribution; the fact that it can be debated or critiqued is an upside! The cumulative nature of Bayesian inference is also reassuring; regardless of how/when data might arrive, you'll reach the same posterior distribution when the final dataset is analyzed.
I'm looking forward to finishing the rest of the book. The coming chapters focus on regression modeling, including hierarchical regression models. The latter is something I've seen numerous practitioners note as being easier to specify within the Bayesian approach, so I'm excited to see how the authors handle this topic.