TARNNResult#

class cultivars.univariate.mean_function.TARNNResult(*, endog, fittedvalues, resid, llf, nobs, n_params, order, sigma2, engine, engine_config, delay, threshold, threshold_values, self_exciting, lower_predictor, upper_predictor, n_lower, n_upper)[source]

Bases: _MeanFunctionResult

A fitted two-regime neural threshold autoregression.

The model

\[\begin{split}y_t = \begin{cases} f_L(y_{t-1}, \ldots, y_{t-p}) + \varepsilon_t, & z_{t-d} \le r, \\ f_U(y_{t-1}, \ldots, y_{t-p}) + \varepsilon_t, & z_{t-d} > r, \end{cases}\end{split}\]

with \(z\) the series itself (self-exciting) or an external variable, \(r\) a fixed threshold, and \(f_L\), \(f_U\) two networks trained separately on their regime’s subsample under one pooled innovation variance.

Shares vocabulary with SETARResult – a delay, a threshold, a lower and an upper regime – but deliberately does not share its base class. That base exposes per-regime companion eigenvalues, and a learned regime has no autoregressive polynomial to take eigenvalues of; inheriting a stationarity property that could only lie is the failure mode this package refuses everywhere else.

Variables:
  • delay – Delay of the threshold variable.

  • threshold – The split point, in the units of the threshold variable.

  • threshold_values – The threshold variable, aligned with resid.

  • self_exciting – Whether the threshold variable is a lag of the series.

  • lower_predictor – Learned mean for observations at or below the split.

  • upper_predictor – Learned mean for observations above it.

  • n_lower – Observations assigned to the lower regime.

  • n_upper – Observations assigned to the upper regime.

Note

The inherited fields and properties are those of ARNNResult. The effective sample drops max(order, delay) leading observations so both the feature lags and the threshold lag exist. The threshold is fixed at construction (the median of the lagged threshold variable by default), not searched, so it carries no sampling uncertainty of the kind a searched threshold would, and n_params counts the two networks and the variance only.

See also

  • TARNN – the specification that produces this.

  • ARNNResult – one function over the whole sample.

  • SETARResult – the linear-per-regime model, with a searched threshold and per-regime stability verdicts.

Example

A regime map with slope 0.6 below zero and -0.4 above, recovered at a fixed split:

>>> import numpy as np
>>> rng = np.random.default_rng(1)
>>> z = np.zeros(600)
>>> for t in range(1, 600):
...     slope = 0.6 if z[t - 1] <= 0 else -0.4
...     z[t] = slope * z[t - 1] + 0.3 * rng.standard_normal()
>>> res = TARNN(z, order=1, threshold=0.0).fit()
>>> res.nobs, res.n_lower + res.n_upper, res.self_exciting
(599, 599, True)
>>> point = np.array([[-1.0], [1.0]])
>>> means = res.predict(point, point[:, 0])
>>> bool(abs(means[0] + 0.6) < 0.2), bool(abs(means[1] - -0.4) < 0.2)
(True, True)

Private methods#

_comparison_label()

Specification label used when this result appears in a ranking.

_from_fit(fit, model)

Assemble the public result from a raw fit and its specification.

_series()

Aligned per-observation output, widened by the regime split.

_summary_table()

Structured summary rendered by every display path.