The gradient of a model's likelihood¶
In the app: Help → Help contents, The gradient of a model's likelihood.
Estimating a linearised model means climbing its log likelihood (or log posterior) in the parameters, and the No-U-Turn sampler moves along its slope: both need the gradient. Differencing the likelihood costs two model solutions and Kalman filters per parameter and is accurate to about seven digits. pymetrix differentiates it exactly instead, for all parameters at once: the steady state (by the implicit-function theorem on the static equations), the linearised equations (second derivatives of the model's equations), the solution x(t) = P x(t-1) + Q e(t) (a Sylvester-type equation from A0 P^2 + A1 P + A2 = 0, as in Iskrev's identification analysis), the measurement equations, the shocks' covariance (sizes and correlations), the measurement errors, the stationary initial variance (a Lyapunov equation), and then each step of the Kalman filter. The optimiser uses it through the transforms that keep parameters inside their bounds; the Hessian, and so the standard errors, come from differences of the exact gradient; NUTS takes it at every leapfrog step. The filter is differentiated backwards (its adjoint, as reverse-mode automatic differentiation would): one pass forwards, one back, whatever the number of parameters, so a gradient costs two to four likelihood evaluations (seven parameters of the New Keynesian template, 36 of Smets and Wouters 2007), not one per parameter. Where it does not apply (known-date regimes, the OccBin filter, DSGE-VARs, diffuse starts, growth models) central differences are used as before; Gradient in the dialogs chooses. With numba installed (pip install pymetrix[fast]) the filter's loops run compiled, about twice as fast on small models. Which sampler? NUTS with a dense mass matrix (Metric, the default) undoes the correlations between parameters that DSGE posteriors have, and gave more effective draws a second than random-walk Metropolis-Hastings on the New Keynesian template and on Smets and Wouters; Metric mode keeps the curvature at the posterior mode (a short burn-in, good on nearly normal posteriors); with Workers its chains run at once in other processes. Where the gradient is by differences, Metropolis-Hastings is usually faster.
See also¶
References¶
- Iskrev, N. (2010). Local identification in DSGE models. Journal of Monetary Economics 57(2), 189-202. doi:10.1016/j.jmoneco.2009.12.007
- Ratto, M. and Iskrev, N. (2011). Algorithms for identification analysis under the DYNARE environment: final version of the software. Joint Research Centre, European Commission. (search)
- Harvey, A. C. (1989). Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press. doi:10.1017/cbo9781107049994
- Hoffman, M. D. and Gelman, A. (2014). The No-U-Turn sampler: adaptively setting path lengths in Hamiltonian Monte Carlo. Journal of Machine Learning Research 15, 1593-1623. (search)