/ lab / bayes

Bayesian, the noun

"Bayesian" mostly gets used as an adjective, a vibe a model has. The noun underneath is a distribution over the thing you didn't know, and each of the three problems below ends with one; whatever you want to ask after that is an integral over it. The framework I work on at my day job dresses this up a lot, but the dressing is only there so the same trick works on models that don't fit on a page.

Where are the keys?

Twenty-five rooms, and the shading is where you think you left your keys (that's the prior). Click a room to look. If they're not in there, that room drops to zero and its share gets spread over every room you haven't checked, so the total never changes, it just moves around; Bayes' rule is the bookkeeping for where it moves.

7% 9% 7% 3% 1% 9% 11% 9% 4% 1% 7% 9% 7% 3% 1% 3% 4% 3% 1% 1% 1% 1%

Searches: 0

This is the rule that found the USS Scorpion in 1968 and Air France 447 in 2011. A prior over the ocean floor, narrowed by every place the search team looked and didn't find anything, which is what you just did, on a grid the size of the ocean floor.

Bayes' rule done by hand on a grid: a prior over where the thing is, times the likelihood of not having found it where you already looked, renormalized after every search. -> bayes.ex

A rate, learned from years

Earthquakes per year in the Bay Area, where I live; not a textbook example for me. Each year is a draw from Poisson(rate); the rate itself is the thing you want, and you don't know it. The dim curve is what you'd guess about it before any data shows up. Click observe a year and watch the bright curve narrow as the years stack up.

0 2 4 6 8 10 12 Rate (events / year) Density mean 5.0

0 years · 0 total events · posterior mean 5.0

Closed-form here: a Gamma(2.0, 0.4) prior times a Poisson likelihood is another Gamma, Gamma(2.0, 0.4). Same shape, only narrower. For models without a tidy conjugate pair the framework does this numerically instead, and you still get the same kind of object out the other end.

Poisson likelihood against a Gamma prior. Gamma is conjugate to Poisson, so the posterior is just another Gamma with updated parameters: closed form, no sampler, no WASM. -> charts.ex

Asking the posterior a question

The section above made a posterior, and squashing it down to one number ("the rate is 3.5") throws away most of what's in it. What you usually want to know is more like is it above some threshold I care about? and the posterior already knows, so move the threshold and read the integral off the curve.

0 2 4 6 8 10 12 Rate (events / year) Density P(rate > 5.0) = 37.8%
5.0

The shaded area is P(rate > threshold | data). Same posterior as the section above; observe more years there and watch the answer here move. Every other question you'd ask about the rate is just a different integral over the same object.

The same posterior as above, integrated past a threshold. That tail area is the whole decision; dragging the line moves the bound on the integral, not the model. -> bayes.ex

source fugue