STVAR.fit#

STVAR.fit()[source]#

Estimate the transition by concentrated maximum likelihood.

Conditional on (gamma, c) the model is linear, so the regime coefficients come from one weighted least-squares solve; the pair is searched on the log-determinant of the residual covariance from several starts around the best hard split, and the covariance, likelihood and parameter count are read off at the optimum.

Return type:

STVARResult

Returns:

The fitted STVARResult.

Raises:

NumericalError – If the transition variable has zero variance or every start lands on a singular residual covariance.

Example

The smooth fit and the hard-split fit on one sample rank through the shared comparison surface:

>>> import numpy as np
>>> from cultivars.multivariate.nonlinear.threshold import TVAR
>>> rng = np.random.default_rng(1)
>>> y = np.zeros((400, 2))
>>> for t in range(1, 400):
...     g = 1.0 / (1.0 + np.exp(-2.0 * y[t - 1, 0]))
...     y[t] = ((1.0 - g) * 0.6 - g * 0.3) * y[t - 1] + rng.standard_normal(2)
>>> smooth = STVAR(y, order=1, transition_variable="y1").fit()
>>> hard = TVAR(y, order=1, transition_variable="y1").fit()
>>> smooth.n_params, hard.n_params
(17.0, 19.0)
>>> [row[0] for row in smooth.compare(hard, criterion="bic").rows]
['STVAR(1, logistic, d=1)', 'TVAR(1, d=1)']