1.5. Closed-form marginal data density of VARs
Under a natural-conjugate prior the coefficients and the residual
covariance of a reduced-form VAR integrate out analytically. When
estimate finds the posterior mode of such a VAR in closed form (see
How the mode is found in Reduced-form VAR Modeling),
it also reports the exact log marginal data density, next to the Laplace
approximation:
pm = mdlest.model_data.estimation.posterior_maximization;
pm.log_marginal_data_density_closed_form % log p(Y), in nats
pm.log_marginal_data_density_closed_form_reason % '', a label or a reason
No option turns it on. It is available for rfvar_model and
prfvar_model with constant parameters, and for switching VARs whose
regimes are known from the data (Switching VARs with known regimes).
1.5.1. The prior and the integral
Write the scored observations of a VAR with \(n\) variables as
with \(Y\) the \(T \times n\) observations, \(X\) the
\(T \times K\) regressors (the constant, the deterministic variables,
then lags 1 to \(p\) of every variable) and the rows of \(U\)
independent \(N(0, \Sigma)\). niw is this prior, with \(B_{0}\),
\(\Omega\), \(S\) and \(\nu\) in the fields B_prior,
Omega, scale_matrix and df of the template.
generate_sims_zha_prior is of the same form when it has its prior on
\(\Sigma\) (use_sigma_prior = true, the default); its dummy
observations give the four terms. With
the posterior is \(\mathrm{vec}(B) \mid \Sigma, Y \sim N(\mathrm{vec}(\hat{B}), \Sigma \otimes K_{A}^{-1})\), \(\Sigma \mid Y \sim IW(\hat{S}, \nu + T)\), and
1.5.2. What the number is
\(p(Y)\) is the density of the scored observations given the observations that are not scored: the first
lag_lengthobservations of the estimation window, or the firstkf_presamplewhen that is larger. It integrates the kernel thatestimatemaximizes, likelihood times prior, without the truncations described below, so that at every parameter value \(\theta\)\[\log p(Y) = \log p(Y \mid \theta) + \log p(\theta) - \log p(\theta \mid Y).\]It is a natural log, in nats, of a density of the data in their own units. Two values compare models only on the same data, in the same units, and on the same scored dates; their difference is then a log Bayes factor.
log_postis the log posterior kernel at the mode, a value at one point: it is not a score of the model.The Laplace approximation,
log_marginal_data_density_laplace, approximates the same integral from the mode and the Hessian. Withestim_hessian_type = 'none'it is not computed; the closed form still is.A regression without observations has \(\log p(Y) = 0\).
Under switching with known regimes, the value is the sum of this closed form over the blocks of dates that share a covariance (see Switching VARs with known regimes).
1.5.3. Which priors have it
|
|
|---|---|
|
the value |
|
the value |
|
NaN; the reason is |
|
NaN; the reason is |
|
empty: the mode is searched numerically |
The value is also NaN, with the reason, when the degrees of freedom of the inverse-Wishart do not exceed \(n - 1\), when \(\Omega^{-1}\) or \(S\) is not positive definite, and when \(\hat{S}\) is not.
The field is empty ([]) whenever the mode is searched numerically:
estim_var_closed_form = false, linear restrictions under niw or
Sims-Zha, and the other cases listed under How the mode is found in
Reduced-form VAR Modeling (priors in
estim_priors, endogenous priors, missing observations, a closed-form
mode that the posterior kernel rejects, and so on). estimate then prints
Posterior mode by numerical search (no closed form: ...) with the
reason, except for a template without a closed form (user_defined) and
for estim_var_closed_form = false; a rejected mode prints
Posterior mode by numerical search: the kernel rejects the closed-form
mode (...).
1.5.4. Truncation: the label in the reason
With RISE’s defaults the kernel that estimate maximizes is truncated
twice:
solve_check_stability = truesets it to zero at VARs that are not stable;estim_prior_trunc = 1e-10bounds each parameter by quantiles at1e-10/2and1 - 1e-10/2: those of its prior or, for a parameter of the VAR prior, those of the wide normal that carries its bounds (about \(6.5 \times 10^{8}\) on either side of zero).
The closed form integrates the untruncated kernel. RISE reports it and
labels it in log_marginal_data_density_closed_form_reason, with one of
integral of the untruncated kernel; the estimated kernel is truncated by the stability check
integral of the untruncated kernel; the estimated kernel is truncated by finite parameter bounds
integral of the untruncated kernel; the estimated kernel is truncated by the stability check and finite parameter bounds
and estimate prints:
Closed-form log marginal data density (untruncated kernel) = -70.107321
integral of the untruncated kernel; the estimated kernel is truncated by the stability check and finite parameter bounds
With solve_check_stability = false and estim_prior_trunc = 0, and no
other finite bound on a parameter, the value is the exact integral of the
estimated kernel, the reason is empty, and estimate prints:
Closed-form log marginal data density (exact, conjugate VAR prior) = -70.107321
The reason of a reported value is empty exactly when the value is that exact integral. The number itself does not depend on the truncation: in the example below it is the same to the last digit with and without the defaults. If \(A\) is the region the truncation keeps, the marginal data density of the model whose prior is truncated to \(A\) (and renormalized) is \(\log p(Y) + \log P(A \mid Y) - \log P(A)\); RISE does not compute these two probabilities.
1.5.5. An example
A VAR(2) in quarterly inflation and the federal funds rate (the US data of
Smets and Wouters (2007) in RISE’s examples/VariousModels/SmetsWouters;
pinfobs and robs, both in percent per quarter), estimated from
1966Q1 to 2004Q4 under niw with its default hyperparameters:
prior = rise.engine.var.var_priors.niw({'pinfobs','robs'}, true, {}, 2, db);
mdlest = estimate(m, data = db, ...
estim_start_date = date2serial('1966Q1'), ...
estim_end_date = date2serial('2004Q4'), ...
estim_var_prior = prior, ...
solve_check_stability = false, ...
estim_prior_trunc = 0);
niw scales its prior by univariate AR(2) fits on the data it is given,
here all of db, the estimation window included; the closed form holds
that scale fixed. To keep the scored quarters out of the prior, give niw
a pre-sample.
The 154 scored quarters (1966Q3-2004Q4) give
Quantity (nats) |
Value |
|---|---|
|
-70.107321 |
|
-70.384232 |
log likelihood at the mode ( |
-38.860659 |
log prior at the mode ( |
6.285893 |
log posterior density at the mode, from \(\hat{B}\), \(K_{A}\), \(\hat{S}\), \(\nu + T\) |
37.532555 |
The last three give \(-38.860659 + 6.285893 - 37.532555 = -70.107321\), the closed form to \(10^{-13}\); the Laplace approximation is 0.28 nats below it.
To choose the lag length, kf_presample = 4 makes the VARs with 1 to 4
lags score the same 152 quarters (1967Q1-2004Q4). With equal prior odds:
Lags |
log marginal data density |
Posterior probability |
|---|---|---|
1 |
-72.8894 |
0.059 |
2 |
-71.1826 |
0.324 |
3 |
-71.2615 |
0.299 |
4 |
-71.1999 |
0.318 |
On the VAR(2), generate_sims_zha_prior with its defaults gives
-55.8205; minnesota, inw and Sims-Zha without its prior on
\(\Sigma\) give NaN with the reasons in the table above.
The tutorial Estimation/var_closed_form_mdd/howto.m runs this example.
1.5.6. The routines
estimate calls rise.engine.var.vartools.bvar_posterior_mode, whose
output carries log_marginal_data_density and
log_marginal_data_density_reason. The value comes from
P.log_marginal_likelihood() of
rise.engine.var.vartools.bvar_conjugate_problem, which returns
[lml, why]. Both take the model data that pull_objective returns as
its seventh output. The closed form of one regression is:
[lml, why] = rise.engine.var.vartools.conjugate_log_marginal_likelihood(Y, X, Bbar, Oinv, S, nu)
with Y the \(n \times T\) observations, X the \(K \times T\)
regressors, Bbar the \(n \times K\) prior mean (B_prior.'),
Oinv \(\Omega^{-1}\), and S, nu the inverse-Wishart.