Model fitting and inference for infectious disease dynamics
Last time we saw that the posterior distribution of , given observed data, is
Our aim is to draw samples from this distribution.
We can do exactly the same thing to study a posterior distribution.
Explore a distribution by drawing from it. More samples, better picture:

Sampling blindly from the prior spends almost all its effort on parameter values that fit the data badly. We need something that concentrates where the posterior is.


Rejection sampling uses a proposal distribution which


Accepted points build up a sample from .

In Markov chain Monte Carlo (MCMC) we do not need one proposal density that bounds everywhere.
Instead we build a chain of samples, where each proposed depends on the previous one: the proposal density takes the form .
A commonly used MCMC algorithm is Metropolis-Hastings.
Its acceptance rate is carefully derived to ensure unbiased samples.

If is symmetric, then
If is asymmetric, then

Too narrow and the chain crawls; too wide and almost nothing is accepted. The proposal has to match the shape of the posterior.
With 2 parameters that is 3 numbers to pick, and with 10 it is 55.
Worse, the shape you need is the shape of the thing you have not sampled yet.
Adaptive MCMC alters the proposal distribution while the chain is running.
Start with a large symmetric variance and scan around to find a mode.
Then alter the shape of the proposal to match the covariance of the accepted values.
Eventually the proposal density should match the shape of the target density.


Classical adaptive Metropolis: Haario et al. (2001). Robust adaptive Metropolis (RAM), which we use in the practical: Vihola (2012).
Metropolis-Hastings proposes a direction at random and hopes for the best.
For a model we can differentiate, and an ODE model qualifies because the solver propagates derivatives, the gradient of the log-posterior tells us which way is uphill.
Hamiltonian Monte Carlo uses it: simulate a puck rolling on the surface, with gradients pulling it towards high density and momentum carrying it a long way. The direction and length of each move now come from the posterior.
NUTS, the No U-Turn Sampler, is HMC with the step size adapted during warmup and the trajectory length stopped when the path turns back on itself.
It usually just works, with no proposal tuning at all, and is the default to reach for. Fall back to RAM or MH for discrete parameters, or a stochastic simulator that breaks differentiation, as the particle filter will later.
Hoffman and Gelman (2014); see Betancourt (2017) for the intuition.
In the practical you will
Markov chain Monte Carlo