DFMResult#

class cultivars.multivariate.large_dim.dynamic_factor.DFMResult(*, panel, series_names, factors, loadings, means, scales, variance_shares, idiosyncratic, criterion_values, n_factors)[source]#

A fitted dynamic factor model: loadings, a factor VAR, and the split.

The estimates of the two-step model on the standardized panel \(x_t = (y_t - \bar y) / s\),

\[x_t = \Lambda F_t + e_t, \qquad F_t = \sum_{i=1}^{p} A_i F_{t-i} + u_t,\]

with \(\Lambda\) the first \(r\) orthonormal right singular vectors of the standardized panel, \(F_t\) its projection onto them, and the VAR fitted to \(F_t\) by least squares without an intercept (the scores have mean zero by construction). The factor VAR is a complete fitted result of its own – forecast it, decompose it, feed it to Spillover – while this result owns the mapping between the panel and the factor space: the loadings, the standardization that was undone, the idiosyncratic remainders and the share of variance the factors carry.

Note

The factor space is identified, the basis is not: any rotation of \((\Lambda, F_t)\) by an orthogonal \(r \times r\) matrix leaves common_component, r_squared and forecast unchanged, so individual factors carry no structural names. Because the loadings are orthonormal and the standardized columns have unit variance, the mean of r_squared over the series equals variance_shares.sum() exactly. A constant column is standardized with scale 1 (not 0), contributes nothing to the factors, and reports an r_squared of 1 because its remainder is identically zero; read such a value as “nothing to explain”, not “fully explained”.

Variables:
  • panel – The observed (nobs, n_series) panel.

  • series_names – One label per series.

  • factors – The fitted VAR on the estimated factors, a full VARResult with variables f1 ... fr.

  • loadings – (n_series, r) orthonormal loadings on the standardized panel; the factor space is identified, the basis is not.

  • means – (n_series,) series means removed before extraction.

  • scales – (n_series,) series standard deviations divided out.

  • variance_shares – (r,) share of the standardized panel’s variance each component explains.

  • idiosyncratic – (nobs, n_series) standardized-panel remainders after the common component.

  • criterion_values – Bai-Ng ICp2 at each candidate count – empty when the caller fixed the count, so the audit trail matches what was actually decided.

  • n_factors – The factor count estimated with.

See also

  • DFM – the model that produces this record.

  • FAVAR – the factors joined to observed variables in one VAR.

  • FactorSV – the factor model with stochastic volatility.

References

Stock, J. H., & Watson, M. W. (2002). Forecasting using principal components from a large number of predictors. Journal of the American Statistical Association, 97(460), 1167-1179.

Bai, J., & Ng, S. (2002). Determining the number of factors in approximate factor models. Econometrica, 70(1), 191-221.

Example

Two persistent factors loaded onto thirty noisy series; the count is recovered, the common component tracks the truth, and the factor VAR is a full result:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> f = np.zeros((200, 2))
>>> for t in range(1, 200):
...     f[t] = 0.7 * f[t - 1] + rng.standard_normal(2)
>>> lam = rng.standard_normal((30, 2))
>>> panel = f @ lam.T + 1.5 * rng.standard_normal((200, 30))
>>> res = DFM(panel, order=1).fit()
>>> res.n_factors, res.n_series, res.nobs, res.loadings.shape
(2, 30, 200, (30, 2))
>>> bool(np.allclose(res.loadings.T @ res.loadings, np.eye(2)))
True
>>> truth = f @ lam.T
>>> bool(np.corrcoef(res.common_component[:, 0], truth[:, 0])[0, 1] > 0.9)
True
>>> res.factors.names, res.factors.order, res.criterion_values.shape
(('f1', 'f2'), 1, (8,))
>>> bool(abs(np.mean(list(res.r_squared().values())) - res.variance_shares.sum()) < 1e-12)
True

Attributes#

panel

The observed (nobs, n_series) panel.

series_names

One label per series, in column order.

factors

The fitted VAR on the factor scores, variables ``f1 .

loadings

(n_series, r) orthonormal loadings on the standardized panel.

means

(n_series,) means removed before extraction.

scales

(n_series,) standard deviations divided out; 1 for a constant column.

variance_shares

(r,) share of standardized variance per component.

idiosyncratic

(nobs, n_series) standardized remainders.

criterion_values

Bai-Ng ICp2 per candidate count, empty when fixed.

n_factors

The factor count the model was estimated with.

common_component

The factors' reconstruction of the panel, in original units.

n_series

Number of series in the panel.

nobs

Panel length.

Methods#

forecast([steps])

Forecast the whole panel through the factor VAR.

r_squared()

Share of each series' variance the common component explains.

summary()

The estimation summary, renderable as text, HTML, or a dataframe.