Skip to content
Four Roads to a Posterior, home

Interactive explorer

Four methods, one posterior

The four algorithms from the assignment, ported line by line from R and run in your browser. With the original settings they reproduce R’s output exactly (and, in As submitted mode, the numbers printed in the 2023 report); change the seed or the tuning to see how each road behaves.

The same four R functions, fed the data the assignment describes: 7 doses, 10 patients each, and logit p = β₀ + β₁·dose. All four roads should arrive at nearly the same posterior.

Model and data

What every method is fitting

yi∣β∼Bin⁡(ni, pi),ni=10log⁡pi1−pi=β0+β1 xi,xi∈{0,…,6}p(β0,β1)∝1\begin{aligned} y_i \mid \beta &\sim \operatorname{Bin}(n_i,\, p_i), \qquad n_i = 10 \\ \log\frac{p_i}{1-p_i} &= \beta_0 + \beta_1\, x_i, \qquad x_i \in \{0,\dots,6\} \\ p(\beta_0, \beta_1) &\propto 1 \end{aligned}

Seven grouped binomial observations, one per dose level, with a flat prior so the posterior is proportional to the likelihood. Two coefficients: an intercept and the change in log-odds of improvement per unit of dose.

Patients improved at each dose
dose xix_i0123456
improved yiy_i3544768
not improved7566342
proportion0.30.50.40.40.70.60.8

Each method runs in a Web Worker with R’s Mersenne-Twister seeded at 90125.

  • Laplace approximation

    approximation

    Waiting…

  • Metropolis-Hastings

    sampler

    Waiting…

  • Hamiltonian Monte Carlo

    sampler

    Waiting…

  • Expectation propagation

    approximation

    Waiting…

Marginal posteriors

Four estimates of β₁

Kernel density of the sampler draws (solid) against the two Gaussian approximations (dashed and dotted). Hover to read the curves.
  • Laplace approximation
  • Metropolis-Hastings
  • Hamiltonian Monte Carlo
  • Expectation propagation
Fitting…
Posterior summaries of β₁ dose for each method
Methodmean95% intervalESS
Laplace………
MH………
HMC………
EP………

Intervals are 2.5% and 97.5% quantiles of the draws for MH and HMC, and mean ± 1.96 sd for the Gaussian approximations. ESS is coda::effectiveSize, reported as is: it can exceed the number of draws when successive HMC draws are negatively correlated.

Mixing

Trace plots for β₁

Every draw from the start of each chain (thinned for drawing). The shaded strip is the burn-in the original code discarded.

Metropolis-Hastings

Hamiltonian Monte Carlo

Joint posterior

β₀ against β₁

Grey contours: the exact posterior (50/80/95/99% Gaussian-equivalent levels). Dots: MH and HMC draws. Ellipses: 50% and 95% regions of Laplace and EP.
  • Laplace
  • MH
  • HMC
  • EP

What it means

Probability of improvement by dose

Posterior median and 95% band of P(improvement) implied by each method. Open circles are the observed proportions out of 10.
  • Laplace
  • MH
  • HMC
  • EP
Every number, every coefficient
Posterior summaries for every coefficient and method
CoefficientMethodmeansd2.5%50%97.5%ESS
β₀ (Intercept)Laplace………………
MH………………
HMC………………
EP………………
β₁ doseLaplace………………
MH………………
HMC………………
EP………………