FunctionalCoefficientVAR.fit#

FunctionalCoefficientVAR.fit(*, bandwidth=None, n_grid=51, trim=0.05)[source]#

Estimate the coefficient curves by local-linear kernel regression.

The curves are evaluated on n_grid equally spaced points between the trim and 1 - trim quantiles of the state; the cross-validation criterion, when it runs, is scored on the observations inside that range only.

Parameters:
  • bandwidth (float | None) – Kernel bandwidth in the state variable’s units, or None to select by leave-one-out cross-validation on a grid around the Silverman-scaled rule of thumb.

  • n_grid (int) – Evaluation points for the reported curves.

  • trim (float) – Quantile trimmed from each end of the state range before the curve grid is laid down.

Return type:

FunctionalCoefficientVARResult

Returns:

The fitted FunctionalCoefficientVARResult.

Raises:
  • SpecificationError – If a stated bandwidth is not positive, n_grid is below 2, or trim is outside [0, 0.5).

  • NumericalError – If no bandwidth identifies every local system.

Example

>>> import numpy as np
>>> y = np.random.default_rng(0).standard_normal((150, 2))
>>> model = FunctionalCoefficientVAR(y, order=1, transition_variable="y1")
>>> res = model.fit(bandwidth=1.0, n_grid=11, trim=0.1)
>>> res.grid.shape, res.bandwidth, res.bandwidth_searched
((11,), 1.0, False)
>>> model.fit(bandwidth=-1.0)
Traceback (most recent call last):
cultivars.exceptions.SpecificationError: bandwidth must be positive; got -1.0.
>>> model.fit(bandwidth=0.05)
Traceback (most recent call last):
cultivars.exceptions.NumericalError: the local system at state value ... is ...