cultivars.multivariate.large_dim#
Large-dimensional multivariate models: shrink, select, or factor the panel.
An unrestricted VAR on \(k\) series with \(p\) lags has
\(p k^2\) slope coefficients, and past a handful of variables a
macroeconomic sample cannot pin them down. Every model here is one of
three answers to that count. Shrink the coefficients toward a prior and
report a posterior: the conjugate Normal-inverse-Wishart VAR with its
exact posterior and closed-form marginal likelihood
(bayesian), the same model with
the tightness itself estimated
(hierarchical), Gibbs sampling
under independent priors that select or shrink coefficient by coefficient
(gibbs), and the two relaxations
of the Gaussian likelihood – Student-t innovations
(student) and stochastic
volatility (volatility). Set
most of the coefficients to exactly zero and report the survivors: the
penalized VAR under five penalties, whose support is a Granger network
(sparse), and its extension to
the contemporaneous precision network
(graphical). Or compress the
panel to a few factors and model those: the dynamic factor model
(dynamic_factor), the
factor-augmented VAR that puts observed policy variables beside the
factors (factor_augmented), and
the factor stochastic-volatility model for a wide panel’s time-varying
covariance (factor_volatility).
One module is a view rather than an estimator:
spillover reads any fitted
closed reduced form as a Diebold-Yilmaz connectedness network.
The models share one shape, with one honest split. A model object holds
the specification; fit returns an immutable record that renders the
same way everywhere (print, a notebook cell, summary()). The
Bayesian records carry draws and propagate them – credible intervals,
impulse responses with posterior bands, a predictive whose bands are
bands of the predictive distribution, a stability share, and chain
diagnostics where the draws are a chain – and deliberately report no
likelihood, parameter count or information criteria, because a posterior
has none; the conjugate and hierarchical models offer a marginal
likelihood instead, and the others say why they do not. The penalized
records carry the selected coefficients, the penalty path and its
cross-validation errors, and deliberately report no standard errors,
because inference after selection is not a solved problem at this
generality. The penalized results satisfy the closed-system contract and
so feed the structural layer and the spillover view directly; the
Bayesian results propagate through their own draws instead.
Names are imported from the leaf module, never from here –
from cultivars.multivariate.large_dim.sparse import SparseVAR – so
an import path names the family, the specification and the class. This
package exposes only the modules.
Layout. The public classes are thin: each validates its specification on
a model base in cultivars._internals – the Bayesian family on
_BayesianVectorAutoRegressionModel and its Student-t, Gibbs and
stochastic-volatility extensions, the penalized family on
_SparseVectorAutoRegressionModel, the factor stochastic-volatility
model on _FactorVolatilityModel, while the two least-squares factor
models validate in place – and assembles its public record from a packed
fit. The samplers (_draw_conjugate, the volatility and factor
blocks), the FISTA solver and the information criteria live in _core
and _internals; the priors the Bayesian family accepts are in
priors.
The small-system reduced forms these models scale up are in
reduced_form; identification of any
closed result is in structural.
Example
One six-variable VAR(1) through the three answers: the conjugate posterior with its evidence, the lasso with its support, and the Student-t fit with its tail index – then the sparse result read as a network:
>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> k, n = 6, 300
>>> first = 0.5 * np.eye(k)
>>> first[1, 0], first[3, 2] = 0.3, -0.3
>>> y = np.zeros((n, k))
>>> for t in range(1, n):
... y[t] = first @ y[t - 1] + rng.standard_normal(k)
>>> conjugate = bayesian.BVAR(y, order=1).fit(n_draws=200, seed=0)
>>> bool(np.isfinite(conjugate.log_marginal_likelihood)), conjugate.forecast(4).shape
(True, (4, 6, 3))
>>> lasso = sparse.SparseVAR(y, order=1).fit(penalty="lasso")
>>> edges = lasso.granger_adjacency(threshold=0.15)
>>> [(i, j) for i in range(k) for j in range(k) if edges[i, j]]
[(1, 0), (3, 2)]
>>> heavy = student.StudentBVAR(y, order=1).fit(n_draws=300, n_burn=100, seed=0)
>>> bool(heavy.df > 10.0), heavy.outlier_dates().size
(True, 0)
>>> network = spillover.Spillover(lasso, horizon=10).compute()
>>> network.transmitters()[:2]
('y1', 'y3')
Modules#
The conjugate Bayesian VAR: an exact posterior, and the number that ranks priors. |
|
The dynamic factor model: a large panel explained by a small VAR. |
|
The factor-augmented VAR: a few shocks, answered by hundreds of series. |
|
Factor stochastic volatility: a moving covariance matrix built from a few paths. |
|
The Gibbs-sampled BVAR: every prior the conjugate model must refuse. |
|
The graphical VAR: two networks, kept apart because they mean different things. |
|
Hierarchical shrinkage: the tightness is estimated, not asserted. |
|
The sparse VAR: shrinkage by selection, and the network it draws. |
|
Diebold-Yilmaz connectedness: who moves whom, in one table. |
|
The Student-t Bayesian VAR: fat tails as a model, not a casualty. |
|
The Student-t Bayesian VAR: fat tails as a model, not a casualty. |