1.10. Direct likelihood of fully observed models
When every variable of a model is observed and the data are complete, the
shocks of every period follow from the data, provided the map from the
shocks to the observed variables can be inverted. The likelihood is then the
density of those shocks times the Jacobian term of the map, with the
Hamilton recursion over the regimes. estimate takes this route by itself
for the maps whose density is proved to have such a closed form, and
filters every other model.
For a reduced-form VAR the route also gives the exact score of the
posterior, on the conditions of Exact score of switching VARs.
1.10.1. The two classes
The proof (rise.engine.dsge_tools.estim.direct_route_class) reads the
model’s structural metadata, not the values of its solution. The metadata
are the coordinates of the symbolic derivatives of the equations that are
not identically zero, and the time incidence of the variables. The
perturbation parameter sig and the observed exogenous variables are known
inputs.
Class A: affine. The solution is affine in the shocks of the period, with an impact that depends neither on the state nor on the shocks.
When. For every first-order solution, and above the first order for a model whose equations have no second derivative between two endogenous variables or shocks, nor between one of them and an observed exogenous variable.
(1+d)*x = e, with an observedd, is not class A: its order-2 policy isx = e - d*e, whose impact varies with the data.Density. The data have the Gaussian density \(N(A_0(t), A_1A_1')\) on the rows the shocks move. No injectivity is needed, so maps with more shocks than observed variables they move are included.
Computation. It is the computation of the direct route before this release:
one Cholesky factor per regime;
the rows the shocks move are those with a coefficient above 1e-12, a compatibility convention;
the reported shocks are the conditional mean \(E[\varepsilon_t \mid r_t]\).
Class B: triangular, affine in each pivot. Every shock enters one equation, affinely, and that equation determines one observed variable, its pivot. The pivots can be ordered so that each depends, in the period, only on earlier pivots and on predetermined variables. In full:
B1. The shock appears in its equation only, and that equation holds no other shock.
B2. The equation is affine in its pivot and its shock: no second derivative pairs either of them with an endogenous variable, a shock or an observed exogenous variable.
B3. The other variables of the equation in the period are earlier pivots or predetermined variables. When the equation has leads, its pivot is not a state variable, since its expectation would depend on it.
B4. The other equations hold, in the period, only predetermined variables: no pivot, no shock, no lead.
B5. No transition driver is a pivot.
Then, at every perturbation order, pruned or not, each pivot is
with \(c_i\) depending only on the parameters and sig. The shocks follow by forward substitution. The term \(\log\lvert\det J\rvert = \sum_i \log\lvert c_i\rvert\) is constant. A zero \(c_i\) gives code 318.
Examples:
\(x = \rho x_{-1} + a x_{-1}^2 + \sigma\varepsilon\) is class B.
Burnside’s asset-pricing model with an additive price shock,
y = beta*exp(theta*x{+1})*(1+y{+1}) + sigv*ed, is class B.The same model with a multiplicative shock,
...*exp(sigv*ed), is not: the price is quadratic in its shock at order 2.
Unproved. Any other model goes to the filter with the reason, which
estimate prints. “Unproved” does not mean the map is not injective.
Cases include:
simultaneous blocks (most New Keynesian models);
shocks that enter nonlinearly;
non-smooth operators (abs, sign, min, max, comparisons, conditionals);
anticipated shocks;
derivatives that are not symbolic;
above the first order, transition probabilities that depend on variables (the probability-weighted equations make the proof conservative).
Inverting all the preimages of a general polynomial map is a separate, later capability.
1.10.2. When the route applies
rise.engine.dsge_tools.estim.likelihood_path decides in this order:
The filter, with the reason, when any of these holds:
estim_force_filteris true;the data have missing observations;
a declared variable is not observed;
the observables have measurement errors;
the model has occasionally binding constraints;
the data carry observed expectations;
an auxiliary variable is not the lag of an observed variable.
At the first order, the direct route (class A).
Above the first order, the direct route for a proved class A or B, and the filter otherwise.
No solution value enters the decision, so the route is the same at every
parameter value. The labels of the filter route follow how the filter chain
dispatches: 'kalman' at the first order and 'nonlinear_filter'
above it. RISE has no particle filter.
1.10.3. Certified bounds
The certified polynomial is the solution projected onto the proved pattern, and its coefficients are taken as exact inputs. The certification covers the inversion of that polynomial, not the accuracy of the perturbation solver. Before the evaluation, two consistency checks are made:
the coefficients the proof excludes (in the row of pivot \(i\), the later shocks and \(\varepsilon_i\) with anything but sig) must be zero to rounding of the solver, below \(1000\,\epsilon\) times the row’s largest coefficient. They are then set to zero;
with one regime, \(c_i\) must equal \(-\partial F/\partial\varepsilon_i \,/\, \partial F/\partial v_i\) at the steady state.
If either fails, the result is code 320: the proof and the solver disagree.
For each pivot, the error bound of the recovered shock is
where:
\(\rho_i\) bounds the floating-point evaluation of \(y_i - G_i\);
\(\Delta M_i\) is the difference of the majorant of \(G_i\) (absolute coefficients) between the enclosure of its inputs and the computed inputs. The inputs are the earlier shocks and, under pruning, the propagated bounds of the components.
\(\delta c_i\) bounds the evaluation of \(c_i\).
Arithmetic.
Nonnegative sums and products use \(\gamma_k = ku/(1-ku)\), and \(ku < 1/2\) is checked.
Every bound is rounded up, and every subtracted bound is rounded down.
Underflow adds a multiple of the smallest subnormal; overflow fails.
The bound on the log density of a period in a regime is
This bound holds for each period on its own. It is not accumulated over the periods or the regime recursion. When it exceeds \(10^{-8}\), the evaluation fails with code 316. Huge scales, heavy cancellation and overflow are therefore refused, not returned.
1.10.4. Pruning
With simul_pruned, the likelihood of a class-B model is that of the
pruned solution as simulated. The accepted values are true,
'one_step_pruning' (up to order 5) and
'one_step_pruning_automatic'. Any other callback is refused with an
error; the filters do not prune.
Start. The pruned components start as the simulations start them: the first is the observed state at the end of the warm-up, and the others are zero. They then follow the recovered shocks.
First component. The components sum to the state, so the first is the observed state less the others: its value at the exact shocks. Its error bound is that of the others. Propagated instead, its bound grew by a factor of about 1.7 per period on Burnside’s model, and the evaluation failed with code 316 after 24 periods.
One regime. The inversion is unique, so the likelihood is exact given that initial split.
Several regimes. The components are kept per regime and mixed into each destination regime with weights proportional to \(p(i \mid t-1)\,Q(i,j)\) (IMM). This is exact when \(Q\) is the identity, and an approximation otherwise.
Memory of the start. The components forget the initial split at the rate of the first-order dynamics, and a unit root does not forget it. On Burnside’s model, data that start after 300 simulated periods give a log likelihood off by 0.029 at order 2 and by 0.020 at order 3 (150 periods) when the route starts the higher components at zero.
Affine solutions. Pruning of an affine solution above the first order is not implemented, and such a model goes to the filter.
1.10.5. Regime probabilities
Without pruning, the state is data and the Hamilton recursion is exact.
Increment. Each period’s increment is the log of the sum, over the regimes with positive predictive probability, of probability times density. The largest density is factored out of the sum. When the scaled sum underflows, because a regime without probability has a much larger density, the sum is taken in logs over the regimes with probability.
Failures. A regime of positive probability whose density cannot be computed stops the likelihood with its code. A failure is never hidden as a zero density.
Support. Data outside the support of every such regime give 312.
Timing. The start, the warm-up transition and the timing of the transition are those of Where the regime probabilities start.
The density is in the model’s coordinates (log variables in logs), as on the filter route.
1.10.6. Accuracy and speed
The scripts are in RISE-unit-tests/development/direct_likelihood. The
model is Burnside’s, with an additive price shock and dividend growth
quadratic in its lag (class B):
y = beta*exp(theta*x{+1})*(1+y{+1}) + sigv*ed and
x = (1-rho)*xbar + rho*x{-1} + kap*(x{-1}-xbar)^2 + sige*e.
Known answers. The data are 150 periods simulated by RISE’s own one-step functions from drawn shocks.
The recovered shocks equal the drawn ones to \(7\times10^{-14}\).
At orders 1 to 3, pruned or not, the log likelihood equals the density of the drawn shocks less \(\log\lvert\det J\rvert\) to \(2\times10^{-7}\). That is the accuracy of the reference, whose Jacobian is taken by finite differences.
With two regimes, it equals an independent Hamilton recursion to \(2\times10^{-7}\). That recursion solves for each regime’s shocks by Newton’s method on RISE’s one-step function.
The unit tests compare the shocks and the densities with references in 50-digit arithmetic, within the certified bounds.
The filters as the measurement error shrinks. A measurement error is added to both observables, with a standard deviation that is a share of each series’ (order 2, 101 periods, one regime):
Share |
0.1 |
0.03 |
0.01 |
0.003 |
0.001 |
|---|---|---|---|---|---|
Divided difference |
254.8 |
279.5 |
281.9 |
282.1 |
282.1 |
Unscented |
238.7 |
256.9 |
258.8 |
259.0 |
259.1 |
Cubature |
249.0 |
271.3 |
273.7 |
274.0 |
274.0 |
Particle (40,000) |
281.9 |
349.1 |
357.2 |
333.1 |
66.3 |
The direct log likelihood is 360.6. The sigma-point filters settle 78 to 101 below it. Their Gaussian approximation of the joint predictive density misses the curvature of the price in the dividend shock, which is large next to the price shock. The reference particle filter of the unit tests comes within 3.4 of the direct value at a share of 0.01. Below that, its weights degenerate. With two regimes the direct value is 334.7, the sigma-point filters settle 76 to 94 below it, and the particle filter comes within 0.6 of it at a share of 0.01.
Speed. On that model with two regimes, an evaluation takes 4 ms on the direct route and 256 ms with the divided-difference filter. With pruning, it takes 50 to 160 ms over 150 periods at orders 2 and 3: the components are computed period by period.
On the suite’s model with time-varying transition probabilities (200 periods, first order), the direct route and the switching Kalman filter give the same log likelihood, -69.164458, and the direct route is 6.7 times faster.
Against the previous release, class-A evaluations (VARs with 2 to 20 variables, the suite’s fully observed DSGE model, 200 and 1,000 periods, one and two regimes) give the same log likelihoods to the last digit, and are no slower: in paired, interleaved runs the ratio of the minimum times is 0.80 to 0.97.
1.10.7. Limits
Unproved maps go to the filter. So do measurement errors, constraints, observed expectations, anticipated shocks, and auxiliary variables other than lags.
Pruning with several regimes is the IMM approximation above.
filterreturns the direct route’s filtration only for fully observed models with time-varying transition probabilities. Other models are filtered there, whileestimateuses the direct route.