ARResult#
- class cultivars.univariate.autoregression.ARResult(*, endog, fittedvalues, resid, llf, nobs, n_params, order, trend, method, const, trend_coeff, ar_params, sigma2)[source]
Bases:
_SummaryMixin,_SeriesMixin,_ComparisonMixin,_StationarityMixinA 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_stationaryfrom the companion matrix of the autoregressive coefficients).repr=Falseis 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
Nonewhentrend == "n".trend_coeff – Linear-trend slope, or
Noneunlesstrend == "ct".ar_params – Autoregressive coefficients.
sigma2 – Innovation variance.
Note
Under
"css"the effective sample is the last \(n - p\) observations andllfis the conditional likelihood; under"exact"it is all \(n\) andllfincludes the density of the first \(p\) observations under stationarity. The two are not on the same scale, and neither are their information criteria, socomparerefuses results with differingnobsrather than rank them: to compare orders, fit every candidate withmethod="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, andsimulate()says so rather than returning a divergent path. Standard errors are not yet reported by this estimator.See also
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
lstsqexactly 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)
Private methods#
Specification label used when this result appears in a ranking. |
|
|
Assemble the public result from a raw fit and its specification. |
Structured summary rendered by every display path. |