SETARResult.nonlinear_state_space#

SETARResult.nonlinear_state_space(measurement_variance)[source]#

The fitted threshold mean as a noisily observed state space.

The errors-in-variables reading of the fit: the latent state is the lag stack of the true series, the transition applies the estimated regime-wise autoregression (hard switch at the fitted threshold, z <= r to the lower regime as in estimation), and the observation reads the current level through Gaussian measurement error of the stated variance. That variance is required and strictly positive because with none the model is observation-driven and filtering it is vacuous. The particle filter is the natural reader – the hard switch makes the transition non-smooth, so the extended filter’s Jacobians are untrustworthy near the threshold; the initial state is diffuse at the sample mean and variance.

Parameters:

measurement_variance (float) – Observation noise variance the emitted system is read through, strictly positive.

Return type:

_NonlinearStateSpace

Returns:

The NonlinearSSM with max(order, delay) states.

Raises:

SpecificationError – If the transition variable is external (a TAR fit) – the emitted transition can depend only on the state, so only self-exciting fits have a closed state-space form – or if the variance is not strictly positive.

Example

The fitted mean read through measurement noise by the particle filter, which recovers the latent series better than the noisy observations do:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> y = np.zeros(400)
>>> for t in range(1, 400):
...     y[t] = (0.6 if y[t - 1] <= 0.0 else -0.4) * y[t - 1] + rng.standard_normal()
>>> res = SETAR(y, order=1, delay=1).fit()
>>> system = res.nonlinear_state_space(0.5)
>>> system.k_states, system.k_endog
(1, 1)
>>> noisy = y + np.sqrt(0.5) * rng.standard_normal(400)
>>> filtered = system.particle_filter(noisy, n_particles=500, seed=0)
>>> latent = filtered.filtered_state[:, 0]
>>> bool(np.mean((latent - y) ** 2) < np.mean((noisy - y) ** 2))
True
>>> res.nonlinear_state_space(0.0)
Traceback (most recent call last):
cultivars.exceptions.SpecificationError: measurement_variance must be strictly ...