SparseVAR#

class cultivars.multivariate.large_dim.sparse.SparseVAR(endog, *, order, trend='c', names=None)[source]#

Penalized VAR: lasso, adaptive lasso, SCAD, MCP, or lag-group.

One estimator, five penalties on the standardized lag coefficients. The lasso \(\lambda \sum |a|\) is the baseline; the adaptive lasso reweights each coefficient by a ridge pilot, \(\lambda \sum |a| / |\tilde a|\); SCAD and MCP are the nonconvex penalties that leave large coefficients unbiased, solved by local linear approximation as a short sequence of weighted lasso problems; and the lag-group penalty \(\lambda \sum_i \sqrt{k^2}\, \lVert A_i \rVert_F\) zeroes whole lag matrices, so it selects lags rather than entries. Every problem is solved by FISTA, warm-started along a geometric path from the level that zeroes everything down to lambda_min_ratio of it, and the level is chosen by rolling-origin one-step forecast error with a refit at every origin. 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:
  • endog (ArrayLike) – The observed panel, shape (nobs, k); wide is the point.

  • order (int) – Autoregressive order, at least 1.

  • trend (Literal['n', 'c', 'ct']) – Deterministic terms, "n", "c" or "ct", never penalized.

  • names (Sequence[str] | None) – One label per variable. Defaults to y1 ... yk.

Raises:
  • SpecificationError – If order is below 1, trend is not one of the three names, or names does 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

  • SparseVARResult – the record fit returns.

  • GraphicalVAR – this estimator plus a sparse residual precision.

  • BVAR – the shrinkage alternative for wide systems, with a likelihood.

References

Basu, S., & Michailidis, G. (2015). Regularized estimation in sparse high-dimensional time series models. Annals of Statistics, 43(4), 1535-1567.

Nicholson, W. B., Matteson, D. S., & Bien, J. (2017). VARX-L: Structured regularization for large vector autoregressions with exogenous variables. International Journal of Forecasting, 33(3), 627-651.

Zou, H., & Li, R. (2008). One-step sparse estimates in nonconcave penalized likelihood models. Annals of Statistics, 36(4), 1509-1533.

Example

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> y = np.zeros((300, 6))
>>> for t in range(1, 300):
...     y[t] = 0.5 * y[t - 1] + rng.standard_normal(6)
>>> res = SparseVAR(y, order=2).fit(penalty="lasso")
>>> res.coefficients.shape
(2, 6, 6)
>>> bool(res.sparsity > 0.3)
True
>>> SparseVAR(y, order=2).fit(penalty="ridge")
Traceback (most recent call last):
cultivars.exceptions.SpecificationError: penalty must be one of ('lasso', 'adaptive', ...

Attributes#

endog

The validated sample.

is_shrunk

Whether a prior contributes anything to this estimate.

k_endog

Number of endogenous variables.

n_regressors

Regressors per equation.

names

Variable labels.

order

Autoregressive order.

prior

The prior on the coefficients; NoPrior when unrestricted.

trend

Deterministic specification.

Methods#

fit(*[, penalty, lam, n_lambdas, ...])

Estimate under one penalty family, selecting the level if unstated.

lag_order_selection([max_lags])

Score every order from zero to max_lags on one common sample.