Checking a Bayesian model before and after

Today let's understand how to check a Bayesian model: once before any data arrive, and once after you have fitted it.

A small online store ships about 45 orders a day. Over its most recent 60 trading days, it logged 61 refund requests in total: 22 days with none, 22 days with one, 9 days with two, and 7 days with three, its busiest day.

Here is that same count plotted, one bar for each number of refund requests a day could bring.

Most days bring zero or one refund request, and the bars thin out fast as the count climbs toward three.

A Poisson likelihood, a Gamma prior, and two checks at two different times

Start with the model this lesson uses for the store's daily refund counts.

A day's refund count is modeled as a Poisson random variable with rate lambda: the chance of seeing exactly k refund requests on a day is

\[ P(Y = k \mid \lambda) = \frac{\lambda^k e^{-\lambda}}{k!} \]

Lambda is the Poisson rate, the average number of refund requests the store expects on an ordinary day. It is the one number in this model nobody knows for certain, and it is what both checks in this lesson examine.

Before any data arrive, lambda itself gets a prior distribution, a Gamma distribution with two numbers, a shape and a rate, that sets out where lambda probably sits.

\[ \lambda \sim \text{Gamma}(\text{shape} = a,\ \text{rate} = b), \qquad \text{mean} = \frac{a}{b}, \qquad \text{variance} = \frac{a}{b^2} \]

This lesson runs two checks on that setup, at two different points in time. The prior predictive check runs before any data arrive: it draws a lambda from the prior alone, simulates a day's count from it, and asks whether the result is even plausible. The posterior predictive check runs after the model is fitted: it draws a lambda from the posterior, simulates a full replicate dataset from it, and compares that replicate against the real 60 days.

Both checks share the same move. Simulate data from the model, then compare it to something real or plausible, rather than trusting a formula alone to show the model is fine.