From prior to posterior

Move what you believe before seeing the data (the prior) and the data themselves, and see what is left: the posterior, its estimators, the credible interval and the predictive, with the R command for each. Three conjugate models: beta-binomial, gamma-Poisson and normal-normal. It runs in the browser, on a phone too.

How to use it

  1. Start with “The prior gets updated”: a beta(3, 9) and 8 penalties saved out of 20, and the posterior that lands between what you believed and what you saw.
  2. In “How much your belief weighs” compare the same prior mean with strength 2 and with strength 60, and try giving the prior by its mean and its mode, as in the exams.
  3. Switch model: “Gamma-Poisson” for counts and “Normal-normal” for means with known σ. In all three only two numbers get updated.
  4. Look at the lower plot: the predictive, compared with what you would get if the parameter were fixed. The difference is what you do not know about the parameter.
  5. Open “Explain it slowly” to see the R command for each step and paste them into the R playground to check you get the same.

What it computes

With a beta(a, b) prior and x successes in n trials, the beta(a + x, b + n − x) posterior; with a gamma(a, b) prior and a total s over n periods, the gamma(a + s, b + n) posterior; with a normal prior worth n0 observations and known σ, the normal posterior with mean (n0·m0 + n·x̄)/(n0 + n) and sd σ/√(n0 + n). From each one, the mean, the mode, the median, the equal-tailed credible interval (qbeta, qgamma, qnorm), the weight of the data and the predictive: beta-binomial, negative binomial (dnbinom) and normal. The numbers match R.