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]#

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)

Attributes#

delay

Lag applied to the threshold variable before the split.

threshold

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

threshold_values

(nobs,) lagged threshold variable, aligned with resid.

self_exciting

True when the threshold variable is a lag of endog.

lower_predictor

Network trained on the lower-regime subsample.

upper_predictor

Network trained on the upper-regime subsample.

n_lower

Effective-sample observations with z <= threshold.

n_upper

Effective-sample observations with z > threshold.

endog

engine

engine_config

fittedvalues

information_criteria

AIC, BIC, and HQIC derived from the likelihood and parameter count.

llf

n_learner_parameters

Weights and biases across both regime networks.

n_params

nobs

order

parameters_per_observation

Nominal learner parameters divided by the effective sample size.

r_squared

Share of the effective sample's variance the fitted mean explains.

regime_weight

1.0 above the threshold, else 0.0.

resid

sigma2

ssr

Sum of squared residuals over the effective sample.

upper_fraction

Share of the effective sample assigned to the upper regime.

Methods#

compare(*others[, criterion])

Rank this result against others by an information criterion.

likelihood_ratio_test(unrestricted)

Refuse the test: a network's weights are unidentified under a linear null.

nonlinear_state_space(measurement_variance)

The fitted two-network threshold mean as a noisily observed state space.

predict(features, threshold_values)

Conditional means, routing each row to its regime's learner.

summary()

The estimation summary, renderable as text, HTML, or a dataframe.

to_dict()

The aligned per-observation outputs as plain numpy arrays.

to_pandas(*[, index])

The aligned per-observation outputs as a pandas.DataFrame.

to_polars()

The aligned per-observation outputs as a polars.DataFrame.