ARResult#

class cultivars.univariate.autoregression.ARResult(*, endog, fittedvalues, resid, llf, nobs, n_params, order, trend, method, const, trend_coeff, ar_params, sigma2)[source]#

A fitted autoregression.

The estimates of

\[y_t = c + \delta t + \sum_{i=1}^{p} \phi_i\, y_{t-i} + \varepsilon_t, \qquad \varepsilon_t \sim N(0, \sigma^2),\]

together with the one-step fitted values and residuals on the effective sample, the maximized log-likelihood, and the counts that turn the likelihood into information criteria. Composes four capabilities: rendering (summary, and the summary is what a bare result prints), frame interop (to_pandas, to_polars, to_dict), criterion-named comparison (information_criteria, compare, likelihood_ratio_test), and stationarity assessment (stability, is_stationary from the companion matrix of the autoregressive coefficients). repr=False is required – see _SummaryMixin – so the summary is what a bare result prints.

Variables:
  • endog – The full observed series, retained so residual and fitted paths can be aligned against it.

  • fittedvalues – One-step fitted values over the effective sample.

  • resid – One-step residuals over the effective sample.

  • llf – Maximized log-likelihood, conditional for CSS and exact otherwise.

  • nobs – Observations the likelihood was evaluated on.

  • n_params – Free parameter count, including the innovation variance.

  • order – Autoregressive order p.

  • trend – Deterministic specification.

  • method – Estimator that produced the fit.

  • const – Intercept, or None when trend == "n".

  • trend_coeff – Linear-trend slope, or None unless trend == "ct".

  • ar_params – Autoregressive coefficients.

  • sigma2 – Innovation variance.

Note

Under "css" the effective sample is the last \(n - p\) observations and llf is the conditional likelihood; under "exact" it is all \(n\) and llf includes the density of the first \(p\) observations under stationarity. The two are not on the same scale, and neither are their information criteria, so compare refuses results with differing nobs rather than rank them: to compare orders, fit every candidate with method="exact". The unconditional mean and variance the estimates imply are \(c / (1 - \sum \phi_i)\) and, for \(p = 1\), \(\sigma^2 / (1 - \phi_1^2)\); a fit whose coefficients sum to one has neither, and simulate() says so rather than returning a divergent path. Standard errors are not yet reported by this estimator.

See also

  • AR – the specification that produces this.

  • ARIMA – the moving-average and integrated generalization, with the same result surface.

  • VARResult – the vector counterpart.

References

Hamilton, J. D. (1994). Time Series Analysis, chapters 5 and 13. Princeton University Press.

Example

>>> rng = np.random.default_rng(0)
>>> y = np.zeros(500)
>>> for t in range(1, 500):
...     y[t] = 1.0 + 0.5 * y[t - 1] + rng.standard_normal()
>>> res = AR(y, order=1, trend="c").fit()
>>> res.nobs, res.n_params, list(res.params)
(499, 3, ['const', 'ar.L1', 'sigma2'])
>>> round(float(res.const), 2), res.ar_params.round(2).tolist(), round(res.sigma2, 2)
(1.02, [0.48], 1.03)

CSS is ordinary least squares on the lagged regression, so the estimates match lstsq exactly and the residuals are the series minus its fitted values:

>>> design = np.column_stack([np.ones(499), y[:-1]])
>>> beta = np.linalg.lstsq(design, y[1:], rcond=None)[0]
>>> bool(np.allclose(beta, [res.const, res.ar_params[0]]))
True
>>> bool(np.allclose(res.endog[1:] - res.fittedvalues, res.resid))
True
>>> res.is_stationary, round(res.stability.max_modulus, 2)
(True, 0.48)

Attributes#

endog

The full observed series.

fittedvalues

One-step fitted values over the effective sample.

resid

One-step residuals over the effective sample.

llf

Maximized log-likelihood; conditional under CSS, exact otherwise.

nobs

Observations the likelihood was evaluated on.

n_params

Free parameter count, including the innovation variance.

order

Autoregressive order p.

trend

"n", "c" or "ct".

method

"css" or "exact".

const

Intercept, or None when trend == "n".

trend_coeff

Linear-trend slope, or None unless trend == "ct".

ar_params

(p,) autoregressive coefficients.

sigma2

Innovation variance.

information_criteria

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

is_stationary

Whether every companion eigenvalue lies inside the unit circle.

params

Estimated parameters keyed by display name, in table order.

stability

Full eigenvalue verdict for the autoregressive polynomial.

Methods#

compare(*others[, criterion])

Rank this result against others by an information criterion.

likelihood_ratio_test(unrestricted)

Test this result as the restricted model against a nesting one.

simulate([n, seed, burn])

A fresh sample path at the fitted parameters.

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.