chapter thirteen

13 Conditional probability with Bayes’ theorem

 

In chapter 12, we implemented types to represent and efficiently sample from categorical distributions. We can also put any projection or filter we want on any discrete distribution. In this chapter, we’ll combine those basic parts to unlock their true power, which is using Bayes’ theorem to compute posterior distributions—that is, to update our previous opinions based on observations. We can build statistical models of the world that describe the relationship between causes and effects and then compute the probability that a particular cause is correlated with an observed effect. This has implications for medicine, social networks, developer tools, and any number of other fields.

If you have a background in probability and statistics, the Bayesian arithmetic in this chapter will be familiar, but representing prior, posterior, and conditional distributions as generic types may be new to you. Learning to represent these concepts in a program certainly changed how I think about them.

13.1 Bayes’ theorem

13.2 Likelihood functions and joint distributions

13.3 Updating priors by reasoning from effects to causes

13.4 Some applications of Bayesian reasoning

13.5 Unconditional likelihood functions are independent

Summary