GraphicalVAR#
- class cultivars.multivariate.large_dim.graphical.GraphicalVAR(endog, *, order, trend='c', names=None)[source]#
Graphical VAR, Barigozzi-Brownlees: sparse dynamics, sparse precision.
Two stages. The dynamics are a lasso VAR,
\[\min_{A}\ \tfrac{1}{2}\sum_t \lVert y_t - c - \textstyle\sum_i A_i y_{t-i} \rVert^2 + \lambda \sum_i \lVert A_i \rVert_1,\]with \(\lambda\) fixed by the caller or chosen by rolling-origin forecast error along a path; the contemporaneous network is then estimated on the residuals by Meinshausen-Buhlmann nodewise lasso regressions – each residual on all the others – with each node’s penalty chosen by K-fold cross-validation, which is legitimate in the second stage because residual rows carry no serial ordering once the dynamics are removed. Deterministic terms are never penalized.
- Variables:
_endog – The validated
(nobs_total, k)panel._order – The autoregressive order.
_trend – The deterministic specification.
_names – One label per variable.
- Parameters:
- Raises:
SpecificationError – If
orderis below 1,trendis not one of the three names, ornamesdoes not have one entry per column.DimensionError – If the panel is not a time-down-the-rows matrix or too short for the order.
See also
GraphicalVARResult– the recordfitreturns.SparseVAR– the first stage on its own, with the elastic-net and group penalties.VAR– the unpenalized model, for systems small enough to afford it.
References
Barigozzi, M., & Brownlees, C. (2019). NETS: Network estimation for time series. Journal of Applied Econometrics, 34(3), 347-364.
Meinshausen, N., & Buhlmann, P. (2006). High-dimensional graphs and variable selection with the lasso. Annals of Statistics, 34(3), 1436-1462.
Example
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> y = np.zeros((300, 5)) >>> for t in range(1, 300): ... y[t] = 0.5 * y[t - 1] + rng.standard_normal(5) >>> res = GraphicalVAR(y, order=1).fit(seed=0) >>> res.precision.shape (5, 5) >>> res.contemporaneous_adjacency().dtype dtype('bool') >>> bool(res.lambda_path.size) and bool(res.cv_errors.size) True >>> fixed = GraphicalVAR(y, order=1).fit(lam=0.05, seed=0) >>> fixed.lam, fixed.lambda_path.shape, fixed.lam_nodes.shape (0.05, (0,), (5,))
Attributes#
The validated sample. |
|
Whether a prior contributes anything to this estimate. |
|
Number of endogenous variables. |
|
Regressors per equation. |
|
Variable labels. |
|
Autoregressive order. |
|
The prior on the coefficients; |
|
Deterministic specification. |
Methods#
|
Estimate both networks. |
|
Score every order from zero to |