FunctionalVAR.fit#

FunctionalVAR.fit()[source]#

Project the curves and estimate the factor VAR.

Builds the basis for the chosen family, projects the curves onto it – centered by the sample mean under "fpca", uncentered under the fixed bases – names the factors (pc1 ..., level/slope/ curvature, or b1 ...), and fits a VAR of the requested order and trend to the scores.

Return type:

FunctionalVARResult

Returns:

The fitted result, with the complete factor-level surface on its factors attribute.

Raises:
  • SpecificationError – If n_components exceeds the sample’s numerical rank.

  • DimensionError – If the sample is too short for the factor VAR, from the VAR’s own validation.

  • NumericalError – If a fixed basis is rank-deficient on the grid.

Example

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> grid = np.linspace(0.0, 1.0, 25)
>>> curves = 0.1 * np.cumsum(rng.standard_normal(80))[:, None] + np.sin(np.pi * grid)
>>> curves = curves + 0.01 * rng.standard_normal((80, 25))
>>> res = FunctionalVAR(curves, grid, order=1, basis="bspline", df=5).fit()
>>> res.basis, res.factors.names, res.explained_variance, res.decay
('bspline', ('b1', 'b2', 'b3', 'b4', 'b5'), None, None)
>>> bool(np.allclose(res.mean_curve, 0.0)), bool(res.reconstruction_rmse < 0.02)
(True, True)