AR#
- class cultivars.univariate.autoregression.AR(endog, *, order, trend='c', method='css')[source]#
Autoregressive AR(p) specification.
The immutable statement 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),\]validated at construction and estimated by
fit(). Two estimators are reachable throughmethod:"css"conditions on the first \(p\) observations and solves the lagged regression by ordinary least squares, so the effective sample is \(n - p\) and the likelihood is the conditional one;"exact"maximizes the exact Gaussian likelihood through the companion state-space embedding, the search kept inside the stationary region by a partial-autocorrelation reparameterization, so the first \(p\) observations contribute their stationary density and the effective sample is \(n\). The two agree as the sample grows and differ in finite samples by the treatment of those \(p\) observations.order=0is admitted and fits the deterministic terms alone.- Parameters:
- Raises:
SpecificationError – If the order is not a non-negative integer, the trend or method is unrecognized, or exact ML is requested with a linear trend.
DimensionError – If the series is not one-dimensional or is shorter than
order + 2.
Note
Exact ML with
trend="ct"is refused in this release; a linear trend is available under CSS only. Because the two estimators report different effective sample sizes, information criteria are comparable across orders only when every candidate uses"exact", andARResult.compare()enforces that.See also
References
Hamilton, J. D. (1994). Time Series Analysis, chapters 5 and 13. Princeton University Press.
Monahan, J. F. (1984). A note on enforcing stationarity in ARMA models. Biometrika, 71(2), 403-404.
Example
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> e = rng.standard_normal(500) >>> y = np.zeros(500) >>> for t in range(1, 500): ... y[t] = 0.5 * y[t - 1] + e[t] >>> res = AR(y, order=1, trend="c").fit() >>> bool(0.3 < res.ar_params[0] < 0.7) True
CSS and exact ML agree closely on a stationary AR(2) and differ in the sample they report:
>>> z = np.zeros(400) >>> for t in range(2, 400): ... z[t] = 0.5 * z[t - 1] - 0.3 * z[t - 2] + e[t] >>> css, exact = AR(z, order=2).fit(), AR(z, order=2, method="exact").fit() >>> css.nobs, exact.nobs, bool(np.allclose(css.ar_params, exact.ar_params, atol=0.01)) (398, 400, True) >>> AR(z, order=1, trend="ct", method="exact") Traceback (most recent call last): ... cultivars.exceptions.SpecificationError: exact ML with trend='ct' is not supported ...
Attributes#
Methods#
|
Estimate the model by the selected method. |