- Introduced by
- W. K. Hastings (algorithm); applied to dynamic models by Carlin, Polson & Stoffer
- Year
- 1970 (algorithm); 1992 (dynamic application)
- Type
- Bayesian MCMC sampler for dynamic models
- Family
- Bayesian / computational
What does it do?
The Dynamic Metropolis-Hastings (Dynamic MH) algorithm applies the Metropolis-Hastings MCMC sampler to Bayesian state-space and time-varying parameter models.
Latent states or evolving parameters are updated by proposal-and-accept moves, either one time point at a time or as a block, and the output is a joint posterior distribution over the whole trajectory rather than single filtered estimates. The name describes Metropolis-Hastings applied to dynamic models rather than a separately defined algorithm; the Carlin, Polson and Stoffer (1992) state-space work used the Gibbs sampler.
The intuition behind the method
In a dynamic model the unknowns are not a fixed set of parameters but an entire sequence of latent states that evolve through time. The MH algorithm handles this by repeatedly proposing a new value for each state from a proposal distribution and accepting or rejecting it based on how well the proposed trajectory fits both the observation at that time and the state transition law. Over many iterations, accepted draws trace out the joint posterior over the full latent trajectory, allowing honest uncertainty to propagate across time steps.
History
Hastings (1970) generalised the sampling method introduced by Metropolis et al. (1953), presenting the sampler together with its theory, techniques of application, and methods for assessing Monte Carlo error. Carlin, Polson, and Stoffer (1992) applied Monte Carlo methods to nonnormal and nonlinear state-space models, proposing the Gibbs sampler to obtain marginal posterior densities of coefficients and states. The Metropolis-Hastings formulation for dynamic models extends these lines of work and is not described in the Carlin et al. abstract.
When to use it
Use Dynamic MH when your state-space or time-varying parameter model is nonlinear or non-Gaussian, making the Kalman filter or its extensions inadequate. It is suitable for moderate-length time series where full posterior inference over latent trajectories is required. Prefer particle MCMC (PMCMC) or particle filters for very long series or real-time filtering. Do not use Dynamic MH when a linear-Gaussian model applies — the Kalman smoother is exact and far cheaper. Also avoid it when only point estimates are needed, since the computational cost of full MCMC is then unnecessary. Before applying the method, check that the observation and transition densities are correctly specified, that the priors are proper, that the latent states and hyperparameters are identifiable, and that p(y_t | x_t) and p(x_t | x_{t-1}) can be evaluated pointwise.
Limitations and considerations
- Single-site MH updates on long time series mix slowly due to high serial correlation among states.
- Proposal tuning is non-trivial; a poorly scaled proposal leads to very low acceptance rates or near-certain acceptance with tiny moves.
- Computationally expensive relative to the Kalman smoother for linear-Gaussian models.
- Block proposals for all time steps simultaneously can be difficult to design efficiently.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Handles nonlinear, non-Gaussian state-space models where analytic filters are unavailable.
- Produces the full joint posterior over latent trajectories, not just filtered point estimates.
- Flexible: the proposal can be tailored to the model structure (random walk, Laplace approximation, prior).
- Can be combined with Gibbs steps for fixed parameters, making it a building block in complex hierarchical dynamic models.
- Under standard conditions (an irreducible, aperiodic chain whose stationary distribution is the posterior), MH converges to that posterior. These are general MH requirements and must still be checked for the specific state-space proposal.
Applications
- Time-varying regression coefficients in macroeconomic or financial models.
- Non-Gaussian state-space models in ecology (population dynamics) and epidemiology (disease spread).
- Stochastic volatility models in finance where the latent variance process is non-Gaussian.
- Nonlinear tracking problems in engineering and robotics.
- Bayesian estimation of hidden Markov models with continuous latent states.
- Parameter inference in compartmental epidemic models with unobserved infection counts.
How it works
How it works
The model is cast as a state-space system: an observation equation linking data y_t to a latent state x_t, and a transition equation describing how x_t evolves from x_{t-1}. Both equations can be nonlinear and non-Gaussian, which is precisely the setting where the Kalman filter is unavailable and MCMC is needed.
Formula
y_t \mid x_t \sim p(y_t \mid x_t), \quad x_t \mid x_{t-1} \sim p(x_t \mid x_{t-1})At each MCMC iteration a candidate state x_t* is drawn from a proposal distribution q, which can be a random walk, a prior draw, or a Gaussian approximation to the local posterior. The proposal may act on one time index at a time (single-site) or on a block of time steps simultaneously (block sampling).
Formula
x_t^* \sim q(x_t^* \mid x_t^{(s)})The Metropolis-Hastings acceptance ratio weighs the likelihood of the observation under the proposed state against the current state, corrected by the transition densities and the proposal ratio. If the candidate fits better it is always accepted; if it fits worse it is accepted with probability alpha, ensuring detailed balance and eventual convergence to the correct posterior.
Formula
\alpha = \min\!\left(1,\, \frac{p(y_t \mid x_t^*)\,p(x_t^* \mid x_{t-1})}{p(y_t \mid x_t^{(s)})\,p(x_t^{(s)} \mid x_{t-1})} \cdot \frac{q(x_t^{(s)} \mid x_t^*)}{q(x_t^* \mid x_t^{(s)})}\right)Accepted candidates replace the current state draws. After cycling through all time steps (and any fixed parameters via Gibbs or MH sub-steps), one complete iteration of the chain is recorded. The process repeats for thousands of iterations, discarding an initial burn-in period.
Convergence is assessed with standard MCMC diagnostics: trace plots of sampled trajectories, R-hat across parallel chains, and effective sample size. Check the traces of both the latent states and the hyperparameters, since hyperparameter traces can look stable while the states still mix slowly. Slow mixing, a symptom of a poor proposal or high autocorrelation across time steps, is addressed by tuning the proposal scale or switching to particle MCMC. To summarise the output, compute pointwise posterior quantiles of each x_t across retained draws to form credible bands. These bands describe marginal uncertainty at each time point and are not simultaneous bands over the whole trajectory.
Common pitfalls
- Skipping convergence diagnostics (R-hat, trace plots) and accepting results from a chain that has not mixed.
- Using single-site updates on a long series without block sampling, resulting in extremely slow mixing.
- Confusing filtered estimates (online) with smoothed posterior draws (offline). Dynamic MH produces the latter.
- Forgetting to account for the proposal ratio when using an asymmetric proposal, violating detailed balance.
- Applying Dynamic MH to a linear-Gaussian model when the Kalman smoother gives exact results at much lower computational cost.
Frequently asked questions
How does Dynamic MH differ from the particle filter?
The particle filter is a sequential (online) algorithm that propagates a weighted set of particles forward in time, producing filtered distributions p(x_t | y_{1:t}). Dynamic MH is an offline MCMC sampler targeting the full smoothing posterior p(x_{1:T} | y_{1:T}). For full posterior inference over trajectories, Dynamic MH or particle MCMC is preferred; for real-time filtering, particle filters are used.
Why does single-site MH mix so slowly in dynamic models?
Latent states at adjacent time points are strongly correlated through the transition density. Updating one state at a time leaves neighbouring states fixed, so most proposals that improve one state worsen the fit to its neighbours, leading to high rejection rates and slow exploration. Block proposals or particle MCMC overcome this by moving all states jointly.
How should I tune the MH proposal?
A target acceptance rate of roughly 20–40% is a commonly quoted rule of thumb for Gaussian random-walk proposals in moderate dimensions. It is a heuristic, not a result derived for this model, and it is best read for low-to-moderate-dimensional proposals. For high-dimensional trajectory blocks, acceptance targets and proposal scaling must be checked empirically. Adaptive MCMC during a warm-up phase can tune the proposal covariance automatically. For state-space models, a Laplace approximation to the local smoothing density can be a stronger proposal than a random walk in some models.
What is the relationship to particle MCMC?
Particle MCMC methods embed a particle filter inside the MH step. The particle filter supplies an estimate of the likelihood, and the whole latent trajectory can be proposed at once. Because the acceptance step uses an estimated rather than exact likelihood, particle MCMC is a pseudo-marginal MH method, not simply Dynamic MH with a different proposal. For long time series it can mix better than single-site updates, but its performance depends on the number of particles and the variance of the likelihood estimate, which should be checked.
Can Dynamic MH handle time-varying parameters rather than latent states?
Yes. Time-varying parameter models (e.g., regression coefficients that drift over time) are a special case of state-space models where the state is the parameter vector. Dynamic MH samples the full trajectory of parameters jointly with any hyperparameters governing their evolution.
Related methods
Sources
Hastings, W. K. (1970). Monte Carlo sampling methods using Markov chains and their applications. Biometrika, 57(1), 97–109.
Open DOI referenceCarlin, B. P., Polson, N. G., & Stoffer, D. S. (1992). A Monte Carlo approach to nonnormal and nonlinear state-space modeling. Journal of the American Statistical Association, 87(418), 493–500.
Open DOI reference